fix disko
This commit is contained in:
@@ -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;
|
||||
})
|
||||
|
||||
@@ -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";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user