diff --git a/modules/misc/news/2025/05/2025-05-29_14-33-51.nix b/modules/misc/news/2025/05/2025-05-29_14-33-51.nix new file mode 100644 index 00000000..33ce3bab --- /dev/null +++ b/modules/misc/news/2025/05/2025-05-29_14-33-51.nix @@ -0,0 +1,7 @@ +{ + time = "2025-05-29T18:33:51+00:00"; + condition = true; + message = '' + A new module is available: 'programs.hwatch'. + ''; +} diff --git a/modules/modules.nix b/modules/modules.nix index 99b32b8f..5020c666 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -139,6 +139,7 @@ let ./programs/home-manager.nix ./programs/hstr.nix ./programs/htop.nix + ./programs/hwatch.nix ./programs/hyfetch.nix ./programs/hyprlock.nix ./programs/i3bar-river.nix diff --git a/modules/programs/hwatch.nix b/modules/programs/hwatch.nix new file mode 100644 index 00000000..3040e6e4 --- /dev/null +++ b/modules/programs/hwatch.nix @@ -0,0 +1,50 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + inherit (lib) + mkIf + mkOption + types + ; + cfg = config.programs.hwatch; +in +{ + meta.maintainers = with lib.hm.maintainers; [ + Aehmlo + ]; + + options.programs.hwatch = { + enable = lib.mkEnableOption '' + hwatch, a modern alternative to the {command}`watch` command + ''; + + package = lib.mkPackageOption pkgs "hwatch" { nullable = true; }; + + extraArgs = mkOption { + type = types.listOf types.str; + default = [ ]; + example = [ + "--exec" + "--precise" + ]; + description = '' + Extra command-line arguments to pass to {command}`hwatch`. + These will be used to populate the {env}`HWATCH` environment variable. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = mkIf (cfg.package != null) [ cfg.package ]; + + home.sessionVariables = mkIf (cfg.extraArgs != [ ]) { + HWATCH = lib.concatMapStringsSep " " lib.escapeShellArg cfg.extraArgs; + }; + }; + +} diff --git a/tests/default.nix b/tests/default.nix index 3af9c443..a347b7ab 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -216,6 +216,7 @@ import nmtSrc { ./modules/programs/helix ./modules/programs/himalaya ./modules/programs/htop + ./modules/programs/hwatch ./modules/programs/hyfetch ./modules/programs/i3status ./modules/programs/inori diff --git a/tests/modules/programs/hwatch/default.nix b/tests/modules/programs/hwatch/default.nix new file mode 100644 index 00000000..37924b50 --- /dev/null +++ b/tests/modules/programs/hwatch/default.nix @@ -0,0 +1,4 @@ +{ + hwatch-empty-config = ./empty-config.nix; + hwatch-example-config = ./example-config.nix; +} diff --git a/tests/modules/programs/hwatch/empty-config.nix b/tests/modules/programs/hwatch/empty-config.nix new file mode 100644 index 00000000..ff7ebd02 --- /dev/null +++ b/tests/modules/programs/hwatch/empty-config.nix @@ -0,0 +1,15 @@ +{ + config, + ... +}: + +{ + programs.hwatch = { + enable = true; + package = config.lib.test.mkStubPackage { }; + }; + + nmt.script = '' + assertFileNotRegex home-path/etc/profile.d/hm-session-vars.sh "HWATCH" + ''; +} diff --git a/tests/modules/programs/hwatch/example-config.nix b/tests/modules/programs/hwatch/example-config.nix new file mode 100644 index 00000000..8542ac41 --- /dev/null +++ b/tests/modules/programs/hwatch/example-config.nix @@ -0,0 +1,20 @@ +{ + config, + ... +}: + +{ + programs.hwatch = { + enable = true; + package = config.lib.test.mkStubPackage { }; + extraArgs = [ + "--exec" + "--precise" + ]; + }; + + nmt.script = '' + assertFileExists home-path/etc/profile.d/hm-session-vars.sh + assertFileContains home-path/etc/profile.d/hm-session-vars.sh 'HWATCH="--exec --precise"' + ''; +}