diff --git a/modules/features/programs/zfs.nix b/modules/features/programs/zfs.nix new file mode 100644 index 0000000..761c7f7 --- /dev/null +++ b/modules/features/programs/zfs.nix @@ -0,0 +1,56 @@ +{ self, inputs, ... }: + +{ + + flake.nixosModules.zfs-support = + { + config, + lib, + pkgs, + ... + }: + + let + + # matches kernel to latest with zfs support + # Black magic wizardry from https://wiki.nixos.org/wiki/ZFS + zfsCompatibleKernelPackages = lib.filterAttrs ( + name: kernelPackages: + (builtins.match "linux_[0-9]+_[0-9]+" name) != null + && (builtins.tryEval kernelPackages).success + && (!kernelPackages.${config.boot.zfs.package.kernelModuleAttribute}.meta.broken) + ) pkgs.linuxKernel.packages; + latestKernelPackage = lib.last ( + lib.sort (a: b: (lib.versionOlder a.kernel.version b.kernel.version)) ( + builtins.attrValues zfsCompatibleKernelPackages + ) + ); + + in + + { + imports = [ inputs.home-manager.nixosModules.home-manager ]; + + boot = { + # sets system to use latest zfs compatible kernel + kernelPackages = lib.mkForce latestKernelPackage; + # adds zfs support at boot + supportedFilesystems = [ "zfs" ]; + + # imports zfs pools on host device + zfs = { + extraPools = [ "orcus" ]; + forceImportRoot = false; + }; + }; + + # adds zfs to system packages + environment.systemPackages = with pkgs; [ zfs ]; + + # is this needed? + #networking.hostId = "603b0c8b"; + + # data integrity service + services.zfs.autoScrub = true; + }; +} diff --git a/modules/hosts/hades/default.nix b/modules/hosts/hades/default.nix index 70dadf7..0ff5f5b 100644 --- a/modules/hosts/hades/default.nix +++ b/modules/hosts/hades/default.nix @@ -20,6 +20,7 @@ terminal desktop #multimedia + zfs gaming music music-production