1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-06 09:01:04 +01:00

default-specialisation: add test for default specialisation

This commit is contained in:
Weathercold 2022-10-08 16:29:46 -04:00 committed by Weathercold
parent f8429e7ed6
commit f16a27debc
3 changed files with 48 additions and 41 deletions

View file

@ -17,25 +17,23 @@ in
lib.types.submodule {
options = {
configuration = lib.mkOption {
type =
let
extended = extendModules {
modules = [
{
# Prevent infinite recursion
specialisation = lib.mkOverride 0 { };
type = let
extended = extendModules {
modules = [
{
# Prevent infinite recursion
specialisation = lib.mkOverride 0 { };
# If used inside the NixOS/nix-darwin module, we get conflicting definitions
# of `name` inside the specialisation: one is the user name coming from the
# NixOS module definition and the other is `configuration`, the name of this
# option. Thus we need to explicitly wire the former into the module arguments.
# See discussion at https://github.com/nix-community/home-manager/issues/3716
_module.args.name = lib.mkForce name;
}
];
};
in
extended.type;
# If used inside the NixOS/nix-darwin module, we get conflicting definitions
# of `name` inside the specialisation: one is the user name coming from the
# NixOS module definition and the other is `configuration`, the name of this
# option. Thus we need to explicitly wire the former into the module arguments.
# See discussion at https://github.com/nix-community/home-manager/issues/3716
_module.args.name = lib.mkForce name;
}
];
};
in extended.type;
default = { };
visible = "shallow";
description = ''
@ -105,28 +103,24 @@ in
message = "<name> in specialisation.<name> cannot contain a forward slash.";
}) (lib.attrNames config.specialisation);
home.extraBuilderCommands =
let
link =
n: v:
let
pkg = v.configuration.home.activationPackage;
in
"ln -s ${pkg} $out/specialisation/${lib.escapeShellArg n}";
in
''
mkdir $out/specialisation
${lib.concatStringsSep "\n" (lib.mapAttrsToList link cfg)}
'';
home.extraBuilderCommands = let
link =
n: v:
let
pkg = v.configuration.home.activationPackage;
in
"ln -s ${pkg} $out/specialisation/${lib.escapeShellArg n}";
in ''
mkdir $out/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
'';
});
home.activation = let
defaultSpecialisation = findFirst (s: s.default) null (attrValues cfg);
in mkIf (defaultSpecialisation != null) (mkForce {
activateSpecialisation = ''
${defaultSpecialisation.configuration.home.activationPackage}/activate
'';
});
};
}