From 69232abb6c0b44bdeec3bd5143fc1ddceecf481d Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 12 Mar 2026 23:38:13 +0000 Subject: [PATCH] Refactoring --- flake.nix | 3 +- hardware/default.nix | 4 +- hardware/disko.nix | 95 ++++++++++--------- .../filesystem.nix | 40 ++++---- .../stationette-hardware-configuration.nix | 16 ++++ home/impermanence.nix | 1 + home/packages.nix | 4 +- home/programs.nix | 7 +- hosts/station/hardware-configuration.nix | 15 --- system/boot.nix | 19 +++- system/fonts.nix | 2 +- system/impermanence.nix | 13 +-- system/users.nix | 4 +- 13 files changed, 117 insertions(+), 106 deletions(-) rename hosts/stationette/hardware-configuration.nix => hardware/filesystem.nix (56%) create mode 100644 hardware/stationette-hardware-configuration.nix delete mode 100644 hosts/station/hardware-configuration.nix diff --git a/flake.nix b/flake.nix index 3498a40..ae02ce4 100644 --- a/flake.nix +++ b/flake.nix @@ -57,8 +57,7 @@ mkHost = hostname: nixpkgs.lib.nixosSystem { modules = [ - ./hosts/${hostname}/hardware-configuration.nix - ./hosts/${hostname}/disko.nix + ./hardware ./system home-manager.nixosModules.home-manager { diff --git a/hardware/default.nix b/hardware/default.nix index 4d20401..3bf3e59 100644 --- a/hardware/default.nix +++ b/hardware/default.nix @@ -1,7 +1,9 @@ -{ ... }: +{ hostname, ... }: { imports = [ ./disko.nix + ./filesystem.nix + ./${hostname}-hardware-configuration.nix ]; } diff --git a/hardware/disko.nix b/hardware/disko.nix index 72bdc6d..127dedb 100644 --- a/hardware/disko.nix +++ b/hardware/disko.nix @@ -1,56 +1,61 @@ { disko, ... }: -# nix --extra-experimental-features "nix-command flakes" run github:nix-community/disko/latest#disko-install -- --flake ./#stationette --disk stationette --write-efi-boot-entries /dev/sda -{ - imports = [ disko.nixosModules.disko ]; - disko.devices = { - disk = { - stationette = { - type = "disk"; -# Check this with lsblk - device = "/dev/sda"; +let +mkDisk = { hostname, drive }: { + type = "disk"; + # Check this with lsblk + device = drive; + content = { + type = "gpt"; + partitions = { + ESP = { + size = "512M"; + type = "EF00"; content = { - type = "gpt"; - partitions = { - ESP = { - size = "512M"; - type = "EF00"; - content = { - type = "filesystem"; - format = "vfat"; - mountpoint = "/boot"; - mountOptions = [ "fmask=0022" "dmask=0022" "umask=0077" ]; - }; + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ "fmask=0022" "dmask=0022" "umask=0077" ]; + }; + }; + root = { + size = "100%"; + content = { + type = "btrfs"; + # Force overwrite + extraArgs = [ "-f" ]; + subvolumes = { + "/root" = { + mountpoint = "/"; + mountOptions = [ "compress=zstd" "noatime" ]; }; - root = { - size = "100%"; - content = { - type = "btrfs"; -# Force overwrite - extraArgs = [ "-f" ]; - subvolumes = { - "/root" = { - mountpoint = "/"; - mountOptions = [ "compress=zstd" "noatime" ]; - }; - "/nix" = { - mountpoint = "/nix"; - mountOptions = [ "compress=zstd" "noatime" ]; - }; - "/persist" = { - mountpoint = "/persist"; - mountOptions = [ "compress=zstd" "noatime" ]; - }; - "/swap" = { - mountpoint = "/.swapvol"; - swap.swapfile.size = "8G"; - }; - }; - }; + "/nix" = { + mountpoint = "/nix"; + mountOptions = [ "compress=zstd" "noatime" ]; + }; + "/persist" = { + mountpoint = "/persist"; + mountOptions = [ "compress=zstd" "noatime" ]; + }; + "/swap" = { + mountpoint = "/.swapvol"; + swap.swapfile.size = "8G"; }; }; }; }; }; }; +}; +in + +# nix --extra-experimental-features "nix-command flakes" run github:nix-community/disko/latest#disko-install -- --flake ./#${hostname} --disk stationette --write-efi-boot-entries ${drive} +{ + imports = [ disko.nixosModules.disko ]; + disko.devices = { + disk = { + station = mkDisk { hostname = "station"; drive = "/dev/nvme0n1"; }; + stationette= mkDisk { hostname = "stationette"; drive = "/dev/sda"; }; + }; + }; } diff --git a/hosts/stationette/hardware-configuration.nix b/hardware/filesystem.nix similarity index 56% rename from hosts/stationette/hardware-configuration.nix rename to hardware/filesystem.nix index 6790eaa..af08655 100644 --- a/hosts/stationette/hardware-configuration.nix +++ b/hardware/filesystem.nix @@ -1,25 +1,14 @@ -# Do not modify this file! It was generated by ‘nixos-generate-config’ -# and may be overwritten by future invocations. Please make changes -# to /etc/nixos/configuration.nix instead. -{ config, lib, pkgs, modulesPath, ... }: +{ config, lib, pkgs, modulesPath, hostname, ... }: + +let +rootDisk = "/dev/disk/by-partlabel/disk-${hostname}-root"; +bootDisk = "/dev/disk/by-partlabel/disk-${hostname}-ESP"; +in { - imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; - - boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "sd_mod" "sdhci_pci" ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-intel" ]; - boot.extraModulePackages = [ ]; - - fileSystems."/" = { - device = "/dev/disk/by-partlabel/disk-stationette-root"; - fsType = "btrfs"; - options = [ "subvol=root" ]; - }; - boot.initrd.postDeviceCommands = lib.mkAfter '' mkdir /btrfs_tmp - mount /dev/disk/by-partlabel/disk-stationette-root /btrfs_tmp + mount ${rootDisk} /btrfs_tmp if [[ -e /btrfs_tmp/root ]]; then mkdir -p /btrfs_tmp/old_roots timestamp=$(date +%Y-%m-%d_%H-%M-%S) @@ -42,22 +31,28 @@ umount /btrfs_tmp ''; + fileSystems."/" = { + device = rootDisk; + fsType = "btrfs"; + options = [ "subvol=root" ]; + }; + fileSystems."/persist" = { - device = "/dev/disk/by-partlabel/disk-stationette-root"; + device = rootDisk; neededForBoot = true; fsType = "btrfs"; options = [ "subvol=persist" ]; }; fileSystems."/nix" = { - device = "/dev/disk/by-partlabel/disk-stationette-root"; + device = rootDisk; neededForBoot = true; fsType = "btrfs"; options = [ "subvol=nix" ]; }; fileSystems."/boot" = { - device = "/dev/disk/by-partlabel/disk-stationette-ESP"; + device = bootDisk; fsType = "vfat"; options = [ "fmask=0022" "dmask=0022" "umask=0077" ]; }; @@ -65,7 +60,4 @@ swapDevices = [ { device = "/.swapvol/swapfile"; } ]; - - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; - hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; } diff --git a/hardware/stationette-hardware-configuration.nix b/hardware/stationette-hardware-configuration.nix new file mode 100644 index 0000000..2e41585 --- /dev/null +++ b/hardware/stationette-hardware-configuration.nix @@ -0,0 +1,16 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; + + boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "sd_mod" "sdhci_pci" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/home/impermanence.nix b/home/impermanence.nix index c775657..870e1be 100644 --- a/home/impermanence.nix +++ b/home/impermanence.nix @@ -16,6 +16,7 @@ ".config/nixos" ".config/sinew.in" ".config/chromium" + ".config/superProductivity" ".local/share/direnv" ".local/share/nvim" ".local/share/voxtype" diff --git a/home/packages.nix b/home/packages.nix index 9fbf93e..e1883ae 100644 --- a/home/packages.nix +++ b/home/packages.nix @@ -8,7 +8,7 @@ permittedInsecurePackages = [ "electron-25.9.0" # Obsidian - "beekeeper-studio-5.3.4" + "beekeeper-studio-5.3.4" ]; }; }; @@ -37,12 +37,14 @@ obsidian # Notes software signal-desktop # Messaging spotify # Music + super-productivity # Task app sxiv # Minimal image viewer tenacity # Audio software try-cli.packages.${pkgs.system}.default # Try CLI tool wally-cli # Keyboard flasher wiremix # Audio mixer TUI xournalpp # Handwriting note-taking software + zenity # For creating dialogs during install script zathura # Minimal PDF viewer ]; } diff --git a/home/programs.nix b/home/programs.nix index fa0e9f5..6dae6fe 100644 --- a/home/programs.nix +++ b/home/programs.nix @@ -32,8 +32,8 @@ chromium = { enable = true; extensions = [ - "cjpalhdlnbpafiamejdnhcphjbkeiagm" - "kmcfomidfpdkfieipokbalgegidffkal" + "cjpalhdlnbpafiamejdnhcphjbkeiagm" # uBlock Origin + "kmcfomidfpdkfieipokbalgegidffkal" # Enpass ]; }; firefox = { @@ -62,7 +62,7 @@ /* ---- EXTENSIONS ---- */ ExtensionSettings = { "*".installation_mode = "allowed"; # blocks all addons except the ones specified below -# Enpass + # Enpass "firefox-enpass@enpass.io" = { install_url = "https://dl.enpass.io/stable/extensions/firefox/versions/v6.11.10.2/enpass_password_manager-6.11.10.2.xpi"; installation_mode = "force_installed"; @@ -70,7 +70,6 @@ }; /* ---- PREFERENCES ---- */ -# Set preferences shared by all profiles. Preferences = { "browser.contentblocking.category" = { Value = "strict"; Status = "locked"; }; "extensions.pocket.enabled" = lock-false; diff --git a/hosts/station/hardware-configuration.nix b/hosts/station/hardware-configuration.nix deleted file mode 100644 index b07f2a6..0000000 --- a/hosts/station/hardware-configuration.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ config, lib, pkgs, modulesPath, ... }: - -{ - imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; - - fileSystems."/persist" = { - device = "/dev/disk/by-partlabel/disk-station-root"; - neededForBoot = true; - fsType = "btrfs"; - options = [ "subvol=persist" ]; - }; - - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; - hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; -} diff --git a/system/boot.nix b/system/boot.nix index f61bcb3..7abc75d 100644 --- a/system/boot.nix +++ b/system/boot.nix @@ -1,5 +1,14 @@ { pkgs, hostname, ... }: +let +# Found by running sudo btrfs inspect-internal map-swapfile -r /.swapvol/swapfile +hibernateBootOffsets = { + stationette = "533760"; + station = "533760"; +}; + +resumeOffset = hibernateBootOffsets."${hostname}" or "0"; +in { boot = { loader = { @@ -26,22 +35,22 @@ ''; }; efi.canTouchEfiVariables = true; - # timeout = 0; + # timeout = 0; # Skips the menu and uses default entry }; + # Creates a cool animation for booting plymouth = { enable = true; theme = "black_hud"; themePackages = with pkgs; [ (adi1090x-plymouth-themes.override { - selected_themes = [ "black_hud" ]; - }) + selected_themes = [ "black_hud" ]; + }) ]; }; initrd.verbose = false; -# Found by running sudo btrfs inspect-internal map-swapfile -r /.swapvol/swapfile kernelParams = [ - "resume_offset=533760" + "resume_offset=${hibernateBootOffset}" "quiet" "udev.log_level=3" "systemd.show_status=auto" diff --git a/system/fonts.nix b/system/fonts.nix index 6822524..6344ddc 100644 --- a/system/fonts.nix +++ b/system/fonts.nix @@ -4,7 +4,7 @@ fonts = { packages = with pkgs; [ nerd-fonts.jetbrains-mono - nerd-fonts.fira-code + nerd-fonts.fira-code ]; }; } diff --git a/system/impermanence.nix b/system/impermanence.nix index ca76c7d..13b5ba8 100644 --- a/system/impermanence.nix +++ b/system/impermanence.nix @@ -1,5 +1,6 @@ { impermanence, ... }: +# Define which files and directories should persist between boots { imports = [ impermanence.nixosModules.impermanence ]; @@ -7,12 +8,12 @@ hideMounts = true; directories = [ "/var/log" - "/var/lib/bluetooth" - "/var/lib/networkmanager" - "/var/lib/nixos" - "/etc/ssh" - "/var/lib/systemd/coredump" - "/etc/NetworkManager/system-connections" + "/var/lib/bluetooth" + "/var/lib/networkmanager" + "/var/lib/nixos" + "/var/lib/systemd/coredump" + "/etc/NetworkManager/system-connections" + "/etc/ssh" ]; files = [ "/etc/machine-id" diff --git a/system/users.nix b/system/users.nix index 5551eca..f9b8d76 100644 --- a/system/users.nix +++ b/system/users.nix @@ -8,8 +8,8 @@ shell = pkgs.zsh; extraGroups = [ "chris" - "wheel" - "networkmanager" + "wheel" + "networkmanager" ]; }; }