refactor: make luks names predictable

This commit is contained in:
oddlama 2024-01-05 13:29:46 +01:00
parent 490e2ce1a5
commit 664cb45a08
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
14 changed files with 68 additions and 61 deletions

View file

@ -2,19 +2,21 @@
config, config,
lib, lib,
... ...
}: { }: let
inherit (config.repo.secrets.local) disks;
in {
disko.devices = { disko.devices = {
disk = { disk = {
m2-ssd = { ${disks.m2-ssd} = {
type = "disk"; type = "disk";
device = "/dev/disk/by-id/${config.repo.secrets.local.disk.m2-ssd}"; device = "/dev/disk/by-id/${disks.m2-ssd}";
content = with lib.disko.gpt; { content = with lib.disko.gpt; {
type = "table"; type = "table";
format = "gpt"; format = "gpt";
partitions = [ partitions = [
(partEfi "efi" "0%" "1GiB") (partEfi "efi" "0%" "1GiB")
(partSwap "swap" "1GiB" "17GiB") (partSwap "swap" "1GiB" "17GiB")
(partLuksZfs "rpool" "17GiB" "100%") (partLuksZfs disks.m2-ssd "rpool" "17GiB" "100%")
]; ];
}; };
}; };
@ -34,6 +36,4 @@
rpool = mkZpool {datasets = impermanenceZfsDatasets;}; rpool = mkZpool {datasets = impermanenceZfsDatasets;};
}; };
}; };
boot.initrd.luks.devices.enc-rpool.allowDiscards = true;
} }

Binary file not shown.

View file

@ -2,23 +2,25 @@
config, config,
lib, lib,
... ...
}: { }: let
inherit (config.repo.secrets.local) disks;
in {
disko.devices = { disko.devices = {
disk = { disk = {
m2-ssd = { ${disks.m2-ssd} = {
type = "disk"; type = "disk";
device = "/dev/disk/by-id/${config.repo.secrets.local.disk.m2-ssd}"; device = "/dev/disk/by-id/${disks.m2-ssd}";
content = with lib.disko.gpt; { content = with lib.disko.gpt; {
type = "table"; type = "table";
format = "gpt"; format = "gpt";
partitions = [ partitions = [
(partLuksZfs "rpool" "0%" "100%") (partLuksZfs disks.m2-ssd "rpool" "0%" "100%")
]; ];
}; };
}; };
boot-ssd = { ${disks.boot-ssd} = {
type = "disk"; type = "disk";
device = "/dev/disk/by-id/${config.repo.secrets.local.disk.boot-ssd}"; device = "/dev/disk/by-id/${disks.boot-ssd}";
content = with lib.disko.gpt; { content = with lib.disko.gpt; {
type = "table"; type = "table";
format = "gpt"; format = "gpt";
@ -33,6 +35,4 @@
rpool = mkZpool {datasets = impermanenceZfsDatasets;}; rpool = mkZpool {datasets = impermanenceZfsDatasets;};
}; };
}; };
boot.initrd.luks.devices.enc-rpool.allowDiscards = true;
} }

Binary file not shown.

View file

@ -2,19 +2,21 @@
config, config,
lib, lib,
... ...
}: { }: let
inherit (config.repo.secrets.local) disks;
in {
disko.devices = { disko.devices = {
disk = { disk = {
main = { ${disks.main} = {
type = "disk"; type = "disk";
device = "/dev/disk/by-id/${config.repo.secrets.local.disk.main}"; device = "/dev/disk/by-id/${disks.main}";
content = with lib.disko.gpt; { content = with lib.disko.gpt; {
type = "table"; type = "table";
format = "gpt"; format = "gpt";
partitions = [ partitions = [
(partGrub "grub" "0%" "1MiB") (partGrub "grub" "0%" "1MiB")
(partEfi "bios" "1MiB" "512MiB") (partEfi "bios" "1MiB" "512MiB")
(partLuksZfs "rpool" "512MiB" "100%") (partLuksZfs disks.main "rpool" "512MiB" "100%")
]; ];
}; };
}; };
@ -24,6 +26,5 @@
}; };
}; };
boot.loader.grub.devices = ["/dev/disk/by-id/${config.repo.secrets.local.disk.main}"]; boot.loader.grub.devices = ["/dev/disk/by-id/${disks.main}"];
boot.initrd.luks.devices.enc-rpool.allowDiscards = true;
} }

Binary file not shown.

View file

@ -44,9 +44,10 @@
# services.telegraf.extraConfig.inputs.github = {}; # services.telegraf.extraConfig.inputs.github = {};
guests = let guests = let
mkGuest = guestName: { mkGuest = guestName: {enableStorageDataset ? false, ...}: {
autostart = true; autostart = true;
zfs."/state" = { zfs."/state" = {
# TODO make one option out of that? and split into two readonly options automatically?
pool = "rpool"; pool = "rpool";
dataset = "local/guests/${guestName}"; dataset = "local/guests/${guestName}";
}; };
@ -54,6 +55,10 @@
pool = "rpool"; pool = "rpool";
dataset = "safe/guests/${guestName}"; dataset = "safe/guests/${guestName}";
}; };
zfs."/storage" = lib.mkIf enableStorageDataset {
pool = "storage";
dataset = "safe/guests/${guestName}";
};
modules = [ modules = [
../../modules ../../modules
./guests/common.nix ./guests/common.nix
@ -62,9 +67,9 @@
]; ];
}; };
mkMicrovm = guestName: { mkMicrovm = guestName: opts: {
${guestName} = ${guestName} =
mkGuest guestName mkGuest guestName opts
// { // {
backend = "microvm"; backend = "microvm";
microvm = { microvm = {
@ -76,9 +81,9 @@
}; };
# deadnix: skip # deadnix: skip
mkContainer = guestName: { mkContainer = guestName: opts: {
${guestName} = ${guestName} =
mkGuest guestName mkGuest guestName opts
// { // {
backend = "container"; backend = "container";
container.macvlan = "lan"; container.macvlan = "lan";
@ -87,11 +92,11 @@
in in
lib.mkIf (!minimal) ( lib.mkIf (!minimal) (
{} {}
// mkMicrovm "samba" // mkMicrovm "samba" {enableStorageDataset = true;}
// mkMicrovm "grafana" // mkMicrovm "grafana" {}
// mkMicrovm "influxdb" // mkMicrovm "influxdb" {}
// mkMicrovm "loki" // mkMicrovm "loki" {}
// mkMicrovm "paperless" // mkMicrovm "paperless" {}
#// mkMicrovm "minecraft" #// mkMicrovm "minecraft"
#// mkMicrovm "immich" #// mkMicrovm "immich"
#// mkMicrovm "firefly" #// mkMicrovm "firefly"

View file

@ -2,32 +2,34 @@
config, config,
lib, lib,
... ...
}: { }: let
inherit (config.repo.secrets.local) disks;
in {
disko.devices = { disko.devices = {
disk = disk =
{ {
m2-ssd-1 = { ${disks.m2-ssd-1} = {
type = "disk"; type = "disk";
device = "/dev/disk/by-id/${config.repo.secrets.local.disk.m2-ssd-1}"; device = "/dev/disk/by-id/${disks.m2-ssd-1}";
content = with lib.disko.gpt; { content = with lib.disko.gpt; {
type = "table"; type = "table";
format = "gpt"; format = "gpt";
partitions = [ partitions = [
(partEfi "efi" "0%" "1GiB") (partEfi "efi" "0%" "1GiB")
(partLuksZfs "rpool" "1GiB" "100%") (partLuksZfs disks.m2-ssd-1 "rpool" "1GiB" "100%")
]; ];
}; };
}; };
m2-ssd-2 = { ${disks.m2-ssd-2} = {
type = "disk"; type = "disk";
device = "/dev/disk/by-id/${config.repo.secrets.local.disk.m2-ssd-2}"; device = "/dev/disk/by-id/${disks.m2-ssd-2}";
content = lib.disko.content.luksZfs "rpool"; content = lib.disko.content.luksZfs disks.m2-ssd-2 "rpool";
}; };
} }
// lib.genAttrs config.repo.secrets.local.disk.hdds-tank (disk: { // lib.genAttrs disks.hdds-storage (disk: {
type = "disk"; type = "disk";
device = "/dev/disk/by-id/${disk}"; device = "/dev/disk/by-id/${disk}";
content = lib.disko.content.luksZfs "tank"; content = lib.disko.content.luksZfs disk "storage";
}); });
zpool = with lib.disko.zfs; { zpool = with lib.disko.zfs; {
rpool = mkZpool { rpool = mkZpool {
@ -38,7 +40,7 @@
"safe/guests" = unmountable; "safe/guests" = unmountable;
}; };
}; };
tank = mkZpool { storage = mkZpool {
mode = "raidz1"; mode = "raidz1";
datasets = { datasets = {
"safe/guests" = unmountable; "safe/guests" = unmountable;
@ -75,7 +77,7 @@
filesystems = { filesystems = {
"rpool/local/state<" = true; "rpool/local/state<" = true;
"rpool/safe<" = true; "rpool/safe<" = true;
"tank/safe<" = true; "storage/safe<" = true;
}; };
snapshotting = { snapshotting = {
type = "periodic"; type = "periodic";
@ -112,7 +114,4 @@
]; ];
}; };
}; };
boot.initrd.luks.devices.enc-rpool.allowDiscards = true;
boot.initrd.luks.devices.enc-tank.allowDiscards = true;
} }

Binary file not shown.

View file

@ -2,19 +2,21 @@
config, config,
lib, lib,
... ...
}: { }: let
inherit (config.repo.secrets.local) disks;
in {
disko.devices = { disko.devices = {
disk = { disk = {
m2-ssd = { ${disks.m2-ssd} = {
type = "disk"; type = "disk";
device = "/dev/disk/by-id/${config.repo.secrets.local.disk.m2-ssd}"; device = "/dev/disk/by-id/${disks.m2-ssd}";
content = with lib.disko.gpt; { content = with lib.disko.gpt; {
type = "table"; type = "table";
format = "gpt"; format = "gpt";
partitions = [ partitions = [
(partEfi "efi" "0%" "1GiB") (partEfi "efi" "0%" "1GiB")
(partSwap "swap" "1GiB" "17GiB") (partSwap "swap" "1GiB" "17GiB")
(partLuksZfs "rpool" "17GiB" "100%") (partLuksZfs disks.m2-ssd "rpool" "17GiB" "100%")
]; ];
}; };
}; };
@ -94,6 +96,4 @@
]; ];
}; };
}; };
boot.initrd.luks.devices.enc-rpool.allowDiscards = true;
} }

Binary file not shown.

View file

@ -2,19 +2,21 @@
config, config,
lib, lib,
... ...
}: { }: let
inherit (config.repo.secrets.local) disks;
in {
disko.devices = { disko.devices = {
disk = { disk = {
mmc = { ${disks.mmc} = {
type = "disk"; type = "disk";
device = "/dev/disk/by-id/${config.repo.secrets.local.disk.mmc}"; device = "/dev/disk/by-id/${disks.mmc}";
content = with lib.disko.gpt; { content = with lib.disko.gpt; {
type = "table"; type = "table";
format = "gpt"; format = "gpt";
partitions = [ partitions = [
(partEfi "efi" "0%" "1GiB") (partEfi "efi" "0%" "1GiB")
(partSwap "swap" "1GiB" "9GiB") (partSwap "swap" "1GiB" "9GiB")
(partLuksZfs "rpool" "9GiB" "100%") (partLuksZfs disks.mmc "rpool" "9GiB" "100%")
]; ];
}; };
}; };

View file

@ -4,13 +4,13 @@ _inputs: final: prev: {
// { // {
disko = { disko = {
content = { content = {
luksZfs = name: { luksZfs = luksName: pool: {
type = "luks"; type = "luks";
name = "enc-${name}"; name = "${pool}_${luksName}";
extraOpenArgs = ["--allow-discards"]; settings.allowDiscards = true;
content = { content = {
type = "zfs"; type = "zfs";
pool = name; inherit pool;
}; };
}; };
}; };
@ -38,10 +38,10 @@ _inputs: final: prev: {
randomEncryption = true; randomEncryption = true;
}; };
}; };
partLuksZfs = name: start: end: { partLuksZfs = luksName: pool: start: end: {
inherit start end; inherit start end;
name = "enc-${name}"; name = "${pool}_${luksName}";
content = final.lib.disko.content.luksZfs name; content = final.lib.disko.content.luksZfs luksName pool;
}; };
}; };
zfs = rec { zfs = rec {