-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
92 lines (86 loc) · 2.81 KB
/
flake.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
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
{
description = ''
A garnix module for adding Linux users and allowing remote access through `SSH`.
[Documentation](https://garnix.io/docs/modules/user) - [Source](https://github.com/garnix-io/user-module).
'';
outputs =
{ self }:
{
garnixModules.default =
{
pkgs,
lib,
config,
...
}:
let
userSubmodule.options = {
user =
lib.mkOption {
type = lib.types.nonEmptyStr;
description = "The Linux username.";
example = "alice";
}
// {
name = "user name";
};
groups = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "The groups the user belongs to.";
example = [ "wheel" ];
default = [ ];
};
shell = lib.mkOption {
type = lib.types.enum [
"bash"
"zsh"
"fish"
];
default = "bash";
description = "The users login shell.";
};
authorizedSshKeys =
lib.mkOption {
type = lib.types.listOf lib.types.nonEmptyStr;
description = ''
The public SSH keys that can be used to log in as this user. (Note that you must
use the IP address rather than domain for SSH.)'';
}
// {
name = "SSH keys";
};
};
in
{
options = {
user = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule userSubmodule);
description = "An attrset of users.";
};
};
config = {
nixosConfigurations.default = builtins.attrValues (
builtins.mapAttrs (name: projectConfig: {
users.users.${projectConfig.user} = {
extraGroups = projectConfig.groups;
isNormalUser = true;
shell = pkgs.${projectConfig.shell};
openssh.authorizedKeys.keys = projectConfig.authorizedSshKeys;
};
programs.zsh.enable = projectConfig.shell == "zsh";
programs.fish.enable = projectConfig.shell == "fish";
services.openssh = {
enable = true;
settings = {
PasswordAuthentication = false;
KbdInteractiveAuthentication = false;
AuthenticationMethods = "publickey";
PermitRootLogin = "prohibit-password";
};
};
}) config.user
);
};
};
};
}