infat: allow customization of autoActivate

This commit is contained in:
Mirko Lenz
2026-03-19 10:22:05 +01:00
committed by Austin Horstman
parent 8962c2a0f4
commit 5a608a621b
4 changed files with 142 additions and 13 deletions

View File

@@ -7,6 +7,7 @@
let
cfg = config.programs.infat;
tomlFormat = pkgs.formats.toml { };
mkCli = lib.cli.toCommandLineShellGNU { };
configDir =
if config.xdg.enable then
@@ -47,7 +48,22 @@ in
{file}`$XDG_CONFIG_HOME/infat/config.toml`.
'';
};
autoActivate = lib.mkEnableOption "auto-activate infat" // {
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 = ''
@@ -58,20 +74,72 @@ in
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 = ''
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.
'';
};
};
};
config = lib.mkIf cfg.enable {
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) {
activation =
lib.mkIf (cfg.package != null && cfg.autoActivate.enable && cfg.autoActivate.extraArgs ? config)
{
infat = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
run ${lib.getExe cfg.package} --config "${configFile}" $VERBOSE_ARG
run ${lib.getExe cfg.package} ${mkCli cfg.autoActivate.extraArgs} $VERBOSE_ARG
'';
};
};

View File

@@ -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'
'';
}

View File

@@ -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;
}

View File

@@ -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'
'';
}