Personal Nix flake
nixos home-manager nix
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: Better storage configuration

Revamp the odd dynamic module generation to regular functions

Add /var/cache and /var/log mount points to all configs

Make disko use /dev/by-id instead of non deterministic partition labels

+291 -193
+67 -71
nix/lib/storage/btrfs.nix
··· 1 - { 2 - mkStorage = { 1 + {lib, ...}: rec { 2 + primary.options = [ 3 + "defaults" 4 + "compress=zstd" 5 + "noatime" 6 + ]; 7 + secondary.options = 8 + [ 9 + "defaults" 10 + "auto" 11 + "exec" 12 + "nofail" 13 + "nosuid" 14 + "nodev" 15 + "x-gvfs-show" 16 + ] 17 + ++ primary.options; 18 + 19 + mkDiskoRootDisk = { 3 20 device, 4 - bootSize ? "512M", 5 - swapSize, 21 + swapSize ? null, 22 + espSize ? "1024M", 23 + espIndex ? 1, 24 + rootIndex ? 2, 6 25 }: { 7 - disko.devices = { 8 - disk = { 9 - vdb = { 10 - inherit device; 11 - type = "disk"; 26 + inherit device; 27 + type = "disk"; 28 + content = { 29 + type = "gpt"; 30 + partitions = { 31 + ESP = { 32 + device = "${device}-part${toString espIndex}"; 33 + type = "EF00"; 34 + size = espSize; 12 35 content = { 13 - type = "gpt"; 14 - partitions = { 15 - ESP = { 16 - type = "EF00"; 17 - size = bootSize; 18 - content = { 19 - type = "filesystem"; 20 - format = "vfat"; 21 - mountpoint = "/boot"; 22 - }; 36 + type = "filesystem"; 37 + format = "vfat"; 38 + mountpoint = "/boot"; 39 + }; 40 + }; 41 + root = { 42 + device = "${device}-part${toString rootIndex}"; 43 + size = "100%"; 44 + content = { 45 + type = "btrfs"; 46 + extraArgs = ["-f"]; # Override existing partition 47 + subvolumes = { 48 + "@" = { 49 + mountpoint = "/"; 50 + mountOptions = primary.options; 23 51 }; 24 - root = { 25 - size = "100%"; 26 - content = { 27 - type = "btrfs"; 28 - extraArgs = ["-f"]; # Override existing partition 29 - # Subvolumes must set a mountpoint in order to be mounted, 30 - # unless their parent is mounted 31 - subvolumes = { 32 - # Subvolume name is different from mountpoint 33 - "@" = { 34 - mountOptions = ["compress=zstd"]; 35 - mountpoint = "/"; 36 - }; 37 - # Subvolume name is the same as the mountpoint 38 - "@home" = { 39 - mountOptions = ["compress=zstd"]; 40 - mountpoint = "/home"; 41 - }; 42 - # Parent is not mounted so the mountpoint must be set 43 - "@nix" = { 44 - mountOptions = ["compress=zstd" "noatime"]; 45 - mountpoint = "/nix"; 46 - }; 47 - "@swap" = { 48 - mountpoint = "/.swapvol"; 49 - swap = { 50 - swapfile.size = swapSize; 51 - }; 52 - }; 53 - }; 54 - }; 52 + "@cache" = { 53 + mountpoint = "/var/cache"; 54 + mountOptions = primary.options ++ ["nofail"]; 55 + }; 56 + "@home" = { 57 + mountpoint = "/home"; 58 + mountOptions = primary.options ++ ["nofail"]; 59 + }; 60 + "@log" = { 61 + mountpoint = "/var/log"; 62 + mountOptions = primary.options ++ ["nofail"]; 63 + }; 64 + "@nix" = { 65 + mountpoint = "/nix"; 66 + mountOptions = primary.options; 67 + }; 68 + "@swap" = lib.mkIf (swapSize != null) { 69 + mountpoint = "/.swapvol"; 70 + swap.swapfile.options = ["defaults" "nofail"]; 71 + swap.swapfile.size = swapSize; 55 72 }; 56 73 }; 57 74 }; 58 75 }; 59 76 }; 60 - }; 61 - }; 62 - 63 - mkSecondaryStorage = { 64 - device, 65 - mountPoint, 66 - }: { 67 - fileSystems.${mountPoint} = { 68 - inherit device; 69 - fsType = "btrfs"; 70 - options = [ 71 - "defaults" 72 - "auto" 73 - "exec" 74 - "nofail" 75 - "nosuid" 76 - "nodev" 77 - "noatime" 78 - "compress=zstd" 79 - "x-gvfs-show" 80 - ]; 81 77 }; 82 78 }; 83 79 }
+2 -2
nix/lib/storage/default.nix
··· 1 - {lib, ...}: { 2 - btrfs = import ./btrfs.nix; 1 + {lib, ...} @ args: { 2 + btrfs = import ./btrfs.nix args; 3 3 ntfs = import ./ntfs.nix; 4 4 5 5 mkSafePath = path:
+13 -22
nix/lib/storage/ntfs.nix
··· 1 1 { 2 - mkSecondaryStorage = { 3 - device, 4 - mountPoint, 5 - }: { 6 - fileSystems.${mountPoint} = { 7 - inherit device; 8 - fsType = "ntfs3"; 9 - options = [ 10 - "defaults" 11 - "auto" 12 - "exec" 13 - "nofail" 14 - "nosuid" 15 - "nodev" 16 - "relatime" 17 - "uid=1000" 18 - "gid=1000" 19 - "iocharset=utf8" 20 - "x-gvfs-show" 21 - ]; 22 - }; 23 - }; 2 + secondary.options = [ 3 + "defaults" 4 + "auto" 5 + "exec" 6 + "nofail" 7 + "nosuid" 8 + "nodev" 9 + "relatime" 10 + "uid=1000" 11 + "gid=1000" 12 + "iocharset=utf8" 13 + "x-gvfs-show" 14 + ]; 24 15 }
+21 -18
nix/nixos/configs/desktop/storage.nix
··· 1 - { 2 - lib, 3 - self, 4 - ... 5 - }: let 6 - inherit (self.lib.storage.btrfs) mkSecondaryStorage mkStorage; 7 - inherit (self.vars) name; 8 - in 9 - lib.mkMerge [ 10 - (mkStorage { 11 - device = "/dev/disk/by-id/nvme-Corsair_MP600_PRO_XT_214279380001310131BD"; 12 - swapSize = "35G"; 13 - }) 14 - (mkSecondaryStorage { 15 - device = "/dev/disk/by-id/ata-ADATA_SU630_2J0220042661-part1"; 16 - mountPoint = "/run/media/${name.user}/storage"; 17 - }) 18 - ] 1 + {self, ...}: { 2 + disko.devices.disk.main = self.lib.storage.btrfs.mkDiskoRootDisk { 3 + device = "/dev/disk/by-id/nvme-Corsair_MP600_PRO_XT_214279380001310131BD"; 4 + swapSize = "35G"; 5 + }; 6 + fileSystems."/run/media/${self.vars.name.user}/storage" = { 7 + device = "/dev/disk/by-id/ata-ADATA_SU630_2J0220042661-part1"; 8 + fsType = "btrfs"; 9 + options = [ 10 + "defaults" 11 + "auto" 12 + "exec" 13 + "nofail" 14 + "nosuid" 15 + "nodev" 16 + "noatime" 17 + "compress=zstd" 18 + "x-gvfs-show" 19 + ]; 20 + }; 21 + }
+6 -13
nix/nixos/configs/laptop/storage.nix
··· 1 - { 2 - inputs, 3 - lib, 4 - ... 5 - }: let 6 - inherit (inputs.self.lib.storage.btrfs) mkStorage; 7 - in 8 - lib.mkMerge [ 9 - (mkStorage { 10 - device = "/dev/disk/by-id/nvme-WDSN740-SDDPNQD-512G-1004_23360G804890"; 11 - swapSize = "17G"; 12 - }) 13 - ] 1 + {self, ...}: { 2 + disko.devices.disk.main = self.lib.storage.btrfs.mkDiskoRootDisk { 3 + device = "/dev/disk/by-id/nvme-WDSN740-SDDPNQD-512G-1004_23360G804890"; 4 + swapSize = "17G"; 5 + }; 6 + }
+35 -22
nix/nixos/configs/raspberrypi/storage.nix
··· 1 1 { 2 - fileSystems."/boot" = { 3 - device = "/dev/disk/by-uuid/12CE-A600"; 4 - fsType = "vfat"; 5 - options = ["fmask=0022" "dmask=0022"]; 6 - }; 7 - 8 - fileSystems."/" = { 9 - device = "/dev/disk/by-uuid/322a6d8e-f946-4d60-98a3-dd1af1373c79"; 10 - fsType = "btrfs"; 11 - options = ["subvol=@" "compress=zstd" "noatime"]; 12 - }; 13 - 14 - fileSystems."/home" = { 15 - device = "/dev/disk/by-uuid/322a6d8e-f946-4d60-98a3-dd1af1373c79"; 16 - fsType = "btrfs"; 17 - options = ["subvol=@home" "compress=zstd" "noatime"]; 18 - }; 19 - 20 - fileSystems."/nix" = { 21 - device = "/dev/disk/by-uuid/322a6d8e-f946-4d60-98a3-dd1af1373c79"; 22 - fsType = "btrfs"; 23 - options = ["subvol=@nix" "compress=zstd" "noatime"]; 2 + fileSystems = let 3 + boot.device = "/dev/disk/by-id/usb-Argon_Forty_000000000F12-0:0-part1"; 4 + root.device = "/dev/disk/by-id/usb-Argon_Forty_000000000F12-0:0-part2"; 5 + options = ["compress=zstd" "noatime"]; 6 + in { 7 + "/boot" = { 8 + inherit (boot) device; 9 + fsType = "vfat"; 10 + options = ["fmask=0022" "dmask=0022"]; 11 + }; 12 + "/" = { 13 + inherit (root) device; 14 + fsType = "btrfs"; 15 + options = ["subvol=@"] ++ options; 16 + }; 17 + "/home" = { 18 + inherit (root) device; 19 + fsType = "btrfs"; 20 + options = ["subvol=@home" "nofail"] ++ options; 21 + }; 22 + "/nix" = { 23 + inherit (root) device; 24 + fsType = "btrfs"; 25 + options = ["subvol=@nix"] ++ options; 26 + }; 27 + "/var/cache" = { 28 + inherit (root) device; 29 + fsType = "btrfs"; 30 + options = ["subvol=@cache" "nofail"] ++ options; 31 + }; 32 + "/var/log" = { 33 + inherit (root) device; 34 + fsType = "btrfs"; 35 + options = ["subvol=@log" "nofail"] ++ options; 36 + }; 24 37 }; 25 38 }
+16 -26
nix/nixos/configs/steamdeck/storage.nix
··· 1 - { 2 - lib, 3 - self, 4 - ... 5 - }: let 6 - inherit (self.lib.storage.btrfs) mkStorage; 7 - inherit (self.vars) name; 8 - in 9 - lib.mkMerge [ 10 - (mkStorage { 11 - device = "/dev/disk/by-id/nvme-KINGSTON_OM3PDP3512B-A01_50026B7685D47463"; 12 - swapSize = "17G"; 13 - }) 14 - { 15 - fileSystems."/run/media/${name.user}/sdcard" = { 16 - device = "/dev/disk/by-id/mmc-EF8S5_0x3b3163d0-part1"; 17 - options = [ 18 - "defaults" 19 - "subvol=@" 20 - "compress=zstd" 21 - "noatime" 22 - "nofail" 23 - ]; 24 - }; 25 - } 26 - ] 1 + {self, ...}: { 2 + disko.devices.disk.main = self.lib.storage.btrfs.mkDiskoRootDisk { 3 + device = "/dev/disk/by-id/nvme-KINGSTON_OM3PDP3512B-A01_50026B7685D47463"; 4 + swapSize = "17G"; 5 + }; 6 + fileSystems."/run/media/${self.vars.name.user}/sdcard" = { 7 + device = "/dev/disk/by-id/mmc-EF8S5_0x3b3163d0-part1"; 8 + options = [ 9 + "defaults" 10 + "subvol=@" 11 + "compress=zstd" 12 + "noatime" 13 + "nofail" 14 + ]; 15 + }; 16 + }
+2
nix/overlays/lix.nix
··· 27 27 ; 28 28 }; 29 29 30 + disko = prev.disko.override {inherit nix;}; 31 + 30 32 # Adapted from https://github.com/nix-community/nixd/issues/704#issuecomment-3688024705 31 33 nixd = prev.symlinkJoin { 32 34 name = "nixd-lix";
+1
nix/shells/maintenance.nix
··· 23 23 (with pkgs; [ 24 24 age-plugin-yubikey 25 25 colmena 26 + disko 26 27 just 27 28 rage 28 29 yaml-language-server
+34 -5
nix/tests/_snapshots/filesystems-desktop.snap.json
··· 1 1 { 2 2 "/": { 3 - "device": "/dev/disk/by-partlabel/disk-vdb-root", 3 + "device": "/dev/disk/by-id/nvme-Corsair_MP600_PRO_XT_214279380001310131BD-part2", 4 4 "fsType": "btrfs", 5 5 "options": [ 6 6 "x-initrd.mount", 7 + "defaults", 7 8 "compress=zstd", 9 + "noatime", 8 10 "subvol=@" 9 11 ] 10 12 }, 11 13 "/.swapvol": { 12 - "device": "/dev/disk/by-partlabel/disk-vdb-root", 14 + "device": "/dev/disk/by-id/nvme-Corsair_MP600_PRO_XT_214279380001310131BD-part2", 13 15 "fsType": "btrfs", 14 16 "options": [ 15 17 "defaults", ··· 17 19 ] 18 20 }, 19 21 "/boot": { 20 - "device": "/dev/disk/by-partlabel/disk-vdb-ESP", 22 + "device": "/dev/disk/by-id/nvme-Corsair_MP600_PRO_XT_214279380001310131BD-part1", 21 23 "fsType": "vfat", 22 24 "options": [ 23 25 "defaults" 24 26 ] 25 27 }, 26 28 "/home": { 27 - "device": "/dev/disk/by-partlabel/disk-vdb-root", 29 + "device": "/dev/disk/by-id/nvme-Corsair_MP600_PRO_XT_214279380001310131BD-part2", 28 30 "fsType": "btrfs", 29 31 "options": [ 32 + "defaults", 30 33 "compress=zstd", 34 + "noatime", 35 + "nofail", 31 36 "subvol=@home" 32 37 ] 33 38 }, 34 39 "/nix": { 35 - "device": "/dev/disk/by-partlabel/disk-vdb-root", 40 + "device": "/dev/disk/by-id/nvme-Corsair_MP600_PRO_XT_214279380001310131BD-part2", 36 41 "fsType": "btrfs", 37 42 "options": [ 38 43 "x-initrd.mount", 44 + "defaults", 39 45 "compress=zstd", 40 46 "noatime", 41 47 "subvol=@nix" ··· 54 60 "noatime", 55 61 "compress=zstd", 56 62 "x-gvfs-show" 63 + ] 64 + }, 65 + "/var/cache": { 66 + "device": "/dev/disk/by-id/nvme-Corsair_MP600_PRO_XT_214279380001310131BD-part2", 67 + "fsType": "btrfs", 68 + "options": [ 69 + "defaults", 70 + "compress=zstd", 71 + "noatime", 72 + "nofail", 73 + "subvol=@cache" 74 + ] 75 + }, 76 + "/var/log": { 77 + "device": "/dev/disk/by-id/nvme-Corsair_MP600_PRO_XT_214279380001310131BD-part2", 78 + "fsType": "btrfs", 79 + "options": [ 80 + "x-initrd.mount", 81 + "defaults", 82 + "compress=zstd", 83 + "noatime", 84 + "nofail", 85 + "subvol=@log" 57 86 ] 58 87 } 59 88 }
+34 -5
nix/tests/_snapshots/filesystems-laptop.snap.json
··· 1 1 { 2 2 "/": { 3 - "device": "/dev/disk/by-partlabel/disk-vdb-root", 3 + "device": "/dev/disk/by-id/nvme-WDSN740-SDDPNQD-512G-1004_23360G804890-part2", 4 4 "fsType": "btrfs", 5 5 "options": [ 6 6 "x-initrd.mount", 7 + "defaults", 7 8 "compress=zstd", 9 + "noatime", 8 10 "subvol=@" 9 11 ] 10 12 }, 11 13 "/.swapvol": { 12 - "device": "/dev/disk/by-partlabel/disk-vdb-root", 14 + "device": "/dev/disk/by-id/nvme-WDSN740-SDDPNQD-512G-1004_23360G804890-part2", 13 15 "fsType": "btrfs", 14 16 "options": [ 15 17 "defaults", ··· 17 19 ] 18 20 }, 19 21 "/boot": { 20 - "device": "/dev/disk/by-partlabel/disk-vdb-ESP", 22 + "device": "/dev/disk/by-id/nvme-WDSN740-SDDPNQD-512G-1004_23360G804890-part1", 21 23 "fsType": "vfat", 22 24 "options": [ 23 25 "defaults" 24 26 ] 25 27 }, 26 28 "/home": { 27 - "device": "/dev/disk/by-partlabel/disk-vdb-root", 29 + "device": "/dev/disk/by-id/nvme-WDSN740-SDDPNQD-512G-1004_23360G804890-part2", 28 30 "fsType": "btrfs", 29 31 "options": [ 32 + "defaults", 30 33 "compress=zstd", 34 + "noatime", 35 + "nofail", 31 36 "subvol=@home" 32 37 ] 33 38 }, 34 39 "/nix": { 35 - "device": "/dev/disk/by-partlabel/disk-vdb-root", 40 + "device": "/dev/disk/by-id/nvme-WDSN740-SDDPNQD-512G-1004_23360G804890-part2", 36 41 "fsType": "btrfs", 37 42 "options": [ 38 43 "x-initrd.mount", 44 + "defaults", 39 45 "compress=zstd", 40 46 "noatime", 41 47 "subvol=@nix" 48 + ] 49 + }, 50 + "/var/cache": { 51 + "device": "/dev/disk/by-id/nvme-WDSN740-SDDPNQD-512G-1004_23360G804890-part2", 52 + "fsType": "btrfs", 53 + "options": [ 54 + "defaults", 55 + "compress=zstd", 56 + "noatime", 57 + "nofail", 58 + "subvol=@cache" 59 + ] 60 + }, 61 + "/var/log": { 62 + "device": "/dev/disk/by-id/nvme-WDSN740-SDDPNQD-512G-1004_23360G804890-part2", 63 + "fsType": "btrfs", 64 + "options": [ 65 + "x-initrd.mount", 66 + "defaults", 67 + "compress=zstd", 68 + "noatime", 69 + "nofail", 70 + "subvol=@log" 42 71 ] 43 72 } 44 73 }
+26 -4
nix/tests/_snapshots/filesystems-raspberrypi.snap.json
··· 1 1 { 2 2 "/": { 3 - "device": "/dev/disk/by-uuid/322a6d8e-f946-4d60-98a3-dd1af1373c79", 3 + "device": "/dev/disk/by-id/usb-Argon_Forty_000000000F12-0:0-part2", 4 4 "fsType": "btrfs", 5 5 "options": [ 6 6 "x-initrd.mount", ··· 10 10 ] 11 11 }, 12 12 "/boot": { 13 - "device": "/dev/disk/by-uuid/12CE-A600", 13 + "device": "/dev/disk/by-id/usb-Argon_Forty_000000000F12-0:0-part1", 14 14 "fsType": "vfat", 15 15 "options": [ 16 16 "fmask=0022", ··· 18 18 ] 19 19 }, 20 20 "/home": { 21 - "device": "/dev/disk/by-uuid/322a6d8e-f946-4d60-98a3-dd1af1373c79", 21 + "device": "/dev/disk/by-id/usb-Argon_Forty_000000000F12-0:0-part2", 22 22 "fsType": "btrfs", 23 23 "options": [ 24 24 "subvol=@home", 25 + "nofail", 25 26 "compress=zstd", 26 27 "noatime" 27 28 ] 28 29 }, 29 30 "/nix": { 30 - "device": "/dev/disk/by-uuid/322a6d8e-f946-4d60-98a3-dd1af1373c79", 31 + "device": "/dev/disk/by-id/usb-Argon_Forty_000000000F12-0:0-part2", 31 32 "fsType": "btrfs", 32 33 "options": [ 33 34 "x-initrd.mount", 34 35 "subvol=@nix", 36 + "compress=zstd", 37 + "noatime" 38 + ] 39 + }, 40 + "/var/cache": { 41 + "device": "/dev/disk/by-id/usb-Argon_Forty_000000000F12-0:0-part2", 42 + "fsType": "btrfs", 43 + "options": [ 44 + "subvol=@cache", 45 + "nofail", 46 + "compress=zstd", 47 + "noatime" 48 + ] 49 + }, 50 + "/var/log": { 51 + "device": "/dev/disk/by-id/usb-Argon_Forty_000000000F12-0:0-part2", 52 + "fsType": "btrfs", 53 + "options": [ 54 + "x-initrd.mount", 55 + "subvol=@log", 56 + "nofail", 35 57 "compress=zstd", 36 58 "noatime" 37 59 ]
+34 -5
nix/tests/_snapshots/filesystems-steamdeck.snap.json
··· 1 1 { 2 2 "/": { 3 - "device": "/dev/disk/by-partlabel/disk-vdb-root", 3 + "device": "/dev/disk/by-id/nvme-KINGSTON_OM3PDP3512B-A01_50026B7685D47463-part2", 4 4 "fsType": "btrfs", 5 5 "options": [ 6 6 "x-initrd.mount", 7 + "defaults", 7 8 "compress=zstd", 9 + "noatime", 8 10 "subvol=@" 9 11 ] 10 12 }, 11 13 "/.swapvol": { 12 - "device": "/dev/disk/by-partlabel/disk-vdb-root", 14 + "device": "/dev/disk/by-id/nvme-KINGSTON_OM3PDP3512B-A01_50026B7685D47463-part2", 13 15 "fsType": "btrfs", 14 16 "options": [ 15 17 "defaults", ··· 17 19 ] 18 20 }, 19 21 "/boot": { 20 - "device": "/dev/disk/by-partlabel/disk-vdb-ESP", 22 + "device": "/dev/disk/by-id/nvme-KINGSTON_OM3PDP3512B-A01_50026B7685D47463-part1", 21 23 "fsType": "vfat", 22 24 "options": [ 23 25 "defaults" 24 26 ] 25 27 }, 26 28 "/home": { 27 - "device": "/dev/disk/by-partlabel/disk-vdb-root", 29 + "device": "/dev/disk/by-id/nvme-KINGSTON_OM3PDP3512B-A01_50026B7685D47463-part2", 28 30 "fsType": "btrfs", 29 31 "options": [ 32 + "defaults", 30 33 "compress=zstd", 34 + "noatime", 35 + "nofail", 31 36 "subvol=@home" 32 37 ] 33 38 }, 34 39 "/nix": { 35 - "device": "/dev/disk/by-partlabel/disk-vdb-root", 40 + "device": "/dev/disk/by-id/nvme-KINGSTON_OM3PDP3512B-A01_50026B7685D47463-part2", 36 41 "fsType": "btrfs", 37 42 "options": [ 38 43 "x-initrd.mount", 44 + "defaults", 39 45 "compress=zstd", 40 46 "noatime", 41 47 "subvol=@nix" ··· 50 56 "compress=zstd", 51 57 "noatime", 52 58 "nofail" 59 + ] 60 + }, 61 + "/var/cache": { 62 + "device": "/dev/disk/by-id/nvme-KINGSTON_OM3PDP3512B-A01_50026B7685D47463-part2", 63 + "fsType": "btrfs", 64 + "options": [ 65 + "defaults", 66 + "compress=zstd", 67 + "noatime", 68 + "nofail", 69 + "subvol=@cache" 70 + ] 71 + }, 72 + "/var/log": { 73 + "device": "/dev/disk/by-id/nvme-KINGSTON_OM3PDP3512B-A01_50026B7685D47463-part2", 74 + "fsType": "btrfs", 75 + "options": [ 76 + "x-initrd.mount", 77 + "defaults", 78 + "compress=zstd", 79 + "noatime", 80 + "nofail", 81 + "subvol=@log" 53 82 ] 54 83 } 55 84 }