Skip to content

Commit

Permalink
zfs: warnIf kernel is not LTS
Browse files Browse the repository at this point in the history
The lack of swift support for new kernels in OpenZFS has been a pain point for
many years and there is no sign of the situation changing any time soon.

This has lead to the creation of the fundamentally flawed
zfs.latestCompatibleLinuxPackages and created friction when removing EOL and
massively insecure kernels from Nixpkgs because users are forced to rely on them
for ZFS
support (https://discourse.nixos.org/t/aggressive-kernel-removal-on-eol-in-nixos/23097/).

To prevent users from unknowingly running into this issue, this commit adds an
eval warning, informing the user that what they're doing is very likely to cause
issues down the line and that they will receive no support from us when that
happens.

This effectively deprecates usage of the ZFS package with non-LTS kernels.

A new override option is introduced to disable the warning should the user
choose to ignore it as to not annoy them.

This trace warning could be upgraded to a throw/assert if it does not show the
desired effect on users.

I'd have preferred to have this warning only appear after e.g. broken checks but
I couldn't think of a good way of implementing that.

The idea to add this warning is the result of a discussion at the 2024-12-02
Darmstadt NixOS Meetup between ma27 (Linux kernel package maintainer), hexa,
maralorn, a few further ZFS users and yours truly but no ZFS maintainer has been
involved until proposing these patches.

I myself do not use ZFS anymore (in part due to the lack of upstream support for
new kernels) nor maintain it. I have made extensive use of it before though and
have seen enough ZFS users run into trap.
  • Loading branch information
Atemu committed Dec 6, 2024
1 parent 4eeb706 commit 084db74
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
5 changes: 5 additions & 0 deletions nixos/doc/manual/configuration/linux-kernel.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,8 @@ This section was moved to the [Nixpkgs manual](https://nixos.org/nixpkgs/manual#
It's a common issue that the latest stable version of ZFS doesn't support the latest
available Linux kernel. It is recommended to use the latest available LTS that's compatible
with ZFS. Usually this is the default kernel provided by nixpkgs (i.e. `pkgs.linuxPackages`).

:::{.note}
Using non-LTS releases with ZFS is likely to leave you in a situation where you are unable to update because it doesn't support any up-to-date kernel.
NixOS will show an eval warning which further elaborates this issue aswell as how to turn the warning off should you choose to ignore it.
:::
13 changes: 13 additions & 0 deletions nixos/modules/tasks/filesystems/zfs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,23 @@ in
modulePackage = lib.mkOption {
internal = true; # It is supposed to be selected automatically, but can be overridden by expert users.
default = selectModulePackage cfgZfs.package;
apply = pkg: pkg.override { inherit (cfgZfs) allowNonLTSKernels; };
type = lib.types.package;
description = "Configured ZFS kernel module package.";
};

allowNonLTSKernels = lib.mkEnableOption ''
usage of ZFS with non-LTS kernels that are likely to become
incompatible, preventing you from updating the system until you switch
to an LTS kernel.
Please see the evaluation warning of the ZFS package for more
information. If you have never seen such a warning, this option very
likely doesn't apply to you.
This option suppresses the warning in case you chose to ignore it.
'';

enabled = lib.mkOption {
readOnly = true;
type = lib.types.bool;
Expand Down
30 changes: 28 additions & 2 deletions pkgs/os-specific/linux/zfs/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ let
, extraPatches ? []
, rev ? "zfs-${version}"
, kernelCompatible ? null
, allowNonLTSKernels ? false # Whether to allow usage with unsupported kernels
, maintainers ? (with lib.maintainers; [ amarshall ])
, tests
}@innerArgs:
Expand All @@ -50,9 +51,34 @@ let
# If you don't do this your ZFS builds will fail on any non-standard (e.g.
# clang-built) kernels.
stdenv' = if kernel == null then stdenv else kernel.stdenv;

isLTS = kernel.passthru.isLTS or false;
in

stdenv'.mkDerivation {
lib.warnIf (!(buildKernel -> !isLTS -> allowNonLTSKernels)) ''
You are using the ZFS kernel module in combination with a non-LTS kernel:
${kernel.modDirVersion}
Because the development cycles of OpenZFS and the Linux kernel do not line
up, it is likely that any given kernel that is not an LTS release will go
EOL (and will therefore be removed from Nixpkgs) before an OpenZFS release
is available that supports the (at that time) latest non-LTS kernel.
When that happens, you will *no longer be able to update* and NixOS/Nixpkgs
maintainers will not be able to help you, unless you downgrade to an LTS
kernel (e.g. `pkgs.linuxPackages`).
To avoid this situation it is recommended that you only use ZFS with an LTS
kernel.
See https://www.kernel.org/ for more information on LTS kernel releases.
If you are willing to risk running into the described issue, this warning
can be suppressed using `boot.zfs.allowNonLTSKernels = true`.
''

(stdenv'.mkDerivation {
name = "zfs-${configFile}-${version}${optionalString buildKernel "-${kernel.version}"}";
pname = "zfs";
inherit version;
Expand Down Expand Up @@ -243,6 +269,6 @@ let
mainProgram = "zfs";
broken = buildKernel && (kernelCompatible != null) && !(kernelCompatible kernel);
};
};
});
in
genericBuild

0 comments on commit 084db74

Please sign in to comment.