Continue refactor towards disko

This commit is contained in:
Jimbo 2024-11-06 11:49:40 -05:00
parent f2cdf01122
commit fe16e208b6
25 changed files with 476 additions and 249 deletions

View file

@ -72,21 +72,21 @@
};
};
in {
# nixos-rebuild switch --flake .#hostname
# nixos-rebuild switch --flake /etc/nixos#hostname
nixosConfigurations = {
firefly = mkNix [ ./hosts/firefly ]; # Main Desktop
detritus = mkNix [ ./hosts/detritus/system ]; # Acer Desktop
detritus = mkNix [ ./hosts/detritus ]; # Acer Desktop
shuttle = mkNix [ ./hosts/shuttleworth/system ]; # Pinebook Pro
lacros = mkNix [ ./hosts/lacros/system ]; # Dell Chromebook
shuttle = mkNix [ ./hosts/shuttleworth ]; # Pinebook Pro
lacros = mkNix [ ./hosts/lacros ]; # Dell Chromebook
redmond = mkNix [ ./hosts/redmond ]; # Lenovo Dual-Boot Laptop
treefruit = mkNix [ ./hosts/treefruit/system ]; # Macbook Pro 14,1
treefruit = mkNix [ ./hosts/treefruit ]; # Macbook Pro 14,1
cyberspark = mkNix [ ./hosts/cyberspark/system ]; # Dell Optiplex 7010
bomberman = mkNix [ ./hosts/bomberman/system ]; # Oracle ARM
cyberspark = mkNix [ ./hosts/cyberspark ]; # Dell Optiplex 7010
bomberman = mkNix [ ./hosts/bomberman ]; # Oracle ARM
};
# home-manager switch --flake .#username
# home-manager switch --flake /etc/nixos#username
homeConfigurations."jimbo" = mkHome [ ./modules/home ] nixpkgs.legacyPackages.x86_64-linux;
};
}

View file

@ -0,0 +1,37 @@
{ pkgs, ... }:
{
boot = {
initrd = {
systemd = {
enable = true;
services.root-reset = {
description = "Reset root and snapshot last boot";
wantedBy = [ "initrd.target" ];
after = [ "dev-${config.networking.hostName}-root.device" ];
before = [ "sysroot.mount" ];
unitConfig.DefaultDependencies = "no";
serviceConfig.Type = "oneshot";
script = ''
mkdir -p /mnt
mount /dev/${config.networking.hostName}/root /mnt
if [[ -e /mnt/prev ]]; then
btrfs subvolume delete /mnt/prev
fi
btrfs subvolume snapshot /mnt/root /mnt/prev
btrfs subvolume list -o /mnt/root | cut -f9 -d' ' | while read subvolume; do
btrfs subvolume delete "/mnt/$subvolume"
done
btrfs subvolume delete /mnt/root
btrfs subvolume create /mnt/root
umount /mnt
'';
};
};
};
};
}

View file

@ -0,0 +1,96 @@
{ disko, config, ... }:
{
imports = [ disko.nixosModules.disko ];
disko.devices = {
disk = {
"${config.networking.hostName}" = {
type = "disk";
device = "/dev/nvme0n1";
content = {
type = "gpt";
partitions = {
ESP = {
size = "2G";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "umask=0077" ];
};
};
luks = {
size = "100%";
content = {
type = "luks";
name = "${config.networking.hostName}-disk";
settings.allowDiscards = true;
passwordFile = "/tmp/secret.key";
content = {
type = "lvm_pv";
vg = "${config.networking.hostName}";
};
};
};
};
};
};
};
lvm_vg = {
"${config.networking.hostName}" = {
type = "lvm_vg";
lvs = {
root = {
size = "100%";
content = {
type = "btrfs";
extraArgs = [ "-f" ];
subvolumes = {
"/root" = {
mountpoint = "/";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/prev" = {
mountpoint = "/prev";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/nix" = {
mountpoint = "/nix";
mountOptions = [ "compress=zstd" "noatime" ];
};
# Impermanence
"/persist" = {
mountpoint = "/persist";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/persist/.snapshots" = { };
"/jimbo" = {
mountpoint = "/persist/home/jimbo";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/jimbo/.snapshots" = { };
};
};
};
swap = {
size = "8G";
content = {
type = "swap";
discardPolicy = "both";
};
};
};
};
};
};
# Needed for impermanence
fileSystems = {
"/persist".neededForBoot = true;
"/persist/home/jimbo".neededForBoot = true;
};
}

View file

@ -1,14 +0,0 @@
{ ... }:
{
imports = [
../../../modules/home/users
../../../modules/home/programs/misc/headless
../../../modules/home/programs/terminal/fastfetch
../../../modules/home/programs/terminal/git
../../../modules/home/programs/terminal/neovim
../../../modules/home/programs/terminal/ranger
../../../modules/home/programs/terminal/tmux
../../../modules/home/programs/terminal/zsh
../../../variables/domains
];
}

View file

@ -0,0 +1,7 @@
{ pkgs, ... }:
{
boot = {
kernelPackages = pkgs.linuxPackages_latest;
kernel.sysctl."vm.max_map_count" = 2147483642;
};
}

View file

@ -0,0 +1,14 @@
{ ... }:
{
imports = [
./boot
./disko
./hardware
../../modules/system
];
system.lanzaboote.enable = true;
system.wireguard.client.enable = false;
networking.hostName = "detritus";
}

View file

@ -0,0 +1,96 @@
{ disko, config, ... }:
{
imports = [ disko.nixosModules.disko ];
disko.devices = {
disk = {
"${config.networking.hostName}" = {
type = "disk";
device = "/dev/sda";
content = {
type = "gpt";
partitions = {
ESP = {
size = "2G";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "umask=0077" ];
};
};
luks = {
size = "100%";
content = {
type = "luks";
name = "${config.networking.hostName}-disk";
settings.allowDiscards = true;
passwordFile = "/tmp/secret.key";
content = {
type = "lvm_pv";
vg = "${config.networking.hostName}";
};
};
};
};
};
};
};
lvm_vg = {
"${config.networking.hostName}" = {
type = "lvm_vg";
lvs = {
root = {
size = "100%";
content = {
type = "btrfs";
extraArgs = [ "-f" ];
subvolumes = {
"/root" = {
mountpoint = "/";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/prev" = {
mountpoint = "/prev";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/nix" = {
mountpoint = "/nix";
mountOptions = [ "compress=zstd" "noatime" ];
};
# Impermanence
"/persist" = {
mountpoint = "/persist";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/persist/.snapshots" = { };
"/jimbo" = {
mountpoint = "/persist/home/jimbo";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/jimbo/.snapshots" = { };
};
};
};
swap = {
size = "8G";
content = {
type = "swap";
discardPolicy = "both";
};
};
};
};
};
};
# Needed for impermanence
fileSystems = {
"/persist".neededForBoot = true;
"/persist/home/jimbo".neededForBoot = true;
};
}

View file

@ -0,0 +1,14 @@
{ config, lib, pkgs, modulesPath, ... }:
{
boot = {
kernelModules = [ "kvm-intel" ];
initrd = {
availableKernelModules = [ "ehci_pci" "ata_piix" "usbhid" "usb_storage" "sd_mod" "sr_mod" ];
kernelModules = [ "dm-snapshot" ];
};
};
networking.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

View file

@ -1,7 +0,0 @@
{ ... }:
{
imports = [
../../../modules/home
../../../modules/home/programs/misc/gaming/launchers
];
}

View file

@ -1,17 +0,0 @@
{ pkgs, ... }:
{
boot = {
kernelPackages = pkgs.linuxPackages_latest;
kernel.sysctl."vm.max_map_count" = 2147483642;
initrd = {
systemd.enable = true;
luks.devices = {
crypt-hhd = {
device = "/dev/disk/by-uuid/0ab46868-3c54-4a19-bf30-93855eac0a86";
preLVM = true;
allowDiscards = true;
};
};
};
};
}

View file

@ -1,26 +0,0 @@
{ ... }:
{
imports = [
./hardware
./boot
# Apps and programs
../../../modules/system
../../../modules/system/accounts
../../../modules/system/desktop
../../../modules/system/programs
../../../modules/system/services
# Devices and hardware
../../../modules/system/devices
../../../modules/system/devices/boot/systemd
../../../modules/system/devices/networking/wireless
../../../modules/system/devices/networking/firewall/pc
# Extras
../../../overlays
../../../variables
];
networking.hostName = "detritus";
}

View file

@ -1,46 +0,0 @@
{ config, lib, pkgs, modulesPath, ... }:
{
boot = {
kernelModules = [ "kvm-intel" ];
initrd = {
availableKernelModules = [ "ehci_pci" "ata_piix" "usbhid" "usb_storage" "sd_mod" "sr_mod" ];
kernelModules = [ "dm-snapshot" ];
};
};
fileSystems = {
"/" = {
device = "/dev/disk/by-uuid/dc6e2cd9-040b-4104-8138-5dfa9cb5558c";
fsType = "btrfs";
options = [ "subvol=@" ];
};
"/home" = {
device = "/dev/disk/by-uuid/dc6e2cd9-040b-4104-8138-5dfa9cb5558c";
fsType = "btrfs";
options = [ "subvol=@home" ];
};
"/nix" = {
device = "/dev/disk/by-uuid/dc6e2cd9-040b-4104-8138-5dfa9cb5558c";
fsType = "btrfs";
options = [ "subvol=@nix" ];
};
"/snapshots" = {
device = "/dev/disk/by-uuid/dc6e2cd9-040b-4104-8138-5dfa9cb5558c";
fsType = "btrfs";
options = [ "subvol=@snapshots" ];
};
"/boot" = {
device = "/dev/disk/by-uuid/C93C-885E";
fsType = "vfat";
options = [ "fmask=0022" "dmask=0022" ];
};
};
swapDevices = [
{ device = "/dev/disk/by-uuid/efbfa333-3971-477c-a0c3-3250a66993a0"; }
];
networking.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

View file

@ -21,12 +21,11 @@ in {
boot = {
# Must be unstable for newest NVIDIA drivers
kernelPackages = pkgs.unstable.linuxPackages_latest;
blacklistedKernelModules = [ "pcspkr" ];
kernel.sysctl."vm.max_map_count" = 2147483642;
kernelParams = commonKernelParams ++ [ "vfio-pci.ids=10de:1f82,10de:10fa" ];
blacklistedKernelModules = [ "pcspkr" ];
initrd = {
systemd = {
initrd.systemd = {
enable = true;
services.root-reset = {
description = "Reset root and snapshot last boot";
@ -57,12 +56,9 @@ in {
};
};
};
};
# Additional entry to boot from the second GPU
specialisation = {
gputwo.configuration = {
specialisation.gputwo.configuration = {
boot.kernelParams = commonKernelParams ++ [ "vfio-pci.ids=10de:2504,10de:228e" ];
};
};
}

View file

@ -17,14 +17,14 @@
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "fmask=0022" "dmask=0022" ];
mountOptions = [ "umask=0077" ];
};
};
luks = {
size = "100%";
content = {
type = "luks";
name = "crypt-nvme";
name = "${config.networking.hostName}-disk";
settings.allowDiscards = true;
passwordFile = "/tmp/secret.key";
content = {

View file

@ -0,0 +1,39 @@
{ pkgs, ... }:
{
boot = {
kernelPackages = pkgs.linuxPackages_latest;
kernel.sysctl."vm.max_map_count" = 2147483642;
initrd = {
systemd = {
enable = true;
services.root-reset = {
description = "Reset root and snapshot last boot";
wantedBy = [ "initrd.target" ];
after = [ "dev-${config.networking.hostName}-root.device" ];
before = [ "sysroot.mount" ];
unitConfig.DefaultDependencies = "no";
serviceConfig.Type = "oneshot";
script = ''
mkdir -p /mnt
mount /dev/${config.networking.hostName}/root /mnt
if [[ -e /mnt/prev ]]; then
btrfs subvolume delete /mnt/prev
fi
btrfs subvolume snapshot /mnt/root /mnt/prev
btrfs subvolume list -o /mnt/root | cut -f9 -d' ' | while read subvolume; do
btrfs subvolume delete "/mnt/$subvolume"
done
btrfs subvolume delete /mnt/root
btrfs subvolume create /mnt/root
umount /mnt
'';
};
};
};
};
}

View file

@ -0,0 +1,96 @@
{ disko, config, ... }:
{
imports = [ disko.nixosModules.disko ];
disko.devices = {
disk = {
"${config.networking.hostName}" = {
type = "disk";
device = "/dev/nvme0n1";
content = {
type = "gpt";
partitions = {
ESP = {
size = "2G";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "fmask=0022" "dmask=0022" ];
};
};
luks = {
size = "100%";
content = {
type = "luks";
name = "crypt-nvme";
settings.allowDiscards = true;
passwordFile = "/tmp/secret.key";
content = {
type = "lvm_pv";
vg = "${config.networking.hostName}";
};
};
};
};
};
};
};
lvm_vg = {
"${config.networking.hostName}" = {
type = "lvm_vg";
lvs = {
root = {
size = "100%";
content = {
type = "btrfs";
extraArgs = [ "-f" ];
subvolumes = {
"/root" = {
mountpoint = "/";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/prev" = {
mountpoint = "/prev";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/nix" = {
mountpoint = "/nix";
mountOptions = [ "compress=zstd" "noatime" ];
};
# Impermanence
"/persist" = {
mountpoint = "/persist";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/persist/.snapshots" = { };
"/jimbo" = {
mountpoint = "/persist/home/jimbo";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/jimbo/.snapshots" = { };
};
};
};
swap = {
size = "8G";
content = {
type = "swap";
discardPolicy = "both";
};
};
};
};
};
};
# Needed for impermanence
fileSystems = {
"/persist".neededForBoot = true;
"/persist/home/jimbo".neededForBoot = true;
};
}

View file

@ -0,0 +1,24 @@
{ config, lib, modulesPath, ... }:
{
boot = {
kernelModules = [ "kvm-intel" ];
initrd = {
availableKernelModules = [ "xhci_pci" "sdhci_pci" ];
kernelModules = [ "dm-snapshot" ];
};
};
fileSystems = {
# Remote
"/home/jimbo/JimboNFS" = {
device = "${config.ips.wgSpan}.1:/export/JimboNFS";
fsType = "nfs4";
options = [ "x-systemd.automount" "_netdev" "nofail" "noauto" ];
};
};
networking.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

View file

@ -1,7 +0,0 @@
{ ... }:
{
imports = [
../../../modules/home
../../../modules/home/programs/misc/remote-desktop
];
}

View file

@ -1,17 +0,0 @@
{ pkgs, ... }:
{
boot = {
kernelPackages = pkgs.linuxPackages_latest;
kernel.sysctl."vm.max_map_count" = 2147483642;
initrd = {
systemd.enable = true;
luks.devices = {
crypt-mmc = {
device = "/dev/disk/by-uuid/5906e176-7ad3-41e5-bc45-ae65664eb10c";
preLVM = true;
allowDiscards = true;
};
};
};
};
}

View file

@ -1,59 +0,0 @@
{ config, lib, modulesPath, ... }:
{
boot = {
kernelModules = [ "kvm-intel" ];
initrd = {
availableKernelModules = [ "xhci_pci" "sdhci_pci" ];
kernelModules = [ "dm-snapshot" ];
};
};
fileSystems = {
"/" = {
device = "/dev/disk/by-uuid/e8c9c5a8-4df0-4100-8de6-f08a1a774fad";
fsType = "btrfs";
options = [ "subvol=@" "noatime" "nodiratime" "discard" ];
};
"/nix" = {
device = "/dev/disk/by-uuid/e8c9c5a8-4df0-4100-8de6-f08a1a774fad";
fsType = "btrfs";
options = [ "subvol=@nix" "noatime" "nodiratime" "discard" ];
};
"/var" = {
device = "/dev/disk/by-uuid/e8c9c5a8-4df0-4100-8de6-f08a1a774fad";
fsType = "btrfs";
options = [ "subvol=@var" "noatime" "nodiratime" "discard" ];
};
"/snapshots" = {
device = "/dev/disk/by-uuid/e8c9c5a8-4df0-4100-8de6-f08a1a774fad";
fsType = "btrfs";
options = [ "subvol=@snapshots" "noatime" "nodiratime" "discard" ];
};
"/home" = {
device = "/dev/disk/by-uuid/e8c9c5a8-4df0-4100-8de6-f08a1a774fad";
fsType = "btrfs";
options = [ "subvol=@home" "noatime" "nodiratime" "discard" ];
};
"/boot" = {
device = "/dev/disk/by-uuid/1C76-1006";
fsType = "vfat";
options = [ "fmask=0022" "dmask=0022" ];
};
# Remote
"/home/jimbo/JimboNFS" = {
device = "${config.ips.wgSpan}.1:/export/JimboNFS";
fsType = "nfs4";
options = [ "x-systemd.automount" "_netdev" "nofail" "noauto" ];
};
};
swapDevices = [
{ device = "/dev/disk/by-uuid/54a9cc22-4a2c-4e04-a968-313c34481489"; }
];
networking.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

View file

@ -1,14 +1,12 @@
{ disko, ... }:
{ disko, config, ... }:
{
imports = [
disko.nixosModules.disko
];
imports = [ disko.nixosModules.disko ];
disko.devices = {
disk = {
main = {
"${config.networking.hostName}" = {
type = "disk";
device = "/dev/sda";
device = "/dev/nvme0n1";
content = {
type = "gpt";
partitions = {
@ -26,12 +24,12 @@
size = "100%";
content = {
type = "luks";
name = "crypt-hdd";
name = "crypt-nvme";
settings.allowDiscards = true;
#passwordFile = "/tmp/secret.key";
passwordFile = "/tmp/secret.key";
content = {
type = "lvm_pv";
vg = "nixos";
vg = "${config.networking.hostName}";
};
};
};
@ -41,7 +39,7 @@
};
lvm_vg = {
nixos = {
"${config.networking.hostName}" = {
type = "lvm_vg";
lvs = {
root = {
@ -50,28 +48,31 @@
type = "btrfs";
extraArgs = [ "-f" ];
subvolumes = {
"/@" = {
"/root" = {
mountpoint = "/";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/@prev" = {
"/prev" = {
mountpoint = "/prev";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/@nix" = {
"/nix" = {
mountpoint = "/nix";
mountOptions = [ "compress=zstd" "noatime" ];
};
# Impermanence
"/@root" = {
"/persist" = {
mountpoint = "/persist";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/@jimbo" = {
"/persist/.snapshots" = { };
"/jimbo" = {
mountpoint = "/persist/home/jimbo";
mountOptions = [ "compress=zstd" "noatime" ];
};
"/jimbo/.snapshots" = { };
};
};
};