4

It is possible to install packages from nixos-unstable in /etc/nixos/configuration.nix using the configuration from this answer.

Here is an example of installing the htop packages from nixos-unstable:

{ config, pkgs, ... }:

let
  unstableTarball =
    fetchTarball
      https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz;
in
{
  ...

  nixpkgs.config = {
    packageOverrides = pkgs: {
      unstable = import unstableTarball {
        config = config.nixpkgs.config;
      };
    };
  };

  environment.systemPackages = with pkgs; [
    ...
    unstable.htop
  ];

  ...
};

I would like to be able to install the Virtualbox package (and related kernel modules) from nixos-unstable as well.

Naively adding the virtualbox package to environment.systemPackages doesn't work like I expect it would. The Virtualbox modules matching the unstable version of Virtualbox do not get installed. Here is a snippet from my /etc/nixos/configuration.nix:

  nixpkgs.config.virtualbox.enableExtensionPack = true;
  virtualisation.virtualbox.host.enable = true;
  environment.systemPackages = with pkgs; [
    ...
    unstable.virtualbox
  ];

The above will correctly install the virtualbox package from nixos-unstable, but not the Virtualbox kernel modules.

How can I get the Virtualbox kernel modules to be installed from nixos-unstable as well? And why doesn't the above work?

3

2 Answers 2

1

Your configuration does not work, because the virtualbox module has its own reference to the virtualbox package. Perhaps its should expose an option to override the package like some other modules do, but for now it doesn't. It shouldn't be hard to make a pull request for it.

The alternative is to replace the offending module/modules by disabling the using disabledModules and then importing your replacements with imports.

Either way, your mileage may vary. The first option seems to be the cleanest to me, but you may want to check the differences between the nixos modules in your release and unstable versions.

5
  • Would you be able to update your answer with how to replace the virtualbox modules? The link you provided says to add a field like the following: imports = [ <nixos-unstable/nixos/modules/services/databases/postgresql.nix> ];. However, in my configuration above, I don't have nixos-unstable in my NIX_PATH, but instead in a let-bound variable. How can I add a module from my unstableTarball to the import list?
    – illabout
    Commented Feb 17, 2018 at 15:51
  • 1
    You can import from a variable like this: imports = [ (unstableTarball + "/nixos/modules/services/databases/postgresql.nix") ]. Note the distinction between import, a primitive function from the Nix language and imports, an attribute name used by the NixOS module system. Commented Feb 18, 2018 at 15:30
  • Putting the virtualbox module in disabledModules while also adding it to imports doesn't appear to work. Here's a snippet of my configuration.nix: nixpaste.lbr.uno/H1bGSJvE?nix. The kernel modules for virtualbox do not appear to getting rebuilt. Maybe the only way is your first suggestion: expose an option to override the package?
    – illabout
    Commented Feb 20, 2018 at 15:07
  • 1
    That still seems like an appropriate option. What might also work is to override virtualbox in your nixpkgs.config.packageOverrides or, better, nixpkgs.overlays. There's some funny business going on in the host module that just might inject the proper virtualbox sources into the kernel configuration. Commented Feb 21, 2018 at 12:19
  • That seems to work a little better, but I am still getting an error: nixpaste.lbr.uno/15ayA-aV?nix. When trying to override virtualbox in nixpkgs.config.packageOverrides, it appears that the virtualbox kernel modules are no longer able to find the kernel headers. Any clue on what could be going on here? Or how to fix it?
    – illabout
    Commented Feb 22, 2018 at 15:22
1

The original kernel module is installed, because it is built separately, against a specific kernel. Normally, the virtualbox-host module keeps the kernel module and the user program in sync.

When you want to override the user program, you would also need to override the kernel module. This would amount to something like this:

!!untested code!!

  ...

  boot.kernelPackages = pkgs.linuxPackages.extend (self: super: {
    virtualbox = super.virtualbox.override {
      inherit (self) kernel;
    };
    virtualboxGuestAdditions = super.virtualboxGuestAdditions.override {
      inherit (self) kernel;
    };
  });
  ## also, the user program override should be introduced 
  ## directly at packageOverrides
  nixpkgs.config.packageOverrides = pkgs: rec {
    unstable = import
      (fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz) {
        config = config.nixpkgs.config;
      };
    virtualbox = unstable.virtualbox;
  };

  ...

Something like this should allow you to run the regular virtualbox-host module, with the unstable packages injected.

3
  • That said, and having run a mixed stable / unstable system myself in the past, I can tell you right now, that you'll probably be better off, just running unstable, anyway :-)
    – Bendlas
    Commented Mar 8, 2018 at 23:30
  • This case of virtualbox might work, though, since the kernel is an awesomely stable target.
    – Bendlas
    Commented Mar 8, 2018 at 23:34
  • 1
    Thanks for the suggestion. However it appears that this causes the same error as described in the issue on Github: /tmp/nix-build-virtualbox-modules-5.2.6-4.9.78.drv-0/virtualbox-5.2.6-modsrc/vboxdrv/Makefile.include.header:141: *** Error: unable to find the headers of the Linux kernel to build against. Specify KERN_VER=<version> (currently 4.9.78) and run Make again. Stop. The version of the virtualbox-modules that it is trying to build is correct, though.
    – illabout
    Commented Mar 9, 2018 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.