mirror of
https://github.com/nix-community/home-manager.git
synced 2026-06-05 21:02:51 +00:00
infat: allow customization of autoActivate
This commit is contained in:
committed by
Austin Horstman
parent
8962c2a0f4
commit
5a608a621b
@@ -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
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
30
tests/modules/programs/infat/auto-activate-args.nix
Normal file
30
tests/modules/programs/infat/auto-activate-args.nix
Normal 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'
|
||||
'';
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user