feat: move common disko functionality into lib

This commit is contained in:
oddlama 2023-04-30 13:41:09 +02:00
parent f62b01f206
commit 08290e5052
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
6 changed files with 80 additions and 70 deletions

View file

@ -63,7 +63,7 @@ This is my personal nix config.
#### Initial deploy #### Initial deploy
- Create a iso disk image for the system by using `nix build --print-out-paths --no-link .#installer-image-<host>` - Create a iso disk image for the system with `nix build --print-out-paths --no-link .#installer-image-<host>`
- dd the resulting image to a stick and boot from it on the target - dd the resulting image to a stick and boot from it on the target
- (Optional) ssh into the target (keys are already set up) - (Optional) ssh into the target (keys are already set up)
- Run `install-system` and reboot - Run `install-system` and reboot

View file

@ -6,6 +6,10 @@
boot.supportedFilesystems = ["zfs"]; boot.supportedFilesystems = ["zfs"];
boot.kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages; boot.kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages;
# The root pool should never be imported forcefully.
# Failure to import is important to notice!
boot.zfs.forceImportRoot = false;
environment.systemPackages = with pkgs; [zfs]; environment.systemPackages = with pkgs; [zfs];
services.zfs = { services.zfs = {

View file

@ -1,4 +1,8 @@
{nodeSecrets, ...}: { {
config,
nodeSecrets,
...
}: {
networking = { networking = {
inherit (nodeSecrets.networking) hostId; inherit (nodeSecrets.networking) hostId;
wireless.iwd.enable = true; wireless.iwd.enable = true;

View file

@ -1,5 +1,6 @@
{ {
extraLib, extraLib,
nodeSecrets,
pkgs, pkgs,
... ...
}: { }: {
@ -7,49 +8,38 @@
disk = { disk = {
m2-ssd = { m2-ssd = {
type = "disk"; type = "disk";
device = "/dev/disk/by-id/nvme-Samsung_SSD_980_1TB_S649NL0TC36758M"; device = "/dev/disk/by-id/${nodeSecrets.disk.m2-ssd}";
content = { content = with extraLib.disko.gpt; {
type = "table"; type = "table";
format = "gpt"; format = "gpt";
partitions = [ partitions = [
{ (partEfi "efi" "0%" "1GiB")
name = "efi"; (partSwap "swap" "1GiB" "17GiB")
start = "0%"; (partZfs "rpool" "17GiB" "100%")
end = "1GiB";
fs-type = "fat32";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
{
name = "swap";
start = "1GiB";
end = "17GiB";
fs-type = "linux-swap";
content = {
type = "swap";
randomEncryption = true;
};
}
{
name = "rpool";
start = "17GiB";
end = "100%";
content = {
type = "zfs";
pool = "rpool";
};
}
]; ];
}; };
}; };
}; };
zpool = extraLib.disko.defineEncryptedZpool "rpool" {}; zpool = with extraLib.disko.zfs; {
rpool =
encryptedZpool
// {
datasets = {
"local" = unmountable;
"local/root" =
filesystem "/"
// {
postCreateHook = "zfs snapshot rpool/local/root@blank";
};
"local/nix" = filesystem "/nix";
"safe" = unmountable;
"safe/persist" = filesystem "/persist";
};
};
};
}; };
# After importing the rpool, rollback the root system to be empty.
boot.initrd.systemd.services = { boot.initrd.systemd.services = {
impermanence-root = { impermanence-root = {
wantedBy = ["initrd.target"]; wantedBy = ["initrd.target"];

Binary file not shown.

View file

@ -19,6 +19,7 @@
mapAttrs' mapAttrs'
mergeAttrs mergeAttrs
nameValuePair nameValuePair
optionalAttrs
partition partition
recursiveUpdate recursiveUpdate
removeSuffix removeSuffix
@ -48,11 +49,36 @@ in rec {
# True if the path or string starts with / # True if the path or string starts with /
isAbsolutePath = x: substring 0 1 x == "/"; isAbsolutePath = x: substring 0 1 x == "/";
# Defines a simple encrypted and compressed pool disko = {
# with datasets necessary datasets for use with impermanence gpt = {
disko.defineEncryptedZpool = name: partEfi = name: start: end: {
recursiveUpdate { inherit name start end;
${name} = { fs-type = "fat32";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
};
partSwap = name: start: end: {
inherit name start end;
fs-type = "linux-swap";
content = {
type = "swap";
randomEncryption = true;
};
};
partZfs = name: start: end: {
inherit name start end;
content = {
type = "zfs";
pool = name;
};
};
};
zfs = {
encryptedZpool = {
type = "zpool"; type = "zpool";
mountRoot = "/mnt"; mountRoot = "/mnt";
rootFsOptions = { rootFsOptions = {
@ -69,37 +95,23 @@ in rec {
keylocation = "prompt"; keylocation = "prompt";
}; };
options.ashift = "12"; options.ashift = "12";
datasets = {
"local".type = "zfs_fs";
"local/root" = {
type = "zfs_fs";
postCreateHook = "zfs snapshot ${name}/local/root@blank";
options = {
canmount = "on";
mountpoint = "/";
};
mountpoint = "/";
};
"local/nix" = {
type = "zfs_fs";
options = {
canmount = "on";
mountpoint = "/nix";
};
mountpoint = "/nix";
};
"safe".type = "zfs_fs";
"safe/persist" = {
type = "zfs_fs";
options = {
canmount = "on";
mountpoint = "/persist";
};
mountpoint = "/persist";
};
};
}; };
unmountable = {type = "zfs_fs";};
filesystem = mountpoint:
{
type = "zfs_fs";
options = {
canmount = "on";
inherit mountpoint;
};
}
// optionalAttrs (mountpoint == "/") {
# Required to add dependencies for initrd
inherit mountpoint;
};
}; };
};
rageMasterIdentityArgs = concatMapStrings (x: ''-i ${escapeShellArg x} '') self.secrets.masterIdentities; rageMasterIdentityArgs = concatMapStrings (x: ''-i ${escapeShellArg x} '') self.secrets.masterIdentities;
rageExtraEncryptionPubkeys = rageExtraEncryptionPubkeys =