How to install version 7.0.22 of virtualbox guest additions?

I am running virtualbox on a Windows 11 host and using it to run NixOS 24.11 and unstable. I’ve found that VirtualBox 7.0.22 is the optimal version for my system as newer versions seem broken at the moment. NixOS uses newer versions of VirtualBox guest additions and currently seamless mode does not work for my NixOS unstable guest, even though I’ve enabled VirtualBox guest additions with virtualisation.virtualbox.guest.enable = true; in /etc/nixos/configuration.nix. I’ve found this thread on how to install older versions of a package, but I do not see an option to specify the package used for VirtualBox guest additions. I know there’s a virtualisation.virtualbox.host.package option, but there does not seem to be a virtualisation.virtualbox.guest.package, so I’m afraid I need to turn to ask for your assistance. Is there a way to specify the VirtualBox guest addition package?

I found this here maybe it helps, from the comments it sounds as they were trying to do the same thing.

Forgive me, but this seems to install VirtualBox itself and the extension pack, it doesn’t seem to install the guest additions. Am I wrong about this? I will not claim to be the most fluent in Nix, I just don’t see any line that refers to guest additions here. Oops, sorry, I’m a little slow sometimes and I do see how I could possibly adjust this to my use case. Thank you.

Hmm, seems I am going to need some help. I’ve added this to my configuration.nix to try to implement these suggested changes:

@ -3,10 +3,20 @@
 # and in the NixOS manual (accessible by running ‘nixos-help’).
 
 { config, pkgs, ... }:
-{
+
+let 
+  virtualbox-7_0_22_pkgs = import (builtins.fetchTree {
+         type = "github";
+        owner = "NixOS";
+        repo = "nixpkgs";              
+         rev = "78ebb34bc8368518f2e1440f8205800d082e6be4";                                           
+     }) { ìnherit (prev) system; };
+in {
+  virtualbox = virtualbox-7_0_22_pkgs.virtualbox;
   imports =
     [ # Include the results of the hardware scan.
       ./hardware-configuration.nix
+      #./virtualbox.nix
       <home-manager/nixos>
     ];

This gives the error:

error:
       … while evaluating the attribute 'config'
         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:1:12284:
       … while calling the 'seq' builtin
         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:1:12293:
       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: syntax error, unexpected invalid token
       at /home/fusion809/NixOS-configs/configuration.nix:13:11:
           12|          rev = "78ebb34bc8368518f2e1440f8205800d082e6be4";
           13|      }) { ìnherit (prev) system; };
             |           ^
           14| in {
building the system configuration...

I’ve also tried uncommenting “virtualbox.nix” with this being virtualbox.nix:

final: prev:
let
  virtualBoxVersion = "7.0.22";
  virtualbox-7_0_22-pkgs = import (builtins.fetchTree {
      type = "github";
      owner = "NixOS";
      repo = "nixpkgs";              
      rev = "78ebb34bc8368518f2e1440f8205800d082e6be4";                                           
  }) { ìnherit (pkgs) system; };

in
  {
    virtualbox = virtualbox-7_0_22-pkgs.virtualbox;
  }

but that gave the error:

error:
       … while evaluating the attribute 'config'
         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:1:12284:
       … while calling the 'seq' builtin
         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:1:12293:
       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: syntax error, unexpected invalid token
       at /home/fusion809/NixOS-configs/virtualbox.nix:9:8:
            8|       rev = "78ebb34bc8368518f2e1440f8205800d082e6be4";
            9|   }) { ìnherit (pkgs) system; };
             |        ^
           10|

I’ve also tried replacing pkgs with prev. I get the same error, more or less then too. How do I get past these errors?

If that post doesn’t work for you (and I suspect it won’t, but you should try it in case I’m wrong—the issue you’re currently encountering with it is an accented ì character where it is complaining—replace that with an English i), here’s another concept. This is more involved than your typical override because it’s a kernel module, but you should be able to do something like this:

boot.kernelPackages =
  let
    # or however you want to get a Nixpkgs from when 7.0.22 was the Virtualbox version
    oldPkgs =
      builtins.fetchTarball {
        url = "https://github.com/NixOS/nixpkgs/archive/882842d2a908700540d206baa79efb922ac1c33d.tar.gz";
      };
  in
  # change linuxPackages to a different kernel package set if desired
  pkgs.linuxPackages.extend (final: prev: {
    virtualboxGuestAdditions = final.callPackage
      "${oldPkgs}/pkgs/applications/virtualization/virtualbox/guest-additions"
      { };
  });
2 Likes

It worked! Thank you @rhendric.

Ah yeah sorry of course.