No more `.dev` on latest kernels?

I’m trying to adapt the gist from droidcam.nix · GitHub that installs droidcam to work on arbitrary kernels (I don’t like this pinning on kernel 4.9), so I tried to import from my configuration.nix the following file (the other nix files being the one from the gist):

{ config, pkgs, lib, ... }:
# Gist from https://gist.github.com/gtgteq/a3bae1c09c95196f6e2a767d08f62ad8
let v4l2loopback-dc = pkgs.callPackage ./v4l2loopback-dc.nix {
      kernel = config.boot.kernelPackages;
    };
    droidcam = pkgs.callPackage ./droidcam.nix {};
in {
  boot.extraModulePackages = [ v4l2loopback-dc ];
  environment.systemPackages = [ droidcam ];
}

However it fails with an error:

error: --- EvalError ------------------------------------------------------------------------------------- nix-build
at: (15:19) in file: /etc/nixos/v4l2loopback-dc.nix

    14|   KVER = "${kernel.modDirVersion}";
    15|   KBUILD_DIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
      |                   ^
    16| 

attribute 'dev' missing

I also tried to replace the kernel = ... with kernel = pkgs.linuxPackages_latest;, but the error is the same. Why don’t the new kernels have a .dev attribute? How can I fix this code accordingly?

Thanks!

1 Like

Oh, it seems that the solution is simply to use instead kernel = config.boot.kernelPackages.kernel; (see the leading .kernel). However, I’m not sure if it’s the proper way to configure kernelPackages, as I can’t see lot’s of packages having that structure in nixpkgs. Is there a better way to define a kernel module?

assuming you don’t need this for stage1 boot

change

to:

  boot.kernelModules = [ "v4l2loopback-dc" ];

and it should work.

If you wanted to override the actual module with a different version, you would change

v4l2loopback-dc = pkgs.callPackage ./v4l2loopback-dc.nix {
      kernel = config.boot.kernelPackages;
    };

to

v4l2loopback-dc = boot.config.kernelPackages.callPackage ./v4l2loopback-dc.nix { };

EDIT:
To expand on what I mentioned:

pkgs in this case refers to the top-level package set.
boot.config.kernelPackages refers to a nested package set.

This is how the module expression is able to receive a kernel input, as that package does exist within the kernelPackages package set, but doesn’t exist at the top level. Also, with nested package sets is that if they fail to find a dependency at the current package scope, they can always go to the parent scope and search for a dependency there.

feel free to make a PR for the droidcam package.

I got a video which will guide you: https://www.youtube.com/watch?v=fvj8H5yUKu8

droidcam is not really open to distro packaging, see On packaging this application · Issue #49 · dev47apps/droidcam · GitHub.

I also opened build: Use pkg-config for all dependencies by jtojnar · Pull Request #102 · dev47apps/droidcam · GitHub that would make packaging it nicer.

1 Like

Thanks a lot for the clarification @jonringer !

Concerning the packaging @jtojnar how are we supposed to install properly this app without writting an expression for it ? (Even starting from the binaries) Even with buildFHS you can’t install kernel modules I guess (or it should be super dirty)!

You should not really install anything without a package on any distro, unless you want a junkyard for a system.

1 Like

I’ve never seen someone so opposed to people using their software >.>

The problems are real, recall jwz: I would like Debian to stop shipping XScreenSaver. jwz went nuclear but he did have a point.

1 Like

Yes sure, I’m just curious to know if there is a dirty way to run that package if I don’t have time to write a nix expression for it and recompile from source (like can I use steam-run to load kernel modules?).

Btw, thanks a lot for this trick, there is just a typo: boot.config sould be replaced with config.boot.

1 Like