Nixops: deploy custom kernel module

I’m still fairly new to NixOS and nixops. Currently I’m running NixOS on my laptop and enjoying it. Now I’m trying to use nixops to test some zfs changes in a VM. I’ve got an overlay that seems to work to build the zfs kernel module and user package on its own when I run nix build. But when I put it in nixops, I’m getting an error. It may be related to Nixops issue #893, but I’m unable to figure it out, and my hunch is I’m missing something pretty simple. Here’s my nixops output:

nixops deploy -d zfs
building all machine configurations...
error: attribute 'extend' missing, at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/system/boot/kernel.nix:39:31
(use '--show-trace' to show detailed location information)
error: unable to build all machine configurations

Here’s the “logical” part of my nixops config:

{
  network.description = "zfs test";

  zfstest =
    { config, pkgs, ... }:
    { 
       boot.zfs.enableUnstable = true;
       boot.supportedFilesystems = [ "zfs" ];
       boot.kernelPackages = pkgs.linuxPackages_4_15;
       
        nixpkgs.overlays = [(
          self: super:
          {
            zfsUnstable = super.zfsUnstable.overrideAttrs (oldAttrs : {
              
              src = super.fetchFromGitHub {
          
                owner = "rbrewer123";
                repo = "zfs";
                
                #rev = "b4555c777a0be3c0dba29662d278c57099c60a87";
                #sha256 = "03k1maiz70jbk45619yqcf3larhvgilaxnvkid3972knm7ycgjsh";
                rev = "de4a0c31b5d269e39114181465ddbba448a4db3f";
                sha256 = "0ghpn9lsjdpx2qh4wk48vdd22sa1qv4hw49m0p4lv6ap5h14bx0v";
              };
          
            });
          
            linuxPackages_4_15.zfsUnstable = super.linuxPackages_4_15.zfsUnstable.overrideAttrs (oldAttrs : {
              
              src = super.fetchFromGitHub {
          
                owner = "rbrewer123";
                repo = "zfs";
                
                #rev = "b4555c777a0be3c0dba29662d278c57099c60a87";
                #sha256 = "03k1maiz70jbk45619yqcf3larhvgilaxnvkid3972knm7ycgjsh";
                rev = "de4a0c31b5d269e39114181465ddbba448a4db3f";
                sha256 = "0ghpn9lsjdpx2qh4wk48vdd22sa1qv4hw49m0p4lv6ap5h14bx0v";
              };
          
            });
          
          }
          )];
    };
}

Does anyone have any ideas what’s wrong?

By setting linuxPackages_4_15.zfsUnstable you’re creating a new set for linuxPackages_4_15 containing nothing but zfsUnstable. You’ll need to use the (unfortunately more verbose)

    linuxPackages_4_15 = super.linuxPackages_4_15 // {
      zfsUnstable = super.linuxPackages_4_15.overrideAttrs (…)
    };
1 Like

Thanks, that got me much further along. It looked like it built the module. However, I think the resulting VM is running the stock zfs unstable without my changes. I’m expecting the hash in the package name to match the one I get when I build the zfs kernel module separately without nixops. Is there still something I need to do with assigning boot.kernelPackages or the nixpkgs.overlays line?

I think we should make it more configurable what zfs packages to use. nixpkgs/zfs.nix at master · NixOS/nixpkgs · GitHub

I have seen it more then once that people try to set a custom zfs version.

More configurable sounds fine, but I’d still like to understand if my overlay is wrong or if there’s a problem somewhere else in the chain.

My change to zfs is subtle, so I’ll try testing with a more explicit change to know for sure if the overlay deployed the expected code.

You could insert a traceVal where the zfs module selects the zfs kernel module and see if the path matches without overlay value. You could add also add it to environment.systemPackages and add the lib.traceVal function to dump the path.