diff --git a/nixos/doc/manual/configuration/linux-kernel.chapter.md b/nixos/doc/manual/configuration/linux-kernel.chapter.md index 4aeda5f46764e..9b880c80b2c7c 100644 --- a/nixos/doc/manual/configuration/linux-kernel.chapter.md +++ b/nixos/doc/manual/configuration/linux-kernel.chapter.md @@ -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. +::: diff --git a/nixos/modules/tasks/filesystems/zfs.nix b/nixos/modules/tasks/filesystems/zfs.nix index 87876867c5729..035ead43b567a 100644 --- a/nixos/modules/tasks/filesystems/zfs.nix +++ b/nixos/modules/tasks/filesystems/zfs.nix @@ -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; diff --git a/pkgs/os-specific/linux/zfs/generic.nix b/pkgs/os-specific/linux/zfs/generic.nix index d267de0eb175a..b5d4b5df2d044 100644 --- a/pkgs/os-specific/linux/zfs/generic.nix +++ b/pkgs/os-specific/linux/zfs/generic.nix @@ -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: @@ -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; @@ -243,6 +269,6 @@ let mainProgram = "zfs"; broken = buildKernel && (kernelCompatible != null) && !(kernelCompatible kernel); }; - }; + }); in genericBuild