Major rework in progress

This commit is contained in:
2024-10-10 11:01:59 -05:00
parent 35d920744f
commit f11a6ab86e
26 changed files with 742 additions and 253 deletions

36
system/disko/default.nix Normal file
View File

@@ -0,0 +1,36 @@
{ config, lib, devices, ... }: {
options = {
disko = {
enable = lib.options.mkOption {
default = false;
type = lib.types.bool;
};
impermanent = lib.options.mkOption {
default = false;
type = lib.types.bool;
};
};
};
config = lib.mkIf config.disko.enable (lib.mkMerge [
{
imports = [
./disko.nix { device = devices.main; }
];
}
(lib.mkIf (devices.bonus != null) {
imports = [
(./disko_bonus.nix { devices = devices.bonus; })
];
})
(lib.mkIf config.disko.impermanent {
imports = [
./impermanent.nix
];
})
]);
}

72
system/disko/disko.nix Normal file
View File

@@ -0,0 +1,72 @@
{ 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";
};
};
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";
};
};
};
};
};
};
};
};
}

View File

@@ -0,0 +1,43 @@
{ devices ? throw "Set this to an attribute set of your devices e.g. { disk1 = \"/dev/sda\"; }", ... }: {
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";
};
};
};
};
};
lvm_vg = {
"${name}_vg" = {
type = "lvm_vg";
lvs = {
${name} = {
size = "100%FREE";
content = {
type = "btrfs";
extraArgs = [ "-f" ];
subvolumes = {
"/${name}" = {
mountOptions = [ "subvol=${name}" "noatime" ];
mountpoint = "/${name}";
};
};
};
};
};
};
};
}) devices;
}

19
system/disko/flake.nix Normal file
View File

@@ -0,0 +1,19 @@
{
description = "disko config";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
disko.url = "github:nix-community/disko";
disko.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { ... }@inputs: {
module = { config, lib, pkgs, devices, ... }: {
imports = [
(./default.nix { inherit devices; })
inputs.disko.nixosModules.default
];
};
};
}

View File

@@ -0,0 +1,29 @@
{ 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
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
btrfs subvolume create /btrfs_tmp/root
umount /btrfs_tmp
'';
config.initialPasswords = lib.mkForce true;
}