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" ]) ];
|
||||
|
||||
|
|
@ -39,12 +42,22 @@
|
|||
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 = { };
|
||||
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
|
||||
have specialisations named "light" and "dark"
|
||||
that apply light and dark color theme configurations.
|
||||
|
|
@ -79,11 +92,18 @@
|
|||
'';
|
||||
};
|
||||
|
||||
config = lib.mkIf (config.specialisation != { }) {
|
||||
assertions = map (n: {
|
||||
assertion = !lib.hasInfix "/" n;
|
||||
message = "<name> in specialisation.<name> cannot contain a forward slash.";
|
||||
}) (lib.attrNames config.specialisation);
|
||||
config = lib.mkIf (cfg != { }) {
|
||||
assertions =
|
||||
[
|
||||
{
|
||||
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 =
|
||||
let
|
||||
|
|
@ -96,7 +116,17 @@
|
|||
in
|
||||
''
|
||||
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