infra/roles/builder/users.nix

62 lines
1.2 KiB
Nix
Raw Normal View History

2022-01-09 15:40:38 +01:00
{ pkgs, ... }:
2022-01-09 15:34:55 +01:00
let
inherit (pkgs) lib;
users = {
# 1. Generate an SSH key for your root account and add the public
# key to a file matching your name in ./keys/
#
# 2. Copy / paste this in order, alphabetically:
#
2022-01-16 10:23:57 -05:00
# youruser.keys = ./keys/youruser;
#
2022-01-09 15:34:55 +01:00
"0x4A6F" = {
trusted = true;
keys = ./keys/0x4A6F;
};
ckie.keys = ./keys/ckie;
2022-01-09 15:34:55 +01:00
jtojnar = {
trusted = true;
keys = ./keys/jtojnar;
};
2022-01-16 10:23:57 -05:00
winter.keys = ./keys/winter;
2022-02-09 08:15:28 +10:00
zowoq = {
trusted = true;
keys = ./keys/zowoq;
};
2022-01-09 15:34:55 +01:00
};
ifAttr = key: default: result: opts:
if (opts ? "${key}") && opts."${key}"
then result
else default;
maybeTrusted = ifAttr "trusted" [] [ "trusted" ];
maybeWheel = ifAttr "sudo" [] [ "wheel" ];
userGroups = opts:
(maybeTrusted opts) ++
(maybeWheel opts);
descToUser = name: opts:
{
isNormalUser = true;
extraGroups = userGroups opts;
createHome = true;
home = "/home/${name}";
hashedPassword = opts.password or null;
openssh.authorizedKeys.keyFiles = [
opts.keys
];
};
in {
users = {
mutableUsers = false;
users = lib.mapAttrs descToUser users;
};
}