fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
2.7 KiB83 linesraw
1{ config, name, extendModules, lib, ... }:
2
3with lib;
4
5{
6  imports =
7    [ (mkRenamedOptionModule [ "specialization" ] [ "specialisation" ]) ];
8
9  options.specialisation = mkOption {
10    type = types.attrsOf (types.submodule {
11      options = {
12        configuration = mkOption {
13          type = let
14            extended = extendModules {
15              modules = [{
16                # Prevent infinite recursion
17                specialisation = mkOverride 0 { };
18
19                # If used inside the NixOS/nix-darwin module, we get conflicting definitions
20                # of `name` inside the specialisation: one is the user name coming from the
21                # NixOS module definition and the other is `configuration`, the name of this
22                # option. Thus we need to explicitly wire the former into the module arguments.
23                # See discussion at https://github.com/nix-community/home-manager/issues/3716
24                _module.args.name = mkForce name;
25              }];
26            };
27          in extended.type;
28          default = { };
29          visible = "shallow";
30          description = ''
31            Arbitrary Home Manager configuration settings.
32          '';
33        };
34      };
35    });
36    default = { };
37    description = ''
38      A set of named specialized configurations. These can be used to extend
39      your base configuration with additional settings. For example, you can
40      have specialisations named "light" and "dark"
41      that apply light and dark color theme configurations.
42
43      ::: {.note}
44      This is an experimental option for now and you therefore have to
45      activate the specialisation by looking up and running the activation
46      script yourself. Running the activation script will create a new
47      Home Manager generation.
48      :::
49
50      For example, to activate the "dark" specialisation, you can
51      first look up your current Home Manager generation by running
52
53      ```console
54      $ home-manager generations | head -1
55      2022-05-02 22:49 : id 1758 -> /nix/store/jy…ac-home-manager-generation
56      ```
57
58      then run
59
60      ```console
61      $ /nix/store/jy…ac-home-manager-generation/specialisation/dark/activate
62      Starting Home Manager activation
63      …
64      ```
65
66      ::: {.warning}
67      Since this option is experimental, the activation process may
68      change in backwards incompatible ways.
69      :::
70    '';
71  };
72
73  config = mkIf (config.specialisation != { }) {
74    home.extraBuilderCommands = let
75      link = n: v:
76        let pkg = v.configuration.home.activationPackage;
77        in "ln -s ${pkg} $out/specialisation/${n}";
78    in ''
79      mkdir $out/specialisation
80      ${concatStringsSep "\n" (mapAttrsToList link config.specialisation)}
81    '';
82  };
83}