summaryrefslogtreecommitdiff
path: root/modules/nixos/traits/users.nix
blob: 3302366df7fc28d47d0f42bfa3ec71e3e5bb16f6 (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
{
  config,
  lib,
  pkgs,
  secretsDir,
  ...
}: let
  cfg = config.traits.users;
  inherit (config.networking) hostName;
in {
  imports = [
    ../../../users/seth/nixos.nix
  ];

  options.traits.users = {
    hostUser = {
      enable = lib.mkEnableOption "${hostName} user configuration";
      manageSecrets =
        lib.mkEnableOption "automatically manage secrets"
        // {
          default = config.traits.secrets.enable;
        };
    };
  };

  config = lib.mkMerge [
    (lib.mkIf cfg.hostUser.enable {
      users.users.${hostName} = {
        isNormalUser = true;
        shell = pkgs.bash;
      };
    })

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

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