fix disko

This commit is contained in:
2024-10-18 20:25:54 -05:00
parent 782086e95a
commit 854fd1641f
6 changed files with 128 additions and 154 deletions

60
flake.lock generated
View File

@@ -189,16 +189,15 @@
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
"system", "system",
"diskoConfig",
"nixpkgs" "nixpkgs"
] ]
}, },
"locked": { "locked": {
"lastModified": 1729099656, "lastModified": 1729281548,
"narHash": "sha256-VftVIg7UXTy1bq+tzi1aVYOWl7PQ35IpjW88yMYjjpc=", "narHash": "sha256-MuojlSnwAJAwfhgmW8ZtZrwm2Sko4fqubCvReqbUzYw=",
"owner": "nix-community", "owner": "nix-community",
"repo": "disko", "repo": "disko",
"rev": "d7d57edb72e54891fa67a6f058a46b2bb405663b", "rev": "a6a3179ddf396dfc28a078e2f169354d0c137125",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -207,22 +206,6 @@
"type": "github" "type": "github"
} }
}, },
"diskoConfig": {
"inputs": {
"disko": "disko",
"nixpkgs": "nixpkgs_10"
},
"locked": {
"lastModified": 1,
"narHash": "sha256-SakyZnAhoToQmui5hozmLqkoLw6N/AHCgKF4tCP/sTQ=",
"path": "/mnt/nix/store/6632xfzj8dykclkxzhjbigh06hkvia70-source/disko",
"type": "path"
},
"original": {
"path": "/mnt/nix/store/6632xfzj8dykclkxzhjbigh06hkvia70-source/disko",
"type": "path"
}
},
"external": { "external": {
"inputs": { "inputs": {
"digital": "digital", "digital": "digital",
@@ -1044,11 +1027,11 @@
"locked": { "locked": {
"lastModified": 0, "lastModified": 0,
"narHash": "sha256-Hz1a2OgtlwgdQhI6hiUvityjVURsoY6oXkXq25RyiBM=", "narHash": "sha256-Hz1a2OgtlwgdQhI6hiUvityjVURsoY6oXkXq25RyiBM=",
"path": "/mnt/nix/store/v3m4p7s1ncm6x2qdbfn8h7816rfidrww-source/home", "path": "/mnt/nix/store/fd7h31g5h6jvpd4hw51q3qa47maycj3b-source/home",
"type": "path" "type": "path"
}, },
"original": { "original": {
"path": "/mnt/nix/store/v3m4p7s1ncm6x2qdbfn8h7816rfidrww-source/home", "path": "/mnt/nix/store/fd7h31g5h6jvpd4hw51q3qa47maycj3b-source/home",
"type": "path" "type": "path"
} }
}, },
@@ -1294,11 +1277,11 @@
}, },
"nixpkgs_7": { "nixpkgs_7": {
"locked": { "locked": {
"lastModified": 1729044727, "lastModified": 1729181673,
"narHash": "sha256-GKJjtPY+SXfLF/yTN7M2cAnQB6RERFKnQhD8UvPSf3M=", "narHash": "sha256-LDiPhQ3l+fBjRATNtnuDZsBS7hqoBtPkKBkhpoBHv3I=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "dc2e0028d274394f73653c7c90cc63edbb696be1", "rev": "4eb33fe664af7b41a4c446f87d20c9a0a6321fa3",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -1310,11 +1293,11 @@
}, },
"nixpkgs_8": { "nixpkgs_8": {
"locked": { "locked": {
"lastModified": 1729044727, "lastModified": 1729181673,
"narHash": "sha256-GKJjtPY+SXfLF/yTN7M2cAnQB6RERFKnQhD8UvPSf3M=", "narHash": "sha256-LDiPhQ3l+fBjRATNtnuDZsBS7hqoBtPkKBkhpoBHv3I=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "dc2e0028d274394f73653c7c90cc63edbb696be1", "rev": "4eb33fe664af7b41a4c446f87d20c9a0a6321fa3",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -1434,11 +1417,11 @@
"locked": { "locked": {
"lastModified": 1, "lastModified": 1,
"narHash": "sha256-6oCDKhDSqJMWeODXDHD5XorN7/+KXBBIPZ2z+obwUNY=", "narHash": "sha256-6oCDKhDSqJMWeODXDHD5XorN7/+KXBBIPZ2z+obwUNY=",
"path": "/mnt/nix/store/6632xfzj8dykclkxzhjbigh06hkvia70-source/packages", "path": "/mnt/nix/store/2r9s3wx2jba75hvnflgiqnpmxfw3hsy5-source/packages",
"type": "path" "type": "path"
}, },
"original": { "original": {
"path": "/mnt/nix/store/6632xfzj8dykclkxzhjbigh06hkvia70-source/packages", "path": "/mnt/nix/store/2r9s3wx2jba75hvnflgiqnpmxfw3hsy5-source/packages",
"type": "path" "type": "path"
} }
}, },
@@ -1524,11 +1507,11 @@
"locked": { "locked": {
"lastModified": 1, "lastModified": 1,
"narHash": "sha256-hg0wqQn6BxQXLmfBINzZoaWpdSIlwwZxKbYz+4df83o=", "narHash": "sha256-hg0wqQn6BxQXLmfBINzZoaWpdSIlwwZxKbYz+4df83o=",
"path": "/mnt/nix/store/6632xfzj8dykclkxzhjbigh06hkvia70-source/programs", "path": "/mnt/nix/store/2r9s3wx2jba75hvnflgiqnpmxfw3hsy5-source/programs",
"type": "path" "type": "path"
}, },
"original": { "original": {
"path": "/mnt/nix/store/6632xfzj8dykclkxzhjbigh06hkvia70-source/programs", "path": "/mnt/nix/store/2r9s3wx2jba75hvnflgiqnpmxfw3hsy5-source/programs",
"type": "path" "type": "path"
} }
}, },
@@ -1655,30 +1638,31 @@
"locked": { "locked": {
"lastModified": 1, "lastModified": 1,
"narHash": "sha256-VZKans7CW3BgyWaVgi9mGKvJsCvyse2zLPRB5fJnlfA=", "narHash": "sha256-VZKans7CW3BgyWaVgi9mGKvJsCvyse2zLPRB5fJnlfA=",
"path": "/mnt/nix/store/6632xfzj8dykclkxzhjbigh06hkvia70-source/services", "path": "/mnt/nix/store/2r9s3wx2jba75hvnflgiqnpmxfw3hsy5-source/services",
"type": "path" "type": "path"
}, },
"original": { "original": {
"path": "/mnt/nix/store/6632xfzj8dykclkxzhjbigh06hkvia70-source/services", "path": "/mnt/nix/store/2r9s3wx2jba75hvnflgiqnpmxfw3hsy5-source/services",
"type": "path" "type": "path"
} }
}, },
"system": { "system": {
"inputs": { "inputs": {
"diskoConfig": "diskoConfig", "disko": "disko",
"impermanence": "impermanence", "impermanence": "impermanence",
"nixpkgs": "nixpkgs_10",
"pckgs": "pckgs", "pckgs": "pckgs",
"prgms": "prgms_2", "prgms": "prgms_2",
"srvcs": "srvcs" "srvcs": "srvcs"
}, },
"locked": { "locked": {
"lastModified": 1, "lastModified": 1,
"narHash": "sha256-4o+6OFouADJTS6Q5yawUGFLMoOUX8Mf/zIIlTARisj4=", "narHash": "sha256-Pk5COJNed5x87n/zc1ljP6CL8YvSOrKFPKcveKtjD/c=",
"path": "/mnt/nix/store/v3m4p7s1ncm6x2qdbfn8h7816rfidrww-source/system", "path": "/mnt/nix/store/fd7h31g5h6jvpd4hw51q3qa47maycj3b-source/system",
"type": "path" "type": "path"
}, },
"original": { "original": {
"path": "/mnt/nix/store/v3m4p7s1ncm6x2qdbfn8h7816rfidrww-source/system", "path": "/mnt/nix/store/fd7h31g5h6jvpd4hw51q3qa47maycj3b-source/system",
"type": "path" "type": "path"
} }
}, },

View File

@@ -47,7 +47,7 @@
sysconfig = { sysconfig = {
${host}.enable = true; ${host}.enable = true;
opts = { opts = {
firstBoot = false; firstBoot = true;
inherit host username devices; inherit host username devices;
}; };
}; };

View File

@@ -13,26 +13,14 @@
}; };
}; };
imports = [
./disko.nix
./disko_bonus.nix
./impermanent.nix
];
config = lib.mkIf config.disko.enable (lib.mkMerge [ config = lib.mkIf config.disko.enable (lib.mkMerge [
{
imports = [
./disko.nix { device = config.sysconfig.opts.devices.main; }
];
}
(lib.mkIf (config.sysconfig.opts.devices.bonus != null) {
imports = [
(./disko_bonus.nix { devices = config.sysconfig.opts.devices.bonus; })
];
})
(lib.mkIf config.disko.impermanent {
imports = [
./impermanent.nix
];
})
(lib.mkIf (!config.disko.enable) { (lib.mkIf (!config.disko.enable) {
disko.impermanent = lib.mkForce false; disko.impermanent = lib.mkForce false;
}) })

View File

@@ -1,66 +1,67 @@
{ device ? throw "Set this to your device e.g. /dev/sda", ... }: { { config, lib, ... }: {
config = lib.mkIf config.disko.enable {
disko.devices = { disko.devices = {
disk.main = { disk.main = {
inherit device; device = config.sysconfig.opts.devices.main;
type = "disk"; type = "disk";
content = { content = {
type = "gpt"; type = "gpt";
partitions = { partitions = {
boot = { boot = {
name = "boot"; name = "boot";
size = "1M"; size = "1M";
type = "EF02"; type = "EF02";
};
esp = {
name = "ESP";
size = "500M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
}; };
}; esp = {
swap = { name = "ESP";
size = "4G"; size = "500M";
content = { type = "EF00";
type = "swap"; content = {
resumeDevice = true; type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}; };
}; swap = {
root = { size = "4G";
name = "root"; content = {
size = "100%"; type = "swap";
content = { resumeDevice = true;
type = "lvm_pv"; };
vg = "root_vg"; };
root = {
name = "root";
size = "100%";
content = {
type = "lvm_pv";
vg = "root_vg";
};
}; };
}; };
}; };
}; };
};
lvm_vg = { lvm_vg = {
root_vg = { root_vg = {
type = "lvm_vg"; type = "lvm_vg";
lvs = { lvs = {
root = { root = {
size = "100%FREE"; size = "100%FREE";
content = { content = {
type = "btrfs"; type = "btrfs";
extraArgs = [ "-f" ]; extraArgs = [ "-f" ];
subvolumes = { subvolumes = {
"/root" = { "/root" = {
mountpoint = "/"; mountpoint = "/";
}; };
"/persist" = { "/persist" = {
mountOptions = [ "subvol=persist" "noatime" ]; mountOptions = [ "subvol=persist" "noatime" ];
mountpoint = "/persist"; mountpoint = "/persist";
}; };
"/nix" = { "/nix" = {
mountOptions = [ "subvol=nix" "noatime" ]; mountOptions = [ "subvol=nix" "noatime" ];
mountpoint = "/nix"; mountpoint = "/nix";
};
}; };
}; };
}; };

View File

@@ -1,26 +1,26 @@
{ devices ? throw "Set this to an attribute set of your devices e.g. { disk1 = \"/dev/sda\"; }", ... }: { { config, lib, ... }: {
disko.devices = builtins.mapAttrs (name: device: { config = lib.mkIf (config.disko.enable && config.sysconfig.opts.devices.bonus != null) {
disk.${name} = { disko.devices = {
inherit device; disk = builtins.mapAttrs (name: device: {
type = "disk"; inherit device;
content = { type = "disk";
type = "gpt"; content = {
partitions = { type = "gpt";
${name} = { partitions = {
name = "${name}"; ${name} = {
size = "100%"; name = "${name}";
content = { size = "100%";
type = "lvm_pv"; content = {
vg = "$name_vg"; type = "lvm_pv";
vg = "$name_vg";
};
}; };
}; };
}; };
}; }) config.sysconfig.opts.devices.bonus;
};
lvm_vg = { lvm_vg = builtins.mapAttrs (name: device: {
"${name}_vg" = {
type = "lvm_vg"; type = "lvm_vg";
lvs = { lvs = {
${name} = { ${name} = {
@@ -37,7 +37,7 @@
}; };
}; };
}; };
}; }) config.sysconfig.opts.devices.bonus;
}; };
}) devices; };
} }

View File

@@ -1,29 +1,30 @@
{ lib, ... }: { { config, lib, ... }: {
boot.initrd.postDeviceCommands = lib.mkAfter '' config = lib.mkIf config.disko.impermanent {
mkdir /btrfs_tmp boot.initrd.postDeviceCommands = lib.mkAfter ''
mount /dev/root_vg/root /btrfs_tmp mkdir /btrfs_tmp
if [[ -e /btrfs_tmp/root ]]; then mount /dev/root_vg/root /btrfs_tmp
mkdir -p /btrfs_tmp/old_roots if [[ -e /btrfs_tmp/root ]]; then
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%d_%H:%M:%S") mkdir -p /btrfs_tmp/old_roots
mv /btrfs_tmp/root "btrfs_tmp/old_roots/$timestamp" timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%d_%H:%M:%S")
fi mv /btrfs_tmp/root "btrfs_tmp/old_roots/$timestamp"
fi
deleteSubvolumeRecursively() { deleteSubvolumeRecursively() {
IFS=$'\n' IFS=$'\n'
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
deleteSubvolumeRecursively "/btrfs_tmp/$i" deleteSubvolumeRecursively "/btrfs_tmp/$i"
done; done;
btrfs subvolume delete $1 btrfs subvolume delete $1
} }
for i in $(find /btrfs_tmp/old_roots -maxdepth 1 -mtime +30); do for i in $(find /btrfs_tmp/old_roots -maxdepth 1 -mtime +30); do
deleteSubvolumeRecursively "$i" deleteSubvolumeRecursively "$i"
done done
btrfs subvolume create /btrfs_tmp/root btrfs subvolume create /btrfs_tmp/root
umount /btrfs_tmp umount /btrfs_tmp
''; '';
config.initialPasswords = lib.mkForce true; };
} }