From 3e54b76507613b1f143a115fcbf44c160ce662a8 Mon Sep 17 00:00:00 2001 From: jaredmontoya <49511278+jaredmontoya@users.noreply.github.com> Date: Thu, 20 Mar 2025 01:15:51 +0100 Subject: [PATCH] pay-respects: allow setting custom options --- modules/programs/pay-respects.nix | 48 ++++++++++--------- .../pay-respects/integration-disabled.nix | 12 +++-- .../pay-respects/integration-enabled.nix | 20 ++++---- 3 files changed, 46 insertions(+), 34 deletions(-) diff --git a/modules/programs/pay-respects.nix b/modules/programs/pay-respects.nix index 302d1b125..cfbd3dc10 100644 --- a/modules/programs/pay-respects.nix +++ b/modules/programs/pay-respects.nix @@ -1,16 +1,24 @@ { config, lib, pkgs, ... }: let - inherit (lib) mkEnableOption mkPackageOption getExe optionalString mkIf; - cfg = config.programs.pay-respects; - payRespectsCmd = getExe cfg.package; + payRespectsCmd = lib.getExe cfg.package; + cfgOptions = lib.concatStringsSep " " cfg.options; in { meta.maintainers = [ lib.hm.maintainers.ALameLlama ]; options.programs.pay-respects = { - enable = mkEnableOption "pay-respects"; + enable = lib.mkEnableOption "pay-respects"; - package = mkPackageOption pkgs "pay-respects" { }; + package = lib.mkPackageOption pkgs "pay-respects" { }; + + options = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ "--alias" ]; + example = [ "--alias" "f" ]; + description = '' + List of options to pass to pay-respects . + ''; + }; enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; }; @@ -25,32 +33,28 @@ in { lib.hm.shell.mkZshIntegrationOption { inherit config; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; programs = { - bash.initExtra = '' - ${optionalString cfg.enableBashIntegration '' - eval "$(${payRespectsCmd} bash --alias)" - ''} + bash.initExtra = lib.mkIf cfg.enableBashIntegration '' + eval "$(${payRespectsCmd} bash ${cfgOptions})" ''; - zsh.initContent = '' - ${optionalString cfg.enableZshIntegration '' - eval "$(${payRespectsCmd} zsh --alias)" - ''} + zsh.initContent = lib.mkIf cfg.enableZshIntegration '' + eval "$(${payRespectsCmd} zsh ${cfgOptions})" ''; - fish.interactiveShellInit = '' - ${optionalString cfg.enableFishIntegration '' - ${payRespectsCmd} fish --alias | source - ''} + fish.interactiveShellInit = lib.mkIf cfg.enableFishIntegration '' + ${payRespectsCmd} fish ${cfgOptions} | source ''; - nushell.extraConfig = '' - ${optionalString cfg.enableNushellIntegration '' - ${payRespectsCmd} nushell --alias [] - ''} + nushell.extraConfig = lib.mkIf cfg.enableNushellIntegration '' + source ${ + pkgs.runCommand "pay-respects-nushell-config" { } '' + ${payRespectsCmd} nushell ${cfgOptions} >> "$out" + '' + } ''; }; }; diff --git a/tests/modules/programs/pay-respects/integration-disabled.nix b/tests/modules/programs/pay-respects/integration-disabled.nix index a6453e354..f973fdbdc 100644 --- a/tests/modules/programs/pay-respects/integration-disabled.nix +++ b/tests/modules/programs/pay-respects/integration-disabled.nix @@ -1,3 +1,5 @@ +{ lib, realPkgs, ... }: + { programs = { pay-respects.enable = true; @@ -11,10 +13,12 @@ nushell.enable = true; }; + _module.args.pkgs = lib.mkForce realPkgs; + nmt.script = '' - assertFileNotRegex home-files/.bashrc '@pay-respects@/bin/pay-respects' - assertFileNotRegex home-files/.zshrc '@pay-respects@/bin/pay-respects' - assertFileNotRegex home-files/.config/fish/config.fish '@pay-respects@/bin/pay-respects' - assertFileNotRegex home-files/.config/nushell/config.nu '@pay-respects@/bin/pay-respects' + assertFileNotRegex home-files/.bashrc '/nix/store/[^/]*-pay-respects-[^/]*/bin/pay-respects' + assertFileNotRegex home-files/.zshrc '/nix/store/[^/]*-pay-respects-[^/]*/bin/pay-respects' + assertFileNotRegex home-files/.config/fish/config.fish '/nix/store/[^/]*-pay-respects-[^/]*/bin/pay-respects' + assertFileNotRegex home-files/.config/nushell/config.nu 'source /nix/store/[^/]*-pay-respects-nushell-config' ''; } diff --git a/tests/modules/programs/pay-respects/integration-enabled.nix b/tests/modules/programs/pay-respects/integration-enabled.nix index c76463f2b..e703f3632 100644 --- a/tests/modules/programs/pay-respects/integration-enabled.nix +++ b/tests/modules/programs/pay-respects/integration-enabled.nix @@ -1,3 +1,5 @@ +{ lib, realPkgs, ... }: + { programs = { pay-respects.enable = true; @@ -7,25 +9,27 @@ nushell.enable = true; }; + _module.args.pkgs = lib.mkForce realPkgs; + nmt.script = '' assertFileExists home-files/.bashrc - assertFileContains \ + assertFileRegex \ home-files/.bashrc \ - 'eval "$(@pay-respects@/bin/pay-respects bash --alias)"' + 'eval "$(/nix/store/[^/]*-pay-respects-[^/]*/bin/pay-respects bash --alias)"' assertFileExists home-files/.zshrc - assertFileContains \ + assertFileRegex \ home-files/.zshrc \ - 'eval "$(@pay-respects@/bin/pay-respects zsh --alias)"' + 'eval "$(/nix/store/[^/]*-pay-respects-[^/]*/bin/pay-respects zsh --alias)"' assertFileExists home-files/.config/fish/config.fish - assertFileContains \ + assertFileRegex \ home-files/.config/fish/config.fish \ - '@pay-respects@/bin/pay-respects fish --alias | source' + '/nix/store/[^/]*-pay-respects-[^/]*/bin/pay-respects fish --alias | source' assertFileExists home-files/.config/nushell/config.nu - assertFileContains \ + assertFileRegex \ home-files/.config/nushell/config.nu \ - '@pay-respects@/bin/pay-respects nushell --alias []' + 'source /nix/store/[^/]*-pay-respects-nushell-config' ''; }