-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathssh.mod.nix
More file actions
196 lines (172 loc) · 4.67 KB
/
Copy pathssh.mod.nix
File metadata and controls
196 lines (172 loc) · 4.67 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
{ self, ... }:
{
flake.homeModules.ssh-client =
{
config,
lib,
osConfig,
...
}:
let
inherit (lib.attrsets)
attrValues
filterAttrs
mapAttrs
;
inherit (lib.lists) head singleton;
inherit (lib.modules) mkAfter;
inherit (lib.strings) concatLines optionalString;
hosts =
self.nixosConfigurations
|> filterAttrs (_: value: value.config.services.openssh.enable)
|> mapAttrs (
name: value:
let
inherit (value) config;
in
# sshclientconfig
''
Host ${name}
User root
# Tailscale.
HostName ${name}
Port ${toString <| head config.services.openssh.ports}
''
);
in
{
xdg.config.files."ssh/config".text =
concatLines
<|
attrValues hosts
++
singleton
# sshclientconfig
''
Host best
User root
HostName rgbcu.be
Port 2222
''
++
singleton
# sshclientconfig
''
Host *
SetEnv COLORTERM=truecolor TERM=xterm-256color
ControlMaster auto
ControlPersist 60m
ControlPath ${config.xdg.cache.directory}/ssh/%r@%n:%p
'';
xdg.cache.files."ssh".type = "directory";
programs.nushell.extraConfig =
mkAfter
<| optionalString osConfig.nixpkgs.hostPlatform.isDarwin /* nu */ ''
try {
$env.SSH_AUTH_SOCK = ^launchctl getenv SSH_AUTH_SOCK | str trim
}
'';
};
flake.homeModules.ssh-client-desktop =
{ pkgs, ... }:
{
packages = [
pkgs.mosh
];
programs.nushell.aliases.mosh = "mosh --no-init";
};
flake.nixosModules.ssh-server =
{
config,
lib,
pkgs,
...
}:
let
inherit (lib.lists) head singleton;
in
{
programs.mosh = {
enable = true;
openFirewall = true;
};
services.openssh = {
enable = true;
ports = singleton 2222;
settings = {
KbdInteractiveAuthentication = false;
PasswordAuthentication = false;
AcceptEnv = [
"SHELLS"
"COLORTERM"
];
};
};
users.users.root.openssh.authorizedKeys.keys = self.keys-admin;
boot.initrd.systemd.network = {
enable = true;
networks."10-wired" = {
matchConfig.Type = "ether";
networkConfig.DHCP = "yes";
};
};
boot.initrd.network.ssh = {
enable = true;
port = head config.services.openssh.ports;
ignoreEmptyHostKeys = true; # Create new keys.
authorizedKeys = config.users.users.root.openssh.authorizedKeys.keys;
};
};
flake.nixosModules.endlessh-go =
{
config,
lib,
pkgs,
...
}:
let
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) str port;
in
{
# And yes, I've tried lib.mkAliasOptionModule.
# It doesn't work for a mysterious reason,
# says it can't find `services.prometheus.exporters.endlessh-go`.
#
# This works, however.
#
# TODO: I may be stupid, because the above note says that I tried
# to alias to a nonexistent option, rather than the other way around.
# Let's try mkAliasOptionModule again later.
options.services.prometheus.exporters.endlessh-go = {
enable = mkEnableOption "Prometheus integration";
listenAddress = mkOption {
type = str;
default = "0.0.0.0";
};
port = mkOption {
type = port;
default = 2112;
};
};
config.services.prometheus.exporters.endlessh-go = {
enable = true;
listenAddress = "[::]";
};
# `services.endlessh-go.openFirewall` exposes both the Prometheus
# exporters port and the SSH port, and we don't want the metrics
# to leak, so we manually expose this like so.
config.networking.firewall.allowedTCPPorts = [ config.services.endlessh-go.port ];
config.services.endlessh-go = {
enable = true;
listenAddress = "[::]";
port = 22;
extraOptions = [
"-alsologtostderr"
"-geoip_supplier max-mind-db"
"-max_mind_db ${pkgs.dbip-country-lite}/share/dbip/dbip-country-lite.mmdb"
];
prometheus = config.services.prometheus.exporters.endlessh-go;
};
};
}