-
Notifications
You must be signed in to change notification settings - Fork 13
/
nas.nix
312 lines (311 loc) · 9.53 KB
/
nas.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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
{ pkgs, lib, config, ... }:
with lib;
let
passwords = import ./load-secrets.nix;
keys = import ./keys.nix;
overlay1 = self: super: {
ntp = super.ntp.overrideAttrs (drv: {
patches = drv.patches or [] ++ [ ./openat.patch ];
});
};
sources = import ./nix/sources.nix;
iohk-ops = sources.iohk-ops;
#nix-src = builtins.fetchTarball "https://github.com/nixos/nix/archive/374fe49ff78c13457c6cfe396f9ed0cb986c903b.tar.gz";
#nix-flake = builtins.getFlake "github.com:cleverca22/nix?rev=374fe49ff78c13457c6cfe396f9ed0cb986c903b";
#nix-flake = builtins.getFlake (builtins.unsafeDiscardStringContext nix-src);
#nix = nix-flake.defaultPackage.x86_64-linux;
flake = builtins.getFlake (toString ./.);
in {
imports = [
#./cardano-relay.nix
#./datadog.nix
#./nas-wifi.nix
(iohk-ops + "/modules/monitoring-exporters.nix")
./cachecache.nix
./clevers_machines.nix
./exporter.nix
./home-assistant.nix
./iohk-binary-cache.nix
./media-center.nix
./nas-hydra.nix
./nas-monitoring-rewrite.nix
./nas-monitoring.nix
./nas-websites.nix
./nixops-managed.nix
./rtmp.nix
./snmpd.nix
./syncplay.nix
./tgt_service.nix
./zdb.nix
./zfs-patch.nix
<nixpkgs/nixos/modules/installer/scan/not-detected.nix>
];
boot = {
initrd.availableKernelModules = [
"ahci" # SATA
"ehci_pci" # USB
"nvme"
"ohci_pci" # USB
"sd_mod"
"usb_storage"
"usbhid"
"xhci_pci" # USB
#"rr3740a"
];
loader.grub = {
device = "/dev/sdf";
configurationLimit = 1;
};
kernelModules = [ "tcp_bbr" "kvm-amd" ];
kernel.sysctl = {
"net.ipv4.tcp_congestion_control" = "bbr";
"fs.inotify.max_user_watches" = "100000";
};
extraModprobeConfig = ''
options netconsole [email protected]/eth0,[email protected]/00:1c:c4:6e:00:46
'';
kernelParams = [
#"maxcpus=1"
"zfs.zfs_active_allocator=cursor"
];
extraModulePackages = [
#config.boot.kernelPackages.rr3740a
];
};
environment = {
systemPackages = with pkgs; [
ethtool
file
flake.inputs.zfs-utils.packages.x86_64-linux.gang-finder
flake.inputs.zfs-utils.packages.x86_64-linux.txg-watcher
gdb
iotop
jq
lsof
nvme-cli
pciutils usbutils # lsusb and lspci
pv
rtorrent
smartmontools
socat
sysstat
tcpdump
tgt
vnstat
];
};
fileSystems = {
"/" = { device = "naspool/root"; fsType = "zfs"; };
"/boot" = { device = "UUID=f5c56a8b-edcd-44ca-8814-490bf43ab576"; fsType = "ext4"; };
"/home" = { device = "naspool/home"; fsType = "zfs"; };
"/home/clever/downloading" = { device = "naspool/downloading"; fsType = "zfs"; };
"/media/videos/4tb" = { device = "c2d:/media/videos/4tb"; fsType = "nfs"; options = [ "soft" ]; };
"/nix" = { device = "naspool/nix"; fsType = "zfs"; };
"/var/lib/deluge" = { device = "naspool/deluge"; fsType = "zfs"; };
"/zfs-defrag" = { device = "/dev/media/zfs-defrag"; fsType = "ext4"; };
};
swapDevices = [
{ device = "/dev/media/swap"; }
];
networking = {
timeServers = [
"router"
"amd"
"system76"
"c2d"
];
defaultGateway = "10.0.0.1";
firewall = {
allowedTCPPorts = [
80 443
1337
1935 1936 # rtmp.nix
111 2049 # nfs
3260
10011 30033 30034 # ts3
58846 8112 # deluge
8081
8333 # bitcoin
6991 # rtorrent
20048 # nfs
];
allowedUDPPorts = [
161
123 # ntp
111 2049 # nfs
9987 # ts3
9990 # ts3 2nd
33445
];
};
hostId = "491ddec8";
hostName = "nas";
nameservers = [ "10.0.0.1" ];
search = [ "localnet" ];
interfaces.eth0 = {
useDHCP = true;
mtu = 1500;
#ipv4.addresses = [
# {
# address = "10.0.0.11";
# prefixLength = 24;
# }
#];
};
usePredictableInterfaceNames = false;
};
security.audit.enable = false;
services = {
arcstats = false;
cachecache.enable = true;
monitoring-exporters = {
enable = true;
metrics = true;
logging = false;
papertrail.enable = false;
ownIp = "127.0.0.1";
};
tgtd = {
enable = true;
targets = {
#"iqn.2019-01.amd-steam" = { backingStore = "/dev/naspool/amd-steam"; index = 1; };
#"iqn.2020-12.amd-steam-xfs" = { backingStore = "/dev/naspool/amd-steam-xfs"; index = 2; };
#"iqn.2021-08.com.example:pi400.img" = { backingStore = "/dev/naspool/rpi/netboot-1"; index=3; };
#"iqn.2019-03.vm-example" = {
# backingStore = "/dev/naspool/vm-example";
# index = 2;
#};
#"iqn.2016-02.windows-extra" = { backingStore = "/dev/naspool/windows-extra"; index = 4; };
#"iqn.2022-10.huge" = { backingStore = "/dev/naspool/huge"; index = 5; blockSize = 4096; };
};
};
locate.enable = false;
nfs = {
server = {
enable = true;
exports = ''
/nas c2d(rw,async,no_subtree_check,no_root_squash) amd(rw,sync,no_subtree_check,no_root_squash) 192.168.2.126(rw,sync,subtree_check,no_root_squash) 192.168.144.3(rw,sync,subtree_check,no_root_squash) 192.168.2.100(rw,sync,no_root_squash,subtree_check) system76(rw,sync,subtree_check,root_squash) 192.168.2.162(rw,sync,subtree_check,root_squash) router(ro,async,no_subtree_check,root_squash) pi5w(rw,async,subtree_check,no_root_squash)
/nas 10.0.0.106(rw,sync,subtree_check,root_squash)
/naspool/amd-nixos amd(rw,sync,subtree_check,no_root_squash)
'';
};
};
nginx = {
enable = true;
statusPage = true;
appendHttpConfig = ''
charset UTF-8;
'';
virtualHosts = {
"nas.localnet" = {
locations = {
"/private/" = {
alias = "/nas/private/";
index = "index.htm";
extraConfig = ''
autoindex on;
autoindex_exact_size off;
'';
};
};
};
};
};
ntp.enable = true;
plex = {
enable = true;
openFirewall = true;
};
postfix = {
enable = true;
relayHost = "c2d.localnet";
};
toxvpn = {
enable = true;
localip = "192.168.123.51";
};
teamspeak3 = {
enable = true;
defaultVoicePort = 9990;
fileTransferPort = 30034;
queryPort = 10012;
};
prometheus.exporters = {
smartctl = {
enable = true;
port = 9633;
devices = [ "/dev/sda" "/dev/sdb" "/dev/sdc" "/dev/sdd" "/dev/sde" "/dev/sdf" ];
};
};
udev = {
extraRules = ''
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="28:c2:dd:14:8b:3d", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlp*", NAME="wlan0"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="d0:50:99:7a:80:21", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="enp*", NAME="eth0"
SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="55d4", SYMLINK+="ttyzigbee", OWNER="hass"
'';
};
zfs = {
autoSnapshot = {
enable = true;
};
};
};
nix = {
#package = pkgs.nixUnstable;
#package = nix;
gc = {
automatic = true;
dates = "0:00:00";
options = ''--max-freed "$((32 * 1024**3 - 1024 * $(df -P -k /nix/store | tail -n 1 | ${pkgs.gawk}/bin/awk '{ print $4 }')))"'';
};
buildMachines = let
key = "/etc/nixos/keys/distro";
builders = import ./builders.nix;
in [
#{ hostName = "[email protected]"; systems = [ "x86_64-darwin" ]; sshKey = key; speedFactor = 1; maxJobs = 1; }
#{ hostName = "[email protected]"; systems = [ "armv6l-linux" "armv7l-linux" ]; sshKey = key; maxJobs = 1; speedFactor = 2; supportedFeatures = [ "big-parallel" ]; }
#{ hostName = "[email protected]"; systems = [ "i686-linux" "x86_64-linux" ]; sshKey = key; maxJobs = 1; speedFactor = 1; supportedFeatures = [ "big-parallel" "kvm" "nixos-test" ]; }
#{ hostName = "[email protected]"; systems = [ "armv7l-linux" "aarch64-linux" ]; sshKey = key; maxJobs = 1; speedFactor = 2; supportedFeatures = [ "big-parallel" ]; }
#builders.rpi4
#builders.pi400
{ hostName = "localhost"; mandatoryFeatures = [ "local" ]; systems = [ "x86_64-linux" "i686-linux" ]; maxJobs = 4; }
{ hostName = "clever@pi5w"; supportedFeatures = [ "big-parallel" ]; systems = [ "aarch64-linux" ]; maxJobs = 4; sshKey = key; }
builders.system76
#builders.amd
#{ hostName = "[email protected]"; supportedFeatures = []; systems = [ "powerpc64-linux" ]; maxJobs = 1; sshKey = key; }
{ hostName = "[email protected]"; supportedFeatures = []; systems = [ "powerpc64-linux" ]; maxJobs = 1; sshKey = key; }
];
settings = {
max-jobs = 2;
cores = 2;
substituters = lib.mkForce [
"http://nas.localnet:8081"
#"ssh://nix-ssh@amd"
];
};
extraOptions = mkAfter ''
gc-keep-derivations = true
keep-outputs = true
auto-optimise-store = false
secret-key-files = /etc/nix/keys/secret-key-file
'';
};
nixpkgs = {
config = {
allowUnfree = true;
};
overlays = [
overlay1
];
};
programs.vim.fat = false;
users = {
extraUsers = {
gits = {
isNormalUser = true;
openssh.authorizedKeys.keys = with keys; [ nix2 clever.amd router.root clever.laptop clever.laptopLuks ];
};
};
};
system.stateVersion = "16.03";
}