forked from input-output-hk/marlowe-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
access.nix
63 lines (60 loc) · 1.77 KB
/
access.nix
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
{ lib, config, pkgs, ... }:
let
inherit (lib) types mkOption optionals;
userType = types.submodule {
options = {
admin = mkOption {
type = types.bool;
default = false;
description = "Whether the user is an admin";
};
keys = mkOption {
type = types.listOf types.str;
description = "The user's SSH public key";
};
name = mkOption {
type = types.str;
description = "The user's name";
};
};
};
admin-keys = lib.concatMap (name:
let user = config.marlowe.users.${name};
in optionals user.admin user.keys)
(builtins.attrNames config.marlowe.users);
in {
options = {
marlowe.users = lib.mkOption {
type = lib.types.attrsOf userType;
internal = true;
description = "The users with access to the machine";
};
};
config = {
marlowe.users = lib.importTOML ./users.toml;
users.users = {
#FIXME should not be needed with --use-remote-sudo, but that's not working...
root.openssh.authorizedKeys.keys = admin-keys;
} // lib.mapAttrs (_: user:
{
isNormalUser = true;
openssh.authorizedKeys.keys = user.keys;
description = user.name;
} // lib.optionalAttrs user.admin { extraGroups = [ "wheel" ]; })
config.marlowe.users;
# Enable SSH + mosh
environment.systemPackages = with pkgs; [ mosh ];
services.openssh.enable = true;
services.openssh.hostKeys = [{
path = "/etc/ssh/ssh_host_ed25519_key";
type = "ed25519";
}];
networking.firewall.allowedTCPPorts = [ 22 ];
networking.firewall.allowedUDPPortRanges = lib.singleton {
from = 60001;
to = 60999;
};
security.pam.enableSSHAgentAuth = true;
security.pam.services.sudo.sshAgentAuth = true;
};
}