From 4e105478ce2591aeb27369f13ee0a37b80954ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 20 Sep 2024 18:38:53 +0200 Subject: [PATCH 1/2] installer: add our own latestZfsCompatibleLinuxPackages --- flake.lock | 6 +++--- nix/installer.nix | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/flake.lock b/flake.lock index 05c8579..9aa2c24 100644 --- a/flake.lock +++ b/flake.lock @@ -18,11 +18,11 @@ }, "nixos-unstable": { "locked": { - "lastModified": 1726658796, - "narHash": "sha256-SiiWCVg/W8i6jvpgQj3NNd3YtV+jfnn/t3Za7hfn1iE=", + "lastModified": 1726798147, + "narHash": "sha256-k/Ojv+MUDKUbj8JPd1MulJrf5BVz3jIUfrreMHbeTBE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "75ac2a58e988a346960938ab16cea903a3cb053a", + "rev": "e88358265511d3a73b30dc6e4c15579844b35280", "type": "github" }, "original": { diff --git a/nix/installer.nix b/nix/installer.nix index 740567a..14b2b42 100644 --- a/nix/installer.nix +++ b/nix/installer.nix @@ -4,6 +4,14 @@ pkgs, ... }: +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 { # more descriptive hostname than just "nixos" networking.hostName = lib.mkDefault "nixos-installer"; @@ -16,7 +24,7 @@ # use latest kernel we can support to get more hardware support boot.zfs.package = pkgs.zfsUnstable; - boot.kernelPackages = pkgs.zfsUnstable.latestCompatibleLinuxPackages; + boot.kernelPackages = latestZfsCompatibleLinuxPackages; documentation.enable = false; documentation.man.man-db.enable = false; From 4de5aac8e9b8d8b839b0eaee61a893a41f0b968f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 22 Sep 2024 17:56:58 +0200 Subject: [PATCH 2/2] improve selecting latest zfs kernel --- nix/installer.nix | 17 ++++------------- nix/latest-zfs-kernel.nix | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 nix/latest-zfs-kernel.nix diff --git a/nix/installer.nix b/nix/installer.nix index 14b2b42..3423b3a 100644 --- a/nix/installer.nix +++ b/nix/installer.nix @@ -4,15 +4,11 @@ pkgs, ... }: -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 = [ + ./latest-zfs-kernel.nix + ./nix-settings.nix + ]; # more descriptive hostname than just "nixos" networking.hostName = lib.mkDefault "nixos-installer"; @@ -24,7 +20,6 @@ in # use latest kernel we can support to get more hardware support boot.zfs.package = pkgs.zfsUnstable; - boot.kernelPackages = latestZfsCompatibleLinuxPackages; documentation.enable = false; documentation.man.man-db.enable = false; @@ -41,10 +36,6 @@ in # alternative to nixos-generate-config ] ++ lib.optional (pkgs.lib.versionAtLeast lib.version "24.11") pkgs.nixos-facter; - imports = [ - ./nix-settings.nix - ]; - # Don't add nixpkgs to the image to save space, for our intended use case we don't need it system.installer.channel.enable = false; } diff --git a/nix/latest-zfs-kernel.nix b/nix/latest-zfs-kernel.nix new file mode 100644 index 0000000..0bc8041 --- /dev/null +++ b/nix/latest-zfs-kernel.nix @@ -0,0 +1,26 @@ +{ + lib, + pkgs, + config, + ... +}: + +let + isUnstable = config.boot.zfs.package == pkgs.zfsUnstable; + zfsCompatibleKernelPackages = lib.filterAttrs ( + name: kernelPackages: + (builtins.match "linux_[0-9]+_[0-9]+" name) != null + && (builtins.tryEval kernelPackages).success + && ( + (!isUnstable && !kernelPackages.zfs.meta.broken) + || (isUnstable && !kernelPackages.zfs_unstable.meta.broken) + ) + ) pkgs.linuxKernel.packages; + latestKernelPackage = lib.last ( + lib.sort (a: b: (lib.versionOlder a.kernel.version b.kernel.version)) (builtins.attrValues zfsCompatibleKernelPackages) + ); +in +{ + # Note this might jump back and worth as kernel get added or removed. + boot.kernelPackages = latestKernelPackage; +}