aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/modules/harness/users.nix
blob: 6586e7b0dea0ea679414759f920e01727d756824 (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
{ config, lib, pkgs, ... }:

with lib;
let
  # Defines the structure of a libkookie user definition
  userCfg = with types; (submodule {
    options = {
      name = mkOption { type = str; description = "The name of the user"; };
      cfg = mkOption { description = "The user configuration"; };
      pubkeys = mkOption { type = listOf str;
                           default = [];
                           description = "Set of ssh public keys to include"; };
    };
  });
in
{
  options.libkookie = {
    activeUsers = mkOption {
      type = with types; listOf userCfg;
      default = [];
      description = ''
        List of active users on this system.  This set is used to
        determine for which users the home-manager specific modules
        need to be included, or which ssh pubkeys are installed.
      '';
    };
  };

  config = {
    users.mutableUsers = false;
    users.users = builtins.listToAttrs (map ({ name, cfg, pubkeys }:
      nameValuePair "${name}"
        (cfg // { group = "${name}"; openssh.authorizedKeys.keys = pubkeys; })) config.libkookie.activeUsers);

    users.groups = builtins.listToAttrs (map ({ name, ... }:
      nameValuePair "${name}" {}) config.libkookie.activeUsers);

  };
}