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?
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.
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.