mirror of
https://github.com/nix-community/home-manager
synced 2024-12-24 02:39:48 +01:00
specialization: add module
This module adds basic support for configuration specializations. These allow the user to build multiple alternative configurations that should be part of the same generation.
This commit is contained in:
parent
af828536ed
commit
0304f0f58b
5 changed files with 92 additions and 0 deletions
71
modules/misc/specialization.nix
Normal file
71
modules/misc/specialization.nix
Normal file
|
@ -0,0 +1,71 @@
|
|||
{ config, extendModules, lib, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
options.specialization = mkOption {
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
configuration = mkOption {
|
||||
type = let
|
||||
stopRecursion = { specialization = mkOverride 0 { }; };
|
||||
extended = extendModules { modules = [ stopRecursion ]; };
|
||||
in extended.type;
|
||||
default = { };
|
||||
visible = "shallow";
|
||||
description = ''
|
||||
Arbitrary Home Manager configuration settings.
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
default = { };
|
||||
description = ''
|
||||
A set of named specialized configurations. These can be used to extend
|
||||
your base configuration with additional settings. For example, you can
|
||||
have specializations named <quote>light</quote> and <quote>dark</quote>
|
||||
that applies light and dark color theme configurations.
|
||||
|
||||
</para><para>
|
||||
|
||||
Note, this is an experimental option for now and you therefore have to
|
||||
activate the specialization by looking up and running the activation
|
||||
script yourself. Note, running the activation script will create a new
|
||||
Home Manager generation.
|
||||
|
||||
</para><para>
|
||||
|
||||
For example, to activate the <quote>dark</quote> specialization. You can
|
||||
first look up your current Home Manager generation by running
|
||||
|
||||
<programlisting language="console">
|
||||
$ home-manager generations | head -1
|
||||
2022-05-02 22:49 : id 1758 -> /nix/store/jy…ac-home-manager-generation
|
||||
</programlisting>
|
||||
|
||||
then run
|
||||
|
||||
<programlisting language="console">
|
||||
$ /nix/store/jy…ac-home-manager-generation/specialization/dark/activate
|
||||
Starting Home Manager activation
|
||||
…
|
||||
</programlisting>
|
||||
|
||||
</para><para>
|
||||
|
||||
WARNING! Since this option is experimental, the activation process may
|
||||
change in backwards incompatible ways.
|
||||
'';
|
||||
};
|
||||
|
||||
config = mkIf (config.specialization != { }) {
|
||||
home.extraBuilderCommands = let
|
||||
link = n: v:
|
||||
let pkg = v.configuration.home.activationPackage;
|
||||
in "ln -s ${pkg} $out/specialization/${n}";
|
||||
in ''
|
||||
mkdir $out/specialization
|
||||
${concatStringsSep "\n" (mapAttrsToList link config.specialization)}
|
||||
'';
|
||||
};
|
||||
}
|
|
@ -30,6 +30,7 @@ let
|
|||
./misc/numlock.nix
|
||||
./misc/pam.nix
|
||||
./misc/qt.nix
|
||||
./misc/specialization.nix
|
||||
./misc/submodule-support.nix
|
||||
./misc/tmpfiles.nix
|
||||
./misc/version.nix
|
||||
|
|
|
@ -46,6 +46,7 @@ import nmt {
|
|||
./modules/home-environment
|
||||
./modules/misc/fontconfig
|
||||
./modules/misc/nix
|
||||
./modules/misc/specialization
|
||||
./modules/programs/alacritty
|
||||
./modules/programs/alot
|
||||
./modules/programs/aria2
|
||||
|
|
1
tests/modules/misc/specialization/default.nix
Normal file
1
tests/modules/misc/specialization/default.nix
Normal file
|
@ -0,0 +1 @@
|
|||
{ specialization = ./specialization.nix; }
|
18
tests/modules/misc/specialization/specialization.nix
Normal file
18
tests/modules/misc/specialization/specialization.nix
Normal file
|
@ -0,0 +1,18 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
home.file.testfile.text = "not special";
|
||||
specialization.test.configuration = {
|
||||
home.file.testfile.text = "very special";
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/testfile
|
||||
assertFileContains home-files/testfile "not special"
|
||||
|
||||
assertFileExists specialization/test/home-files/testfile
|
||||
assertFileContains specialization/test/home-files/testfile "not special"
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue