From 366b60b8a06d237dbadd9a573ab21532dec70031 Mon Sep 17 00:00:00 2001 From: Aguirre Matteo Date: Tue, 23 Sep 2025 10:42:28 -0300 Subject: [PATCH] ahoviewer: add module --- modules/programs/ahoviewer.nix | 73 +++++++++++++++++++ .../modules/programs/ahoviewer/ahoviewer.cfg | 16 ++++ tests/modules/programs/ahoviewer/default.nix | 5 ++ .../programs/ahoviewer/example-config.nix | 41 +++++++++++ .../modules/programs/ahoviewer/plugins/a.nix | 13 ++++ .../modules/programs/ahoviewer/plugins/b.nix | 13 ++++ .../plugins/plugin-a/plugin-a.plugin | 7 ++ .../ahoviewer/plugins/plugin-a/plugin-a.py | 1 + .../plugins/plugin-b/plugin-b.plugin | 7 ++ .../ahoviewer/plugins/plugin-b/plugin-b.py | 1 + 10 files changed, 177 insertions(+) create mode 100644 modules/programs/ahoviewer.nix create mode 100644 tests/modules/programs/ahoviewer/ahoviewer.cfg create mode 100644 tests/modules/programs/ahoviewer/default.nix create mode 100644 tests/modules/programs/ahoviewer/example-config.nix create mode 100644 tests/modules/programs/ahoviewer/plugins/a.nix create mode 100644 tests/modules/programs/ahoviewer/plugins/b.nix create mode 100644 tests/modules/programs/ahoviewer/plugins/plugin-a/plugin-a.plugin create mode 100644 tests/modules/programs/ahoviewer/plugins/plugin-a/plugin-a.py create mode 100644 tests/modules/programs/ahoviewer/plugins/plugin-b/plugin-b.plugin create mode 100644 tests/modules/programs/ahoviewer/plugins/plugin-b/plugin-b.py diff --git a/modules/programs/ahoviewer.nix b/modules/programs/ahoviewer.nix new file mode 100644 index 000000000..03b5d3c33 --- /dev/null +++ b/modules/programs/ahoviewer.nix @@ -0,0 +1,73 @@ +{ + lib, + pkgs, + config, + ... +}: +let + inherit (lib) + types + mkIf + mkEnableOption + mkPackageOption + mkOption + ; + + cfg = config.programs.ahoviewer; +in +{ + meta.maintainers = with lib.hm.maintainers; [ aguirre-matteo ]; + options.programs.ahoviewer = { + enable = mkEnableOption "ahoviewer"; + package = mkPackageOption pkgs "ahoviewer" { nullable = true; }; + config = mkOption { + type = with types; either str path; + default = ""; + example = '' + ZoomMode = "M"; + Geometry : + { + x = 964; + y = 574; + w = 948; + h = 498; + }; + BooruWidth = 382; + TagViewPosition = 318; + SmartNavigation = true; + StoreRecentFiles = false; + RememberLastFile = false; + SaveThumbnails = false; + AutoOpenArchive = false; + BooruBrowserVisible = true; + ''; + description = '' + Configuration settings for ahoviewer. All the available options + can be found editing the preferences in the GUI and looking at + $XDG_CONFIG_HOME/ahoviewer/ahoviewer.cfg + ''; + }; + plugins = mkOption { + type = with types; listOf package; + default = [ ]; + description = '' + List of plugins for ahoviewer. + ''; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "programs.ahoviewer" pkgs lib.platforms.linux) + ]; + + xdg.configFile."ahoviewer/ahoviewer.cfg" = mkIf (cfg.config != "") { + source = if lib.isPath cfg.config then cfg.config else pkgs.writeText "ahoviewer.cfg" cfg.config; + }; + xdg.dataFile = mkIf (cfg.plugins != [ ]) ( + lib.listToAttrs ( + map (p: lib.nameValuePair "ahoviewer/plugins/${p.pname}" { source = p; }) cfg.plugins + ) + ); + }; +} diff --git a/tests/modules/programs/ahoviewer/ahoviewer.cfg b/tests/modules/programs/ahoviewer/ahoviewer.cfg new file mode 100644 index 000000000..0bb515e27 --- /dev/null +++ b/tests/modules/programs/ahoviewer/ahoviewer.cfg @@ -0,0 +1,16 @@ +ZoomMode = "M"; +Geometry : +{ + x = 964; + y = 574; + w = 948; + h = 498; +}; +BooruWidth = 382; +TagViewPosition = 318; +SmartNavigation = true; +StoreRecentFiles = false; +RememberLastFile = false; +SaveThumbnails = false; +AutoOpenArchive = false; +BooruBrowserVisible = true; diff --git a/tests/modules/programs/ahoviewer/default.nix b/tests/modules/programs/ahoviewer/default.nix new file mode 100644 index 000000000..7b95d3d69 --- /dev/null +++ b/tests/modules/programs/ahoviewer/default.nix @@ -0,0 +1,5 @@ +{ lib, pkgs, ... }: + +lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { + ahoviewer-example-config = ./example-config.nix; +} diff --git a/tests/modules/programs/ahoviewer/example-config.nix b/tests/modules/programs/ahoviewer/example-config.nix new file mode 100644 index 000000000..cda98410a --- /dev/null +++ b/tests/modules/programs/ahoviewer/example-config.nix @@ -0,0 +1,41 @@ +{ pkgs, ... }: + +{ + programs.ahoviewer = { + enable = true; + config = '' + ZoomMode = "M"; + Geometry : + { + x = 964; + y = 574; + w = 948; + h = 498; + }; + BooruWidth = 382; + TagViewPosition = 318; + SmartNavigation = true; + StoreRecentFiles = false; + RememberLastFile = false; + SaveThumbnails = false; + AutoOpenArchive = false; + BooruBrowserVisible = true; + ''; + plugins = [ + (pkgs.callPackage ./plugins/a.nix { }) + (pkgs.callPackage ./plugins/b.nix { }) + ]; + }; + + nmt.script = '' + assertFileExists home-files/.config/ahoviewer/ahoviewer.cfg + assertFileContent home-files/.config/ahoviewer/ahoviewer.cfg \ + ${./ahoviewer.cfg} + + assertFileExists home-files/.local/share/ahoviewer/plugins/plugin-a/plugin-a.plugin + assertFileExists home-files/.local/share/ahoviewer/plugins/plugin-a/plugin-a.py + + assertFileExists home-files/.local/share/ahoviewer/plugins/plugin-a/plugin-a.plugin + assertFileExists home-files/.local/share/ahoviewer/plugins/plugin-a/plugin-a.py + ''; +} diff --git a/tests/modules/programs/ahoviewer/plugins/a.nix b/tests/modules/programs/ahoviewer/plugins/a.nix new file mode 100644 index 000000000..cde7bd7ac --- /dev/null +++ b/tests/modules/programs/ahoviewer/plugins/a.nix @@ -0,0 +1,13 @@ +{ + stdenvNoCC, +}: + +stdenvNoCC.mkDerivation { + pname = "plugin-a"; + version = "1.0.0"; + src = ./plugin-a; + buildPhase = '' + mkdir -p $out + cp $src/* $out/ + ''; +} diff --git a/tests/modules/programs/ahoviewer/plugins/b.nix b/tests/modules/programs/ahoviewer/plugins/b.nix new file mode 100644 index 000000000..f6a0c9383 --- /dev/null +++ b/tests/modules/programs/ahoviewer/plugins/b.nix @@ -0,0 +1,13 @@ +{ + stdenvNoCC, +}: + +stdenvNoCC.mkDerivation { + pname = "plugin-b"; + version = "1.0.0"; + src = ./plugin-b; + buildPhase = '' + mkdir -p $out + cp $src/* $out/ + ''; +} diff --git a/tests/modules/programs/ahoviewer/plugins/plugin-a/plugin-a.plugin b/tests/modules/programs/ahoviewer/plugins/plugin-a/plugin-a.plugin new file mode 100644 index 000000000..8fb5936cf --- /dev/null +++ b/tests/modules/programs/ahoviewer/plugins/plugin-a/plugin-a.plugin @@ -0,0 +1,7 @@ +[Plugin] +Module=plugin-a +Loader=python3 +Name=Test +Description=Test +Hidden=false +X-ActionName=TestPlugin diff --git a/tests/modules/programs/ahoviewer/plugins/plugin-a/plugin-a.py b/tests/modules/programs/ahoviewer/plugins/plugin-a/plugin-a.py new file mode 100644 index 000000000..44159b395 --- /dev/null +++ b/tests/modules/programs/ahoviewer/plugins/plugin-a/plugin-a.py @@ -0,0 +1 @@ +print("Hello world") diff --git a/tests/modules/programs/ahoviewer/plugins/plugin-b/plugin-b.plugin b/tests/modules/programs/ahoviewer/plugins/plugin-b/plugin-b.plugin new file mode 100644 index 000000000..33e253fd4 --- /dev/null +++ b/tests/modules/programs/ahoviewer/plugins/plugin-b/plugin-b.plugin @@ -0,0 +1,7 @@ +[Plugin] +Module=plugin-b +Loader=python3 +Name=Test +Description=Test +Hidden=false +X-ActionName=TestPlugin diff --git a/tests/modules/programs/ahoviewer/plugins/plugin-b/plugin-b.py b/tests/modules/programs/ahoviewer/plugins/plugin-b/plugin-b.py new file mode 100644 index 000000000..44159b395 --- /dev/null +++ b/tests/modules/programs/ahoviewer/plugins/plugin-b/plugin-b.py @@ -0,0 +1 @@ +print("Hello world")