From fa4d3d89773682062f7fedcbabd523abb3e9977a Mon Sep 17 00:00:00 2001 From: serenity-F Date: Thu, 26 Sep 2024 16:51:15 +1000 Subject: [PATCH] zfs - hopefully set-up now? --- core/hosts/hades/default.nix | 17 ++++-- .../{hardware.nix => hardware/default.nix} | 33 +++++------- core/hosts/hades/{ => hardware}/disko.nix | 0 core/hosts/hades/hardware/zfs.nix | 54 +++++++++++++++++++ .../{network.nix => network/default.nix} | 0 5 files changed, 82 insertions(+), 22 deletions(-) rename core/hosts/hades/{hardware.nix => hardware/default.nix} (82%) rename core/hosts/hades/{ => hardware}/disko.nix (100%) create mode 100644 core/hosts/hades/hardware/zfs.nix rename core/hosts/hades/{network.nix => network/default.nix} (100%) diff --git a/core/hosts/hades/default.nix b/core/hosts/hades/default.nix index 68dc354..c1330f1 100644 --- a/core/hosts/hades/default.nix +++ b/core/hosts/hades/default.nix @@ -2,22 +2,33 @@ { imports = [ - ## Include the results of the hardware scan. + + ## Import necessary flake modules + #"${builtins.fetchTarball ""}/module.nix" + + ## Include host specific options ./hardware.nix - #"${builtins.fetchTarball "https://github.com/nix-community/disko/archive/master.tar.gz"}/module.nix" ./network.nix + + ## Include core config options ../../config.nix ]; nix = { + #settings = { #}; + gc = { - ## Every day, automatically collect garbage older than 10 days + ## Automatically run 'nix-collect-garbage', automatic = true; + ## every day, dates = "daily"; + ## and clear junk older than 3 days options = "--delete-older-than 3d"; + + ## No clue what this does lol. persistent = true; }; }; diff --git a/core/hosts/hades/hardware.nix b/core/hosts/hades/hardware/default.nix similarity index 82% rename from core/hosts/hades/hardware.nix rename to core/hosts/hades/hardware/default.nix index 361901f..f531729 100644 --- a/core/hosts/hades/hardware.nix +++ b/core/hosts/hades/hardware/default.nix @@ -1,24 +1,15 @@ { config, lib, pkgs, modulesPath, ... }: -let - latestZfsCompatibleLinuxPackages = lib.pipe pkgs.linuxKernel.packages [ - builtins.attrValues - (builtins.filter ( - kPkgs: - (builtins.tryEval kPkgs).success - && kPkgs ? kernel - && kPkgs.kernel.pname == "linux" - && !kPkgs.zfs.meta.broken - )) - (builtins.sort (a: b: (lib.versionOlder a.kernel.version b.kernel.version))) - lib.last - ]; -in - { imports = [ + + ## Import necessary flake modules + #"${builtins.fetchTarball "https://github.com/nix-community/disko/archive/master.tar.gz"}/module.nix" + + ## Include results from the (non-existent) hardware scan + ## as well as the host-specific hardware config options (modulesPath + "/installer/scan/not-detected.nix") - ## Commented out disko for now as I have broken it :c + ## Disko commented out for now as we have "broken" it #./disko.nix ]; @@ -32,9 +23,9 @@ in ## Enable swap on luks boot = { - kernelPackages = latestZfsCompatibleLinuxPackages; kernelModules = [ "kvm-intel" ]; extraModulePackages = [ ]; + supportedFilesystems = [ "btrfs" "xfs" "ntfs" ]; initrd = { availableKernelModules = [ "xhci_pci" "ehci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" ]; kernelModules = [ ]; @@ -64,8 +55,12 @@ in }; - ## Trim to keep SSDs healthy-ish - services.fstrim.enable = true; + ## Hardware-related services + services = { + ## TRIM to keep SSDs healthy-ish + fstrim.enable = true; + + }; #powerManagement = { #enable = true; diff --git a/core/hosts/hades/disko.nix b/core/hosts/hades/hardware/disko.nix similarity index 100% rename from core/hosts/hades/disko.nix rename to core/hosts/hades/hardware/disko.nix diff --git a/core/hosts/hades/hardware/zfs.nix b/core/hosts/hades/hardware/zfs.nix new file mode 100644 index 0000000..0fd154c --- /dev/null +++ b/core/hosts/hades/hardware/zfs.nix @@ -0,0 +1,54 @@ +## ZFS Support NixOS module + +## temporary location while we figure out how ZFS works, +## eventually this will be embedded into the flake in a better way + +{ config, lib, pkgs, ... }: + +let + ## This 'let' binding creates an attribute set + ## called "LatestZfsLinux", which we can call as + ## a package to specify when building our kernel. + latestZfsLinux = lib.pipe pkgs.linuxKernel.packages [ + builtins.attrValues + (builtins.filter ( + kPkgs: + (builtins.tryEval kPkgs).success + && kPkgs ? kernel + && kPkgs.kernel.pname == "linux" + && !kPkgs.zfs.meta.broken + )) + (builtins.sort (a: b: (lib.versionOlder a.kernel.version b.kernel.version))) + lib.last + ]; +in + +{ + + imports = [ + ]; + + ## Enable zfs in kernel and boot + boot = { + kernelPackages = latestZfsLinux; + supportedFilesystems = [ "zfs" ]; + zfs = { + #extraPools = [ "diska" "diskb" ]; + forceImportRoot = false; + }; + }; + + ## Enable trim for ZFS SSDs + services = { + zfs = { + ## Trim for SSSds with ZFS + trim.enable = true; + ## Autoscrub data integrity ZFS service, + ## more to be added soon + autoScrub = { + enable = true; + }; + }; + }; + +} diff --git a/core/hosts/hades/network.nix b/core/hosts/hades/network/default.nix similarity index 100% rename from core/hosts/hades/network.nix rename to core/hosts/hades/network/default.nix