Skip to content

Commit 087764d

Browse files
Merge pull request #16 from randomizedcoder/2025_06_28
2025 06 28
2 parents bafa796 + e3429e3 commit 087764d

File tree

148 files changed

+12963
-1074
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+12963
-1074
lines changed

arm/nix-os-raspberrypi/Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# arm/nix-os-raspberrypi/Makefile
3+
#
4+
5+
# Fake targets
6+
.PHONY: rpi2 rpi4 rpi4
7+
8+
all: rp5
9+
10+
rpi2:
11+
nix build .#installerImages.rpi02
12+
13+
rp4:
14+
nix build .#installerImages.rpi4
15+
16+
rp5:
17+
nix build .#installerImages.rpi5
18+
19+
rp5_on_amd64:
20+
sudo nix build .#nixosConfigurations.rpi5.config.system.build.sdImage --system aarch64-linux
21+
22+
update:
23+
sudo nix flake update;
24+
25+
sync:
26+
rsync -avz ./ 172.16.40.122:/home/das/nixos/arm/nix-os-raspberrypi/
27+
28+
# end
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
{ config, lib, ... }:
2+
3+
let
4+
firmwarePartition = lib.recursiveUpdate {
5+
# label = "FIRMWARE";
6+
priority = 1;
7+
8+
type = "0700"; # Microsoft basic data
9+
attributes = [
10+
0 # Required Partition
11+
];
12+
13+
size = "1024M";
14+
content = {
15+
type = "filesystem";
16+
format = "vfat";
17+
# mountpoint = "/boot/firmware";
18+
mountOptions = [
19+
"noatime"
20+
"noauto"
21+
"x-systemd.automount"
22+
"x-systemd.idle-timeout=1min"
23+
];
24+
};
25+
};
26+
27+
espPartition = lib.recursiveUpdate {
28+
# label = "ESP";
29+
30+
type = "EF00"; # EFI System Partition (ESP)
31+
attributes = [
32+
2 # Legacy BIOS Bootable, for U-Boot to find extlinux config
33+
];
34+
35+
size = "1024M";
36+
content = {
37+
type = "filesystem";
38+
format = "vfat";
39+
# mountpoint = "/boot";
40+
mountOptions = [
41+
"noatime"
42+
"noauto"
43+
"x-systemd.automount"
44+
"x-systemd.idle-timeout=1min"
45+
"umask=0077"
46+
];
47+
};
48+
};
49+
50+
in {
51+
52+
boot.supportedFilesystems = [ "zfs" ];
53+
# networking.hostId is set somewhere else
54+
services.zfs.autoScrub.enable = true;
55+
services.zfs.trim.enable = true;
56+
57+
disko.devices = {
58+
disk.nvme0 = {
59+
type = "disk";
60+
device = "/dev/nvme0n1";
61+
content = {
62+
type = "gpt";
63+
partitions = {
64+
65+
FIRMWARE = firmwarePartition {
66+
label = "FIRMWARE";
67+
content.mountpoint = "/boot/firmware";
68+
};
69+
70+
ESP = espPartition {
71+
label = "ESP";
72+
content.mountpoint = "/boot";
73+
};
74+
75+
zfs = {
76+
size = "100%";
77+
content = {
78+
type = "zfs";
79+
pool = "rpool"; # zroot
80+
};
81+
};
82+
83+
};
84+
};
85+
}; #nvme0
86+
87+
zpool = {
88+
rpool = {
89+
type = "zpool";
90+
91+
# zpool properties
92+
options = {
93+
ashift = "12";
94+
autotrim = "on"; # see also services.zfs.trim.enable
95+
};
96+
97+
# zfs properties
98+
rootFsOptions = {
99+
# "com.sun:auto-snapshot" = "false";
100+
# https://jrs-s.net/2018/08/17/zfs-tuning-cheat-sheet/
101+
compression = "lz4";
102+
atime = "off";
103+
xattr = "sa";
104+
acltype = "posixacl";
105+
# https://rubenerd.com/forgetting-to-set-utf-normalisation-on-a-zfs-pool/
106+
normalization = "formD";
107+
dnodesize = "auto";
108+
mountpoint = "none";
109+
canmount = "off";
110+
};
111+
112+
postCreateHook = let
113+
poolName = "rpool";
114+
in "zfs list -t snapshot -H -o name | grep -E '^${poolName}@blank$' || zfs snapshot ${poolName}@blank";
115+
116+
datasets = {
117+
118+
# stuff which can be recomputed/easily redownloaded, e.g. nix store
119+
local = {
120+
type = "zfs_fs";
121+
options.mountpoint = "none";
122+
};
123+
"local/nix" = {
124+
type = "zfs_fs";
125+
options = {
126+
reservation = "128M";
127+
mountpoint = "legacy"; # to manage "with traditional tools"
128+
};
129+
mountpoint = "/nix"; # nixos configuration mountpoint
130+
};
131+
132+
# _system_ data
133+
system = {
134+
type = "zfs_fs";
135+
options = {
136+
mountpoint = "none";
137+
};
138+
};
139+
"system/root" = {
140+
type = "zfs_fs";
141+
options = {
142+
mountpoint = "legacy";
143+
};
144+
mountpoint = "/";
145+
};
146+
"system/var" = {
147+
type = "zfs_fs";
148+
options = {
149+
mountpoint = "legacy";
150+
};
151+
mountpoint = "/var";
152+
};
153+
154+
# _user_ and _user service_ data. safest, long retention policy
155+
safe = {
156+
type = "zfs_fs";
157+
options = {
158+
copies = "2";
159+
mountpoint = "none";
160+
};
161+
};
162+
"safe/home" = {
163+
type = "zfs_fs";
164+
options = {
165+
mountpoint = "legacy";
166+
};
167+
mountpoint = "/home";
168+
};
169+
"safe/var/lib" = {
170+
type = "zfs_fs";
171+
options = {
172+
mountpoint = "legacy";
173+
};
174+
mountpoint = "/var/lib";
175+
};
176+
177+
};
178+
};
179+
};
180+
};
181+
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
{ config, lib, ... }:
2+
3+
let
4+
firmwarePartition = lib.recursiveUpdate {
5+
# label = "FIRMWARE";
6+
priority = 1;
7+
8+
type = "0700"; # Microsoft basic data
9+
attributes = [
10+
0 # Required Partition
11+
];
12+
13+
size = "1024M";
14+
content = {
15+
type = "filesystem";
16+
format = "vfat";
17+
# mountpoint = "/boot/firmware";
18+
mountOptions = [
19+
"noatime"
20+
"noauto"
21+
"x-systemd.automount"
22+
"x-systemd.idle-timeout=1min"
23+
];
24+
};
25+
};
26+
27+
espPartition = lib.recursiveUpdate {
28+
# label = "ESP";
29+
30+
type = "EF00"; # EFI System Partition (ESP)
31+
attributes = [
32+
2 # Legacy BIOS Bootable, for U-Boot to find extlinux config
33+
];
34+
35+
size = "1024M";
36+
content = {
37+
type = "filesystem";
38+
format = "vfat";
39+
# mountpoint = "/boot";
40+
mountOptions = [
41+
"noatime"
42+
"noauto"
43+
"x-systemd.automount"
44+
"x-systemd.idle-timeout=1min"
45+
"umask=0077"
46+
];
47+
};
48+
};
49+
50+
in {
51+
52+
# https://nixos.wiki/wiki/Btrfs#Scrubbing
53+
services.btrfs.autoScrub = {
54+
enable = true;
55+
interval = "monthly";
56+
fileSystems = [ "/" ];
57+
};
58+
59+
fileSystems = {
60+
# mount early enough in the boot process so no logs will be lost
61+
"/var/log".neededForBoot = true;
62+
};
63+
64+
disko.devices.disk.main = {
65+
type = "disk";
66+
device = "/dev/sda";
67+
68+
content = {
69+
type = "gpt";
70+
partitions = {
71+
72+
FIRMWARE = firmwarePartition {
73+
label = "FIRMWARE";
74+
content.mountpoint = "/boot/firmware";
75+
};
76+
77+
ESP = espPartition {
78+
label = "ESP";
79+
content.mountpoint = "/boot";
80+
};
81+
82+
system = {
83+
type = "8305"; # Linux ARM64 root (/)
84+
85+
size = "100%";
86+
content = {
87+
type = "btrfs";
88+
extraArgs = [
89+
# "--label nixos"
90+
"-f" # Override existing partition
91+
];
92+
postCreateHook = let
93+
thisBtrfs = config.disko.devices.disk.main.content.partitions.system.content;
94+
device = thisBtrfs.device;
95+
subvolumes = thisBtrfs.subvolumes;
96+
97+
makeBlankSnapshot = btrfsMntPoint: subvol: let
98+
subvolAbsPath = lib.strings.normalizePath "${btrfsMntPoint}/${subvol.name}";
99+
dst = "${subvolAbsPath}-blank";
100+
# NOTE: this one-liner has the same functionality (inspired by zfs hook)
101+
# btrfs subvolume list -s mnt/rootfs | grep -E ' rootfs-blank$' || btrfs subvolume snapshot -r mnt/rootfs mnt/rootfs-blank
102+
in ''
103+
if ! btrfs subvolume show "${dst}" > /dev/null 2>&1; then
104+
btrfs subvolume snapshot -r "${subvolAbsPath}" "${dst}"
105+
fi
106+
'';
107+
# Mount top-level subvolume (/) with "subvol=/", without it
108+
# the default subvolume will be mounted. They're the same in
109+
# this case, though. So "subvol=/" isn't really necessary
110+
in ''
111+
MNTPOINT=$(mktemp -d)
112+
mount ${device} "$MNTPOINT" -o subvol=/
113+
trap 'umount $MNTPOINT; rm -rf $MNTPOINT' EXIT
114+
${makeBlankSnapshot "$MNTPOINT" subvolumes."/rootfs"}
115+
'';
116+
subvolumes = {
117+
"/rootfs" = {
118+
mountpoint = "/";
119+
mountOptions = [ "noatime" ];
120+
};
121+
"/nix" = {
122+
mountpoint = "/nix";
123+
mountOptions = [ "noatime" ];
124+
};
125+
"/home" = {
126+
mountpoint = "/home";
127+
mountOptions = [ "noatime" ];
128+
};
129+
"/log" = {
130+
mountpoint = "/var/log";
131+
mountOptions = [ "noatime" ];
132+
};
133+
"/swap" = {
134+
mountpoint = "/.swapvol";
135+
swap."swapfile" = {
136+
size = "8G";
137+
priority = 3; # (higher number -> higher priority)
138+
# to be used after zswap (set zramSwap.priority > this priority),
139+
# but before "hibernation" swap
140+
# https://github.com/nix-community/disko/issues/651
141+
};
142+
};
143+
};
144+
};
145+
}; # system
146+
147+
swap = {
148+
type = "8200"; # Linux swap
149+
150+
size = "9G"; # RAM + 1GB
151+
content = {
152+
type = "swap";
153+
resumeDevice = true; # "hibernation" swap
154+
# zram's swap will be used first, and this one only
155+
# used when the system is under pressure enough that zram and
156+
# "regular" swap above didn't work
157+
# https://github.com/systemd/systemd/issues/16708#issuecomment-1632592375
158+
# (set zramSwap.priority > btrfs' .swapvol priority > this priority)
159+
priority = 2;
160+
};
161+
};
162+
163+
};
164+
};
165+
166+
}; # disko.devices.disk.main
167+
}

0 commit comments

Comments
 (0)