install virtualbox modules from nixos-unstable in configuration.nix

自古美人都是妖i 提交于 2019-12-06 09:53:31

问题


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?


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/48838411/install-virtualbox-modules-from-nixos-unstable-in-configuration-nix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!