From 39c7d0a97a77d3f31953941767a0822c94dc01f5 Mon Sep 17 00:00:00 2001 From: Christoph Heiss Date: Wed, 7 Jun 2023 14:51:05 +0200 Subject: [PATCH] imv: add module (#4032) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * imv: add module Signed-off-by: Christoph Heiss * imv: add test cases Signed-off-by: Christoph Heiss --------- Signed-off-by: Christoph Heiss Co-authored-by: Naïm Favier --- modules/misc/news.nix | 7 +++ modules/modules.nix | 1 + modules/programs/imv.nix | 49 +++++++++++++++++++ tests/default.nix | 1 + .../programs/imv/basic-configuration.conf | 6 +++ .../programs/imv/basic-configuration.nix | 20 ++++++++ tests/modules/programs/imv/default.nix | 4 ++ .../programs/imv/empty-configuration.nix | 14 ++++++ 8 files changed, 102 insertions(+) create mode 100644 modules/programs/imv.nix create mode 100644 tests/modules/programs/imv/basic-configuration.conf create mode 100644 tests/modules/programs/imv/basic-configuration.nix create mode 100644 tests/modules/programs/imv/default.nix create mode 100644 tests/modules/programs/imv/empty-configuration.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 649d73e1f..3c665eb77 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1055,6 +1055,13 @@ in ''; } + { + time = "2023-06-07T12:16:55+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'programs.imv'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 78c41a301..0ee8ee54f 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -97,6 +97,7 @@ let ./programs/hyfetch.nix ./programs/i3status-rust.nix ./programs/i3status.nix + ./programs/imv.nix ./programs/info.nix ./programs/ion.nix ./programs/irssi.nix diff --git a/modules/programs/imv.nix b/modules/programs/imv.nix new file mode 100644 index 000000000..2841b5a2b --- /dev/null +++ b/modules/programs/imv.nix @@ -0,0 +1,49 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.programs.imv; + + toConfig = attrs: + '' + # Generated by Home Manager. + '' + generators.toINI { } attrs; +in { + meta.maintainers = [ maintainers.christoph-heiss ]; + + options.programs.imv = { + enable = mkEnableOption + "imv: a command line image viewer intended for use with tiling window managers"; + + package = mkPackageOption pkgs "imv" { }; + + settings = mkOption { + default = { }; + type = with types; attrsOf (attrsOf (oneOf [ bool int str ])); + description = '' + Configuration options for imv. See + + imv + 5 + . + ''; + example = literalExpression '' + { + options.background = "ffffff"; + aliases.x = "close"; + } + ''; + }; + }; + + config = mkIf cfg.enable { + assertions = + [ (hm.assertions.assertPlatform "programs.imv" pkgs platforms.linux) ]; + + home.packages = [ cfg.package ]; + + xdg.configFile = + mkIf (cfg.settings != { }) { "imv/config".text = toConfig cfg.settings; }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index c68856b92..49b2dcea1 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -164,6 +164,7 @@ import nmt { ./modules/programs/gnome-terminal ./modules/programs/hexchat ./modules/programs/i3status-rust + ./modules/programs/imv ./modules/programs/kodi ./modules/programs/looking-glass-client ./modules/programs/mangohud diff --git a/tests/modules/programs/imv/basic-configuration.conf b/tests/modules/programs/imv/basic-configuration.conf new file mode 100644 index 000000000..12f266d96 --- /dev/null +++ b/tests/modules/programs/imv/basic-configuration.conf @@ -0,0 +1,6 @@ +# Generated by Home Manager. +[aliases] +x=close + +[options] +background=ffffff diff --git a/tests/modules/programs/imv/basic-configuration.nix b/tests/modules/programs/imv/basic-configuration.nix new file mode 100644 index 000000000..e62a9d49c --- /dev/null +++ b/tests/modules/programs/imv/basic-configuration.nix @@ -0,0 +1,20 @@ +{ pkgs, ... }: + +{ + config = { + programs.imv = { + enable = true; + package = pkgs.writeScriptBin "dummy-imv" ""; + settings = { + options.background = "ffffff"; + aliases.x = "close"; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/imv/config + assertFileContent home-files/.config/imv/config \ + ${./basic-configuration.conf} + ''; + }; +} diff --git a/tests/modules/programs/imv/default.nix b/tests/modules/programs/imv/default.nix new file mode 100644 index 000000000..b035c7278 --- /dev/null +++ b/tests/modules/programs/imv/default.nix @@ -0,0 +1,4 @@ +{ + imv-basic-configuration = ./basic-configuration.nix; + imv-empty-configuration = ./empty-configuration.nix; +} diff --git a/tests/modules/programs/imv/empty-configuration.nix b/tests/modules/programs/imv/empty-configuration.nix new file mode 100644 index 000000000..1c46b4c65 --- /dev/null +++ b/tests/modules/programs/imv/empty-configuration.nix @@ -0,0 +1,14 @@ +{ pkgs, ... }: + +{ + config = { + programs.imv = { + enable = true; + package = pkgs.writeScriptBin "dummy-imv" ""; + }; + + nmt.script = '' + assertPathNotExists home-files/.config/imv/config + ''; + }; +}