default-specialisation: add test for default specialisation

This commit is contained in:
Weathercold 2022-10-08 16:29:46 -04:00
parent 01a518ba06
commit c00a3920ce
No known key found for this signature in database
GPG key ID: 059102E35214D867
3 changed files with 43 additions and 36 deletions

View file

@ -11,23 +11,21 @@ in {
type = types.attrsOf (types.submodule { type = types.attrsOf (types.submodule {
options = { options = {
configuration = mkOption { configuration = mkOption {
type = type = let
let extended = extendModules {
extended = extendModules { modules = [{
modules = [{ # Prevent infinite recursion
# Prevent infinite recursion specialisation = mkOverride 0 { };
specialisation = 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 = mkForce name; _module.args.name = mkForce name;
}]; }];
}; };
in in extended.type;
extended.type;
default = { }; default = { };
visible = "shallow"; visible = "shallow";
description = '' description = ''
@ -89,25 +87,21 @@ in {
message = "There can only be one default specialisation"; message = "There can only be one default specialisation";
}]; }];
home.extraBuilderCommands = home.extraBuilderCommands = let
let link = n: v:
link = n: v: let pkg = v.configuration.home.activationPackage;
let pkg = v.configuration.home.activationPackage; in "ln -s ${pkg} $out/specialisation/${n}";
in "ln -s ${pkg} $out/specialisation/${n}"; in ''
in mkdir $out/specialisation
'' ${concatStringsSep "\n" (mapAttrsToList link cfg)}
mkdir $out/specialisation '';
${concatStringsSep "\n" (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 });
'';
});
}; };
} }

View 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"
'';
}

View file

@ -1 +1,4 @@
{ specialisation = ./specialisation.nix; } {
specialisation = ./specialisation.nix;
default-specialisation = ./default-specialisation.nix;
}