mirror of
https://github.com/nix-community/home-manager.git
synced 2025-12-06 09:01:04 +01:00
specialisation: add default specialisation option
Add the option `specialisation.<name>.default`, which activates this specialisation by default.
This commit is contained in:
parent
c7fdb7e90b
commit
f8429e7ed6
1 changed files with 37 additions and 7 deletions
|
|
@ -6,6 +6,9 @@
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.specialisation;
|
||||||
|
in
|
||||||
{
|
{
|
||||||
imports = [ (lib.mkRenamedOptionModule [ "specialization" ] [ "specialisation" ]) ];
|
imports = [ (lib.mkRenamedOptionModule [ "specialization" ] [ "specialisation" ]) ];
|
||||||
|
|
||||||
|
|
@ -39,12 +42,22 @@
|
||||||
Arbitrary Home Manager configuration settings.
|
Arbitrary Home Manager configuration settings.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
default = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether this specialisation is activated by default.
|
||||||
|
Note that setting this option will override the default activation
|
||||||
|
script, making it impossible to activate the default
|
||||||
|
configuration.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
default = { };
|
default = { };
|
||||||
description = ''
|
description = ''
|
||||||
A set of named specialized configurations. These can be used to extend
|
A set of named specialised configurations. These can be used to extend
|
||||||
your base configuration with additional settings. For example, you can
|
your base configuration with additional settings. For example, you can
|
||||||
have specialisations named "light" and "dark"
|
have specialisations named "light" and "dark"
|
||||||
that apply light and dark color theme configurations.
|
that apply light and dark color theme configurations.
|
||||||
|
|
@ -79,11 +92,18 @@
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf (config.specialisation != { }) {
|
config = lib.mkIf (cfg != { }) {
|
||||||
assertions = map (n: {
|
assertions =
|
||||||
assertion = !lib.hasInfix "/" n;
|
[
|
||||||
message = "<name> in specialisation.<name> cannot contain a forward slash.";
|
{
|
||||||
}) (lib.attrNames config.specialisation);
|
assertion = count (s: s.default) (attrValues cfg) <= 1;
|
||||||
|
message = "There can only be one default specialisation";
|
||||||
|
}
|
||||||
|
]
|
||||||
|
++ map (n: {
|
||||||
|
assertion = !lib.hasInfix "/" n;
|
||||||
|
message = "<name> in specialisation.<name> cannot contain a forward slash.";
|
||||||
|
}) (lib.attrNames config.specialisation);
|
||||||
|
|
||||||
home.extraBuilderCommands =
|
home.extraBuilderCommands =
|
||||||
let
|
let
|
||||||
|
|
@ -96,7 +116,17 @@
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
mkdir $out/specialisation
|
mkdir $out/specialisation
|
||||||
${lib.concatStringsSep "\n" (lib.mapAttrsToList link config.specialisation)}
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList link cfg)}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
home.activation =
|
||||||
|
let
|
||||||
|
defaultSpecialisation = findFirst (s: s.default) null (attrValues cfg);
|
||||||
|
in
|
||||||
|
mkIf (defaultSpecialisation != null) (mkForce {
|
||||||
|
activateSpecialisation = ''
|
||||||
|
${defaultSpecialisation.configuration.home.activationPackage}/activate
|
||||||
|
'';
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue