mirror of
https://github.com/nix-community/home-manager.git
synced 2025-12-06 17:11:03 +01:00
default-specialisation: add test for default specialisation
This commit is contained in:
parent
f8429e7ed6
commit
f16a27debc
3 changed files with 48 additions and 41 deletions
|
|
@ -17,25 +17,23 @@ in
|
||||||
lib.types.submodule {
|
lib.types.submodule {
|
||||||
options = {
|
options = {
|
||||||
configuration = lib.mkOption {
|
configuration = lib.mkOption {
|
||||||
type =
|
type = let
|
||||||
let
|
extended = extendModules {
|
||||||
extended = extendModules {
|
modules = [
|
||||||
modules = [
|
{
|
||||||
{
|
# Prevent infinite recursion
|
||||||
# Prevent infinite recursion
|
specialisation = lib.mkOverride 0 { };
|
||||||
specialisation = lib.mkOverride 0 { };
|
|
||||||
|
|
||||||
# If used inside the NixOS/nix-darwin module, we get conflicting definitions
|
# 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
|
# 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
|
# 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.
|
# 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
|
# See discussion at https://github.com/nix-community/home-manager/issues/3716
|
||||||
_module.args.name = lib.mkForce name;
|
_module.args.name = lib.mkForce name;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
in
|
in extended.type;
|
||||||
extended.type;
|
|
||||||
default = { };
|
default = { };
|
||||||
visible = "shallow";
|
visible = "shallow";
|
||||||
description = ''
|
description = ''
|
||||||
|
|
@ -105,28 +103,24 @@ in
|
||||||
message = "<name> in specialisation.<name> cannot contain a forward slash.";
|
message = "<name> in specialisation.<name> cannot contain a forward slash.";
|
||||||
}) (lib.attrNames config.specialisation);
|
}) (lib.attrNames config.specialisation);
|
||||||
|
|
||||||
home.extraBuilderCommands =
|
home.extraBuilderCommands = let
|
||||||
let
|
link =
|
||||||
link =
|
n: v:
|
||||||
n: v:
|
let
|
||||||
let
|
pkg = v.configuration.home.activationPackage;
|
||||||
pkg = v.configuration.home.activationPackage;
|
in
|
||||||
in
|
"ln -s ${pkg} $out/specialisation/${lib.escapeShellArg n}";
|
||||||
"ln -s ${pkg} $out/specialisation/${lib.escapeShellArg n}";
|
in ''
|
||||||
in
|
mkdir $out/specialisation
|
||||||
''
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList link cfg)}
|
||||||
mkdir $out/specialisation
|
'';
|
||||||
${lib.concatStringsSep "\n" (lib.mapAttrsToList link cfg)}
|
|
||||||
'';
|
|
||||||
|
|
||||||
home.activation =
|
home.activation = let
|
||||||
let
|
defaultSpecialisation = findFirst (s: s.default) null (attrValues cfg);
|
||||||
defaultSpecialisation = findFirst (s: s.default) null (attrValues cfg);
|
in mkIf (defaultSpecialisation != null) (mkForce {
|
||||||
in
|
activateSpecialisation = ''
|
||||||
mkIf (defaultSpecialisation != null) (mkForce {
|
${defaultSpecialisation.configuration.home.activationPackage}/activate
|
||||||
activateSpecialisation = ''
|
'';
|
||||||
${defaultSpecialisation.configuration.home.activationPackage}/activate
|
});
|
||||||
'';
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
tests/modules/misc/specialisation/default-specialisation.nix
Normal file
10
tests/modules/misc/specialisation/default-specialisation.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
{ config, ... }: {
|
||||||
|
home.file.testfile.text = "not special";
|
||||||
|
specialisation = { test.default = true; };
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertFileExists activate
|
||||||
|
assertFileContains activate \
|
||||||
|
"${config.specialisation.test.configuration.home.activationPackage}/activate"
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
|
@ -1 +1,4 @@
|
||||||
{ specialisation = ./specialisation.nix; }
|
{
|
||||||
|
specialisation = ./specialisation.nix;
|
||||||
|
default-specialisation = ./default-specialisation.nix;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue