diff --git a/modules/programs/infat.nix b/modules/programs/infat.nix index 9a9dd9cbb..0c683ba03 100644 --- a/modules/programs/infat.nix +++ b/modules/programs/infat.nix @@ -7,7 +7,6 @@ let cfg = config.programs.infat; tomlFormat = pkgs.formats.toml { }; - mkCli = lib.cli.toCommandLineShellGNU { }; configDir = if config.xdg.enable then @@ -75,18 +74,12 @@ in ''; }; extraArgs = lib.mkOption { - type = - with lib.types; - attrsOf (oneOf [ - str - bool - ]); - default = { - robust = true; - }; - example = { - quiet = true; - }; + type = lib.types.listOf lib.types.str; + default = [ "--robust" ]; + example = [ + "--robust" + "--quiet" + ]; description = '' Additional arguments to pass when auto-activating infat. This can be used to customize the behavior of infat when @@ -104,9 +97,10 @@ in default = { }; example = { enable = true; - extraArgs = { - quiet = true; - }; + extraArgs = [ + "--robust" + "--quiet" + ]; }; description = '' Auto-activation settings for infat. @@ -122,24 +116,38 @@ in assertions = [ (lib.hm.assertions.assertPlatform "programs.infat" pkgs lib.platforms.darwin) ]; + warnings = lib.optional cfg.autoActivate._legacyBoolean '' Using `programs.infat.autoActivate` as a Boolean is deprecated and will be removed in a future release. Please use `programs.infat.autoActivate.enable` instead. ''; - programs.infat.autoActivate.extraArgs = lib.mkIf (cfg.settings != { }) { - config = configFile; - }; + home = { packages = lib.mkIf (cfg.package != null) [ cfg.package ]; + file.${configFile} = lib.mkIf (cfg.settings != { }) { source = tomlFormat.generate "infat-settings.toml" cfg.settings; }; + activation = - lib.mkIf (cfg.package != null && cfg.autoActivate.enable && cfg.autoActivate.extraArgs ? config) + let + autoActivateExtraArgs = + cfg.autoActivate.extraArgs + ++ lib.optionals (cfg.settings != { } && !lib.elem "--config" cfg.autoActivate.extraArgs) [ + "--config" + configFile + ]; + in + lib.mkIf + ( + cfg.package != null + && cfg.autoActivate.enable + && (cfg.settings != { } || lib.elem "--config" cfg.autoActivate.extraArgs) + ) { infat = lib.hm.dag.entryAfter [ "writeBoundary" ] '' - run ${lib.getExe cfg.package} ${mkCli cfg.autoActivate.extraArgs} $VERBOSE_ARG + run ${lib.getExe cfg.package} ${lib.escapeShellArgs autoActivateExtraArgs} $VERBOSE_ARG ''; }; }; diff --git a/tests/modules/programs/infat/auto-activate-args.nix b/tests/modules/programs/infat/auto-activate-args.nix index 880c087ff..36fafafc2 100644 --- a/tests/modules/programs/infat/auto-activate-args.nix +++ b/tests/modules/programs/infat/auto-activate-args.nix @@ -1,18 +1,7 @@ -{ - config, - pkgs, - ... -}: - -let - activationScript = pkgs.writeText "activation-script" config.home.activation.infat.data; -in { programs.infat = { enable = true; - autoActivate.extraArgs = { - quiet = true; - }; + autoActivate.extraArgs = [ "--quiet" ]; settings = { extensions = { md = "TextEdit"; @@ -23,8 +12,8 @@ in test.stubs.infat = { }; nmt.script = '' - assertFileRegex "${activationScript}" '.*--config' - assertFileRegex "${activationScript}" '.*--quiet' - assertFileNotRegex "${activationScript}" '.*--robust' + assertFileContains activate ' --config' + assertFileContains activate ' --quiet' + assertFileNotRegex activate '.*--robust' ''; } diff --git a/tests/modules/programs/infat/example-settings.nix b/tests/modules/programs/infat/example-settings.nix index a9980d788..a90b200ac 100644 --- a/tests/modules/programs/infat/example-settings.nix +++ b/tests/modules/programs/infat/example-settings.nix @@ -35,5 +35,6 @@ '' assertFileExists "${expectedConfigPath}" assertFileContent "${expectedConfigPath}" "${expectedConfigContent}" + assertFileContains activate ' --robust' ''; }