From 5a608a621b001922dd708ca51a6260d5bef9e29b Mon Sep 17 00:00:00 2001 From: Mirko Lenz Date: Thu, 19 Mar 2026 10:22:05 +0100 Subject: [PATCH] infat: allow customization of autoActivate --- modules/programs/infat.nix | 94 ++++++++++++++++--- .../programs/infat/auto-activate-args.nix | 30 ++++++ tests/modules/programs/infat/default.nix | 2 + .../infat/deprecated-auto-activate-bool.nix | 29 ++++++ 4 files changed, 142 insertions(+), 13 deletions(-) create mode 100644 tests/modules/programs/infat/auto-activate-args.nix create mode 100644 tests/modules/programs/infat/deprecated-auto-activate-bool.nix diff --git a/modules/programs/infat.nix b/modules/programs/infat.nix index 009dbb795..9a9dd9cbb 100644 --- a/modules/programs/infat.nix +++ b/modules/programs/infat.nix @@ -7,6 +7,7 @@ let cfg = config.programs.infat; tomlFormat = pkgs.formats.toml { }; + mkCli = lib.cli.toCommandLineShellGNU { }; configDir = if config.xdg.enable then @@ -47,15 +48,72 @@ in {file}`$XDG_CONFIG_HOME/infat/config.toml`. ''; }; - autoActivate = lib.mkEnableOption "auto-activate infat" // { - default = true; - example = false; + autoActivate = lib.mkOption { + type = + lib.types.coercedTo lib.types.bool + (enable: { + inherit enable; + _legacyBoolean = true; + }) + ( + lib.types.submodule { + options = { + _legacyBoolean = lib.mkOption { + type = lib.types.bool; + default = false; + visible = false; + }; + enable = lib.mkEnableOption "auto-activate infat" // { + default = true; + example = false; + description = '' + Automatically activate infat on startup. + This is useful if you want to use infat as a + default application handler for certain file types. + If you don't want this, set this to false. + This option is only effective if `settings` is set. + ''; + }; + extraArgs = lib.mkOption { + type = + with lib.types; + attrsOf (oneOf [ + str + bool + ]); + default = { + robust = true; + }; + example = { + quiet = true; + }; + description = '' + Additional arguments to pass when auto-activating infat. + This can be used to customize the behavior of infat when + it is auto-activated on startup. Call `infat --help` + for more information on available arguments. + If {option}`programs.infat.settings` is set, + `config` will be added automatically. + Otherwise you can set `config` to point + to a custom configuration file. + ''; + }; + }; + } + ); + default = { }; + example = { + enable = true; + extraArgs = { + quiet = true; + }; + }; description = '' - Automatically activate infat on startup. - This is useful if you want to use infat as a - default application handler for certain file types. - If you don't want this, set this to false. - This option is only effective if `settings` is set. + Auto-activation settings for infat. + + For backwards compatibility, this option also accepts a boolean. + Boolean values are deprecated; use + {option}`programs.infat.autoActivate.enable` instead. ''; }; }; @@ -64,16 +122,26 @@ 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.settings != { } && cfg.package != null && cfg.autoActivate) { - infat = lib.hm.dag.entryAfter [ "writeBoundary" ] '' - run ${lib.getExe cfg.package} --config "${configFile}" $VERBOSE_ARG - ''; - }; + activation = + lib.mkIf (cfg.package != null && cfg.autoActivate.enable && cfg.autoActivate.extraArgs ? config) + { + infat = lib.hm.dag.entryAfter [ "writeBoundary" ] '' + run ${lib.getExe cfg.package} ${mkCli cfg.autoActivate.extraArgs} $VERBOSE_ARG + ''; + }; }; }; } diff --git a/tests/modules/programs/infat/auto-activate-args.nix b/tests/modules/programs/infat/auto-activate-args.nix new file mode 100644 index 000000000..880c087ff --- /dev/null +++ b/tests/modules/programs/infat/auto-activate-args.nix @@ -0,0 +1,30 @@ +{ + config, + pkgs, + ... +}: + +let + activationScript = pkgs.writeText "activation-script" config.home.activation.infat.data; +in +{ + programs.infat = { + enable = true; + autoActivate.extraArgs = { + quiet = true; + }; + settings = { + extensions = { + md = "TextEdit"; + }; + }; + }; + + test.stubs.infat = { }; + + nmt.script = '' + assertFileRegex "${activationScript}" '.*--config' + assertFileRegex "${activationScript}" '.*--quiet' + assertFileNotRegex "${activationScript}" '.*--robust' + ''; +} diff --git a/tests/modules/programs/infat/default.nix b/tests/modules/programs/infat/default.nix index 8fdd5ecc1..c28aa91d3 100644 --- a/tests/modules/programs/infat/default.nix +++ b/tests/modules/programs/infat/default.nix @@ -1,6 +1,8 @@ { lib, pkgs, ... }: lib.optionalAttrs pkgs.stdenv.hostPlatform.isDarwin { + infat-auto-activate-args = ./auto-activate-args.nix; + infat-deprecated-auto-activate-bool = ./deprecated-auto-activate-bool.nix; infat-example-settings = ./example-settings.nix; infat-no-settings = ./no-settings.nix; } diff --git a/tests/modules/programs/infat/deprecated-auto-activate-bool.nix b/tests/modules/programs/infat/deprecated-auto-activate-bool.nix new file mode 100644 index 000000000..e4f98863c --- /dev/null +++ b/tests/modules/programs/infat/deprecated-auto-activate-bool.nix @@ -0,0 +1,29 @@ +_: + +{ + programs.infat = { + enable = true; + autoActivate = false; + settings = { + extensions = { + md = "TextEdit"; + }; + }; + }; + + test = { + asserts.warnings.expected = [ + '' + Using `programs.infat.autoActivate` as a Boolean is deprecated and will be + removed in a future release. Please use `programs.infat.autoActivate.enable` + instead. + '' + ]; + + stubs.infat = { }; + }; + + nmt.script = '' + assertFileNotRegex activate '.*@infat@/bin/infat' + ''; +}