diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 7e835212..dd4bb9e2 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -448,4 +448,10 @@ github = "liyangau"; githubId = 71299093; }; + wcarlsen = { + name = "Willi Carlsen"; + email = "carlsenwilli+nix@gmail.com"; + github = "wcarlsen"; + githubId = 17003032; + }; } diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 6a494739..82ad5287 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1288,6 +1288,13 @@ in A new module is available: 'programs.cava'. ''; } + + { + time = "2023-11-01T21:18:20+00:00"; + message = '' + A new module is available: 'programs.granted'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 2e9d237b..02f4ae07 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -99,6 +99,7 @@ let ./programs/gnome-terminal.nix ./programs/go.nix ./programs/gpg.nix + ./programs/granted.nix ./programs/havoc.nix ./programs/helix.nix ./programs/hexchat.nix diff --git a/modules/programs/granted.nix b/modules/programs/granted.nix new file mode 100644 index 00000000..a0916925 --- /dev/null +++ b/modules/programs/granted.nix @@ -0,0 +1,36 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.granted; + package = pkgs.granted; + +in { + meta.maintainers = [ hm.maintainers.wcarlsen ]; + + options.programs.granted = { + enable = mkEnableOption "granted"; + + enableZshIntegration = mkOption { + default = true; + type = types.bool; + description = '' + Whether to enable Zsh integration. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ package ]; + + programs.zsh.initExtra = mkIf cfg.enableZshIntegration '' + function assume() { + export GRANTED_ALIAS_CONFIGURED="true" + source ${package}/bin/.assume-wrapped "$@" + unset GRANTED_ALIAS_CONFIGURED + } + ''; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 704ce793..23dd36cc 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -84,6 +84,7 @@ import nmt { ./modules/programs/git ./modules/programs/git-cliff ./modules/programs/gpg + ./modules/programs/granted ./modules/programs/helix ./modules/programs/himalaya ./modules/programs/htop diff --git a/tests/modules/programs/granted/default.nix b/tests/modules/programs/granted/default.nix new file mode 100644 index 00000000..da462752 --- /dev/null +++ b/tests/modules/programs/granted/default.nix @@ -0,0 +1,4 @@ +{ + granted-integration-enabled = ./integration-enabled.nix; + granted-integration-disabled = ./integration-disabled.nix; +} diff --git a/tests/modules/programs/granted/integration-disabled.nix b/tests/modules/programs/granted/integration-disabled.nix new file mode 100644 index 00000000..6e43b477 --- /dev/null +++ b/tests/modules/programs/granted/integration-disabled.nix @@ -0,0 +1,27 @@ +{ pkgs, ... }: + +{ + programs = { + granted.enable = true; + granted.enableZshIntegration = false; + zsh.enable = true; + }; + + test.stubs.granted = { }; + + nmt.script = '' + assertFileExists home-files/.zshrc + assertFileNotRegex \ + home-files/.zshrc \ + 'function assume()' + assertFileNotRegex \ + home-files/.zshrc \ + 'export GRANTED_ALIAS_CONFIGURED="true"' + assertFileNotRegex \ + home-files/.zshrc \ + 'source @granted@/bin/.assume-wrapped "$@"' + assertFileNotRegex \ + home-files/.zshrc \ + 'unset GRANTED_ALIAS_CONFIGURED' + ''; +} diff --git a/tests/modules/programs/granted/integration-enabled.nix b/tests/modules/programs/granted/integration-enabled.nix new file mode 100644 index 00000000..daf84367 --- /dev/null +++ b/tests/modules/programs/granted/integration-enabled.nix @@ -0,0 +1,26 @@ +{ pkgs, ... }: + +{ + programs = { + granted.enable = true; + zsh.enable = true; + }; + + test.stubs.granted = { }; + + nmt.script = '' + assertFileExists home-files/.zshrc + assertFileContains \ + home-files/.zshrc \ + 'function assume()' + assertFileContains \ + home-files/.zshrc \ + 'export GRANTED_ALIAS_CONFIGURED="true"' + assertFileContains \ + home-files/.zshrc \ + 'source @granted@/bin/.assume-wrapped "$@"' + assertFileContains \ + home-files/.zshrc \ + 'unset GRANTED_ALIAS_CONFIGURED' + ''; +}