summaryrefslogtreecommitdiff
path: root/modules/nixos/traits/host-user.nix
blob: 2da91d679e29bdf749581964e383c20d9e5b5833 (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
{
  config,
  lib,
  pkgs,
  secretsDir,
  ...
}: let
  cfg = config.traits.users.hostUser;
  inherit (config.networking) hostName;
in {
  options.traits.users.hostUser = {
    enable = lib.mkEnableOption "${hostName} user configuration";
    manageSecrets =
      lib.mkEnableOption "automatic secrets management"
      // {
        default = config.traits.secrets.enable;
      };
  };

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

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

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