summaryrefslogtreecommitdiffstats
path: root/modules/by-name/us/users/module.nix
blob: b7f6297fec94e8eefcf4ca603981e2cbccef944b (plain) (blame)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{
  config,
  lib,
  pkgs,
  ...
}: let
  cfg = config.vhack.users;

  mkUser = {
    name,
    hashedPassword,
    uid,
    sshKey,
    groups,
    enableDeprecatedPlugdev,
  }: {
    inherit name;
    value = {
      inherit name uid hashedPassword;
      isNormalUser = true;
      createHome = true;
      home = "/home/${name}";
      extraGroups = groups ++ lib.optional enableDeprecatedPlugdev "plugdev";
      openssh.authorizedKeys.keys = [
        sshKey
      ];
    };
  };

  extraUsers = lib.listToAttrs (
    builtins.map mkUser cfg.users
  );
in {
  options.vhack.users = {
    enable = lib.mkEnableOption "user setup";
    users = lib.mkOption {
      type = lib.types.listOf (lib.types.submodule {
        options = {
          name = lib.mkOption {
            type = lib.types.str;
            description = "User name";
          };

          groups = lib.mkOption {
            type = lib.types.listOf lib.types.str;
            default = ["wheel"];
            description = "The groups the user should be part of";
          };

          # Although deprecated, this helps with old udev rules, that still use this group.
          # TODO: Try to find a way to remove this option (i.e. set it always to false).
          enableDeprecatedPlugdev = lib.mkEnableOption "the deprecated plugdev group for the user";

          hashedPassword = lib.mkOption {
            type = lib.types.str;
            description = "Hashed user password.";
          };
          sshKey = lib.mkOption {
            type = lib.types.str;
            description = "public ssh key, for ssh access.";
          };
          uid = lib.mkOption {
            type = lib.types.int;
            description = "UNIQUE user id, ideally greater than 1000.";
          };
        };
      });
      description = "Users";
    };
  };

  config = lib.mkIf cfg.enable {
    programs.fish = {
      enable = true;
      useBabelfish = true;
    };

    users = {
      mutableUsers = false;
      defaultUserShell = config.programs.fish.package;

      users =
        {
          root = {
            hashedPassword = lib.mkForce null; # to lock root
            openssh.authorizedKeys.keys = lib.mkForce [];
          };
        }
        // extraUsers;
    };
  };
}