summaryrefslogtreecommitdiff
path: root/modules/nixos/server/host-user.nix
blob: 0764cb064c956f340bba40bfd6c77e57acb5a9e5 (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
{
  config,
  lib,
  secretsDir,
  ...
}:
let
  cfg = config.server.hostUser;
  inherit (config.networking) hostName;
in
{
  options.server.hostUser = {
    enable = lib.mkEnableOption "${hostName} user configuration" // {
      default = config.server.enable;
    };

    manageSecrets = lib.mkEnableOption "automatic management of secrets" // {
      default = config.traits.secrets.enable;
      defaultText = lib.literalExpression "config.traits.secrets.enable";
    };
  };

  config = lib.mkIf cfg.enable (
    lib.mkMerge [
      {
        users.users.${hostName} = {
          isNormalUser = true;
          extraGroups = [ "wheel" ];
        };
      }

      (lib.mkIf cfg.manageSecrets {
        age.secrets = {
          userPassword.file = secretsDir + "/userPassword.age";
        };

        users.users.${hostName} = {
          hashedPasswordFile = config.age.secrets.userPassword.path;
        };
      })
    ]
  );
}