-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathflake.nix
More file actions
310 lines (271 loc) · 9.9 KB
/
flake.nix
File metadata and controls
310 lines (271 loc) · 9.9 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
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
{
description = ''
Examples of NixOS systems' configuration for Raspberry Pi boards
using nixos-raspberrypi
'';
nixConfig = {
bash-prompt = "\[nixos-raspberrypi-demo\] ➜ ";
extra-substituters = [
"https://nixos-raspberrypi.cachix.org"
];
extra-trusted-public-keys = [
"nixos-raspberrypi.cachix.org-1:4iMO9LXa8BqhU+Rpg6LQKiGa2lsNh/j2oiYLNOQ5sPI="
];
connect-timeout = 5;
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixos-raspberrypi = {
url = "github:nvmd/nixos-raspberrypi/main";
};
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixos-raspberrypi/nixpkgs";
};
nixos-anywhere = {
url = "github:nix-community/nixos-anywhere";
};
};
outputs = { self, nixpkgs
, nixos-raspberrypi, disko
, nixos-anywhere, ... }@inputs: let
allSystems = nixpkgs.lib.systems.flakeExposed;
forSystems = systems: f: nixpkgs.lib.genAttrs systems (system: f system);
in {
devShells = forSystems allSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
nil # lsp language server for nix
nixpkgs-fmt
nix-output-monitor
nixos-anywhere.packages.${system}.default
];
};
});
nixosConfigurations = let
users-config-stub = ({ config, ... }: {
# This is identical to what nixos installer does in
# (modulesPash + "profiles/installation-device.nix")
# Use less privileged nixos user
users.users.nixos = {
isNormalUser = true;
extraGroups = [
"wheel"
"networkmanager"
"video"
];
# Allow the graphical user to login without password
initialHashedPassword = "";
};
# Allow the user to log in as root without a password.
users.users.root.initialHashedPassword = "";
# Don't require sudo/root to `reboot` or `poweroff`.
security.polkit.enable = true;
# Allow passwordless sudo from nixos user
security.sudo = {
enable = true;
wheelNeedsPassword = false;
};
# Automatically log in at the virtual consoles.
services.getty.autologinUser = "nixos";
# We run sshd by default. Login is only possible after adding a
# password via "passwd" or by adding a ssh key to ~/.ssh/authorized_keys.
# The latter one is particular useful if keys are manually added to
# installation device for head-less systems i.e. arm boards by manually
# mounting the storage in a different system.
services.openssh = {
enable = true;
settings.PermitRootLogin = "yes";
};
# allow nix-copy to live system
nix.settings.trusted-users = [ "nixos" ];
# We are stateless, so just default to latest.
system.stateVersion = config.system.nixos.release;
});
network-config = {
# This is mostly portions of safe network configuration defaults that
# nixos-images and srvos provide
networking.useNetworkd = true;
# mdns
networking.firewall.allowedUDPPorts = [ 5353 ];
systemd.network.networks = {
"99-ethernet-default-dhcp".networkConfig.MulticastDNS = "yes";
"99-wireless-client-dhcp".networkConfig.MulticastDNS = "yes";
};
# This comment was lifted from `srvos`
# Do not take down the network for too long when upgrading,
# This also prevents failures of services that are restarted instead of stopped.
# It will use `systemctl restart` rather than stopping it with `systemctl stop`
# followed by a delayed `systemctl start`.
systemd.services = {
systemd-networkd.stopIfChanged = false;
# Services that are only restarted might be not able to resolve when resolved is stopped before
systemd-resolved.stopIfChanged = false;
};
# Use iwd instead of wpa_supplicant. It has a user friendly CLI
networking.wireless.enable = false;
networking.wireless.iwd = {
enable = true;
settings = {
Network = {
EnableIPv6 = true;
RoutePriorityOffset = 300;
};
Settings.AutoConnect = true;
};
};
};
common-user-config = {config, pkgs, ... }: {
imports = [
./modules/nice-looking-console.nix
users-config-stub
network-config
];
time.timeZone = "UTC";
networking.hostName = "rpi${config.boot.loader.raspberry-pi.variant}-demo";
services.udev.extraRules = ''
# Ignore partitions with "Required Partition" GPT partition attribute
# On our RPis this is firmware (/boot/firmware) partition
ENV{ID_PART_ENTRY_SCHEME}=="gpt", \
ENV{ID_PART_ENTRY_FLAGS}=="0x1", \
ENV{UDISKS_IGNORE}="1"
'';
environment.systemPackages = with pkgs; [
tree
];
users.users.nixos.openssh.authorizedKeys.keys = [
# YOUR SSH PUB KEY HERE #
];
users.users.root.openssh.authorizedKeys.keys = [
# YOUR SSH PUB KEY HERE #
];
system.nixos.tags = let
cfg = config.boot.loader.raspberry-pi;
in [
"raspberry-pi-${cfg.variant}"
cfg.bootloader
config.boot.kernelPackages.kernel.version
];
};
in {
rpi02 = nixos-raspberrypi.lib.nixosSystemFull {
specialArgs = inputs;
modules = [
({ config, pkgs, lib, nixos-raspberrypi, ... }: {
imports = with nixos-raspberrypi.nixosModules; [
# Hardware configuration
raspberry-pi-02.base
usb-gadget-ethernet
# config.txt example
./pi02-configtxt.nix
];
})
# Disk configuration
# Assumes the system will continue to reside on the installation media (sd-card),
# as there're hardly other feasible options on RPi02.
# (see also https://github.com/nvmd/nixos-raspberrypi/issues/8#issuecomment-2804912881)
# `sd-image` has lots of dependencies unnecessary for the installed system,
# replicating its disk layout
({ config, pkgs, ... }: {
fileSystems = {
"/boot/firmware" = {
device = "/dev/disk/by-label/FIRMWARE";
fsType = "vfat";
options = [
"noatime"
"noauto"
"x-systemd.automount"
"x-systemd.idle-timeout=1min"
];
};
"/" = {
device = "/dev/disk/by-label/NIXOS_SD";
fsType = "ext4";
options = [ "noatime" ];
};
};
})
# Further user configuration
common-user-config
({ config, pkgs, ... }: {
hardware.i2c.enable = true;
environment.systemPackages = with pkgs; [
i2c-tools
];
})
];
};
rpi4 = nixos-raspberrypi.lib.nixosSystem {
specialArgs = inputs;
modules = [
({ config, pkgs, lib, nixos-raspberrypi, disko, ... }: {
imports = with nixos-raspberrypi.nixosModules; [
# Hardware configuration
raspberry-pi-4.base
raspberry-pi-4.display-vc4
raspberry-pi-4.bluetooth
];
})
# Disk configuration
disko.nixosModules.disko
# WARNING: formatting disk with disko is DESTRUCTIVE, check if
# `disko.devices.disk.main.device` is set correctly!
./disko-usb-btrfs.nix
# Further user configuration
common-user-config
{
boot.tmp.useTmpfs = true;
}
# Advanced: Use non-default kernel from kernel-firmware bundle
({ config, pkgs, lib, ... }: let
kernelBundle = pkgs.linuxAndFirmware.v6_6_31;
in {
boot = {
loader.raspberry-pi.firmwarePackage = kernelBundle.raspberrypifw;
kernelPackages = kernelBundle.linuxPackages_rpi4;
};
nixpkgs.overlays = lib.mkAfter [
(self: super: {
# This is used in (modulesPath + "/hardware/all-firmware.nix") when at least
# enableRedistributableFirmware is enabled
# I know no easier way to override this package
inherit (kernelBundle) raspberrypiWirelessFirmware;
# Some derivations want to use it as an input,
# e.g. raspberrypi-dtbs, omxplayer, sd-image-* modules
inherit (kernelBundle) raspberrypifw;
})
];
})
];
};
rpi5 = nixos-raspberrypi.lib.nixosSystemFull {
specialArgs = inputs;
modules = [
({ config, pkgs, lib, nixos-raspberrypi, disko, ... }: {
imports = with nixos-raspberrypi.nixosModules; [
# Hardware configuration
raspberry-pi-5.base
raspberry-pi-5.page-size-16k
raspberry-pi-5.display-vc4
./pi5-configtxt.nix
];
})
# Disk configuration
disko.nixosModules.disko
# WARNING: formatting disk with disko is DESTRUCTIVE, check if
# `disko.devices.disk.nvme0.device` is set correctly!
./disko-nvme-zfs.nix
{ networking.hostId = "8821e309"; } # NOTE: for zfs, must be unique
# Further user configuration
common-user-config
{
boot.loader.raspberry-pi.bootloader = "kernel";
boot.tmp.useTmpfs = true;
}
];
};
};
};
}