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

View File

@@ -47,7 +47,7 @@
sysconfig = {
${host}.enable = true;
opts = {
firstBoot = false;
firstBoot = true;
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 [
{
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) {
disko.impermanent = lib.mkForce false;
})

View File

@@ -1,66 +1,67 @@
{ device ? throw "Set this to your device e.g. /dev/sda", ... }: {
disko.devices = {
disk.main = {
inherit device;
type = "disk";
content = {
type = "gpt";
partitions = {
boot = {
name = "boot";
size = "1M";
type = "EF02";
};
esp = {
name = "ESP";
size = "500M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
{ config, lib, ... }: {
config = lib.mkIf config.disko.enable {
disko.devices = {
disk.main = {
device = config.sysconfig.opts.devices.main;
type = "disk";
content = {
type = "gpt";
partitions = {
boot = {
name = "boot";
size = "1M";
type = "EF02";
};
};
swap = {
size = "4G";
content = {
type = "swap";
resumeDevice = true;
esp = {
name = "ESP";
size = "500M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
};
};
root = {
name = "root";
size = "100%";
content = {
type = "lvm_pv";
vg = "root_vg";
swap = {
size = "4G";
content = {
type = "swap";
resumeDevice = true;
};
};
root = {
name = "root";
size = "100%";
content = {
type = "lvm_pv";
vg = "root_vg";
};
};
};
};
};
};
lvm_vg = {
root_vg = {
type = "lvm_vg";
lvs = {
root = {
size = "100%FREE";
content = {
type = "btrfs";
extraArgs = [ "-f" ];
subvolumes = {
"/root" = {
mountpoint = "/";
};
"/persist" = {
mountOptions = [ "subvol=persist" "noatime" ];
mountpoint = "/persist";
};
"/nix" = {
mountOptions = [ "subvol=nix" "noatime" ];
mountpoint = "/nix";
lvm_vg = {
root_vg = {
type = "lvm_vg";
lvs = {
root = {
size = "100%FREE";
content = {
type = "btrfs";
extraArgs = [ "-f" ];
subvolumes = {
"/root" = {
mountpoint = "/";
};
"/persist" = {
mountOptions = [ "subvol=persist" "noatime" ];
mountpoint = "/persist";
};
"/nix" = {
mountOptions = [ "subvol=nix" "noatime" ];
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: {
disk.${name} = {
inherit device;
type = "disk";
content = {
type = "gpt";
partitions = {
${name} = {
name = "${name}";
size = "100%";
content = {
type = "lvm_pv";
vg = "$name_vg";
config = lib.mkIf (config.disko.enable && config.sysconfig.opts.devices.bonus != null) {
disko.devices = {
disk = builtins.mapAttrs (name: device: {
inherit device;
type = "disk";
content = {
type = "gpt";
partitions = {
${name} = {
name = "${name}";
size = "100%";
content = {
type = "lvm_pv";
vg = "$name_vg";
};
};
};
};
};
};
}) config.sysconfig.opts.devices.bonus;
lvm_vg = {
"${name}_vg" = {
lvm_vg = builtins.mapAttrs (name: device: {
type = "lvm_vg";
lvs = {
${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 ''
mkdir /btrfs_tmp
mount /dev/root_vg/root /btrfs_tmp
if [[ -e /btrfs_tmp/root ]]; then
mkdir -p /btrfs_tmp/old_roots
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%d_%H:%M:%S")
mv /btrfs_tmp/root "btrfs_tmp/old_roots/$timestamp"
fi
config = lib.mkIf config.disko.impermanent {
boot.initrd.postDeviceCommands = lib.mkAfter ''
mkdir /btrfs_tmp
mount /dev/root_vg/root /btrfs_tmp
if [[ -e /btrfs_tmp/root ]]; then
mkdir -p /btrfs_tmp/old_roots
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%d_%H:%M:%S")
mv /btrfs_tmp/root "btrfs_tmp/old_roots/$timestamp"
fi
deleteSubvolumeRecursively() {
IFS=$'\n'
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
deleteSubvolumeRecursively "/btrfs_tmp/$i"
done;
btrfs subvolume delete $1
}
deleteSubvolumeRecursively() {
IFS=$'\n'
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
deleteSubvolumeRecursively "/btrfs_tmp/$i"
done;
btrfs subvolume delete $1
}
for i in $(find /btrfs_tmp/old_roots -maxdepth 1 -mtime +30); do
deleteSubvolumeRecursively "$i"
done
done
btrfs subvolume create /btrfs_tmp/root
umount /btrfs_tmp
'';
btrfs subvolume create /btrfs_tmp/root
umount /btrfs_tmp
'';
config.initialPasswords = lib.mkForce true;
};
}