Attempt to make ZFS work with custom installer image

This commit is contained in:
Vili Sinervä 2025-07-24 12:28:46 +03:00
parent 3f660b0349
commit 32479e136f
Signed by: Vili Sinervä
SSH key fingerprint: SHA256:FladqYjaE4scJY3Hi+gnShZ6ygnTJgixy0I6BAoHyos

View file

@ -1,12 +1,51 @@
{ nixpkgs-flake, lib, ... }:
{
config,
nixpkgs-flake,
lib,
pkgs,
...
}:
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
)
);
zfs = pkgs.zfsUnstable.override {
# this overrides saves 10MB
samba = pkgs.coreutils;
python3 = pkgs.python3Minimal;
};
in
{
imports = [
"${nixpkgs-flake}/nixos/modules/installer/cd-dvd/installation-cd-graphical-combined.nix"
];
# This block copied from https://github.com/nix-community/nixos-images
boot.zfs.package = pkgs.zfsUnstable;
services.udev.packages = [ zfs ]; # to hook zvol naming, etc.
# unsure if need this, but in future udev rules could potentially point to systemd services.
systemd.packages = [ zfs ];
environment.defaultPackages = lib.mkForce [ zfs ]; # this merges with outer noninteractive module.
boot.kernelModules = [ "zfs" ];
boot.extraModulePackages = [ config.boot.kernelPackages.zfs_unstable ];
boot.kernelPackages = latestKernelPackage;
custom.services.nixCacheClient.enable = true;
boot.supportedFilesystems.zfs = lib.mkForce true;
services.qemuGuest.enable = true;
isoImage.squashfsCompression = "gzip -Xcompression-level 1";
system.installer.channel.enable = false;
isoImage.squashfsCompression = "zstd";
networking.wireless.enable = false;
}