summaryrefslogtreecommitdiffstats
path: root/modules/system/primary-user.nix
blob: 8f62f14b75b660d55e115296f37b29e949db1f77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{
  lib,
  config,
  ...
}:

{
  options = {
    system.primaryUser = lib.mkOption {
      type = lib.types.nullOr lib.types.str;
      default = null;
      description = ''
        The user used for options that previously applied to the user
        running `darwin-rebuild`.

        This is a transition mechanism as nix-darwin reorganizes its
        options and will eventually be unnecessary and removed.
      '';
    };

    system.primaryUserHome = lib.mkOption {
      internal = true;
      type = lib.types.str;
      default =
        config.users.users.${config.system.primaryUser}.home or "/Users/${config.system.primaryUser}";
    };

    system.requiresPrimaryUser = lib.mkOption {
      internal = true;
      type = lib.types.listOf lib.types.str;
      default = [ ];
    };
  };

  config = {
    assertions = [
      {
        assertion = config.system.primaryUser == null -> config.system.requiresPrimaryUser == [ ];
        message = ''
          Previously, some nix-darwin options applied to the user running
          `darwin-rebuild`. As part of a long‐term migration to make
          nix-darwin focus on system‐wide activation and support first‐class
          multi‐user setups, all system activation now runs as `root`, and
          these options instead apply to the `system.primaryUser` user.

          You currently have the following primary‐user‐requiring options set:

          ${lib.concatMapStringsSep "\n" (name: "* `${name}`") (
            lib.sort (name1: name2: name1 < name2) config.system.requiresPrimaryUser
          )}

          To continue using these options, set `system.primaryUser` to the name
          of the user you have been using to run `darwin-rebuild`.

          If you run into any unexpected issues with the migration, please
          open an issue at <https://github.com/nix-darwin/nix-darwin/issues/new>
          and include as much information as possible.
        '';
      }
    ];
  };
}