Any way to preserve and reuse intermediate artifacts

Hi there

I am trying to debug virtualbox package, for that I am modifying the pkgs/applications/virtualization/virtualbox/default.nix in a branch on my fork. Then I pin that branch/commit in my configuration.nix and use nixpkgs.config.packageOverrides to tell nix to use that version of virtualbox. Virtualbox is activated through = true;. If I nix-build it separately and execute it, it will throw an error at runtime.

My question is that each time I do nixos-rebuild to check a change in default.nix, the entire VirtualBox gets rebuilt, which takes 17 minutes on my machine. My question is this: is there a way to preserve and reuse intermediate artifacts? If I am patching only one source file, it should not be needed to recreate all the .o files for the entire project.

1 Like

Thank you for the quick and relevant answer.
I activated ccache with programs.ccache.enable = true; and nix.settings.extra-sandbox-paths = [ config.programs.ccache.cacheDir ];, also added the wrapper configuration to Nix overlays. After that I nixos-rebuild switched, and then added programs.ccache.packageNames = [ "virtualbox" ];

Now it seems nix is trying to build it in 32 bit version for some reason. Or compiler.h is not found.

virtualbox> Checking for environment: Determined build machine: linux.amd64, target machine: linux.amd64, OK.
virtualbox> Checking for libdevmapper: found version 1.02.191 (2023-02-21), OK.
virtualbox> Checking for libcap library: found, OK.
virtualbox> Checking for compiler.h: compiler.h not found, OK.
virtualbox> Checking for 32-bit support: 
virtualbox>   Cannot compile 32-bit applications (missing headers and/or libraries)!
virtualbox>   Check the file /build/VirtualBox-7.0.6/configure.log for detailed error information.
virtualbox> Check /build/VirtualBox-7.0.6/configure.log for details
error: builder for '/nix/store/gkmylj2mq5fghsz37n2ml8arw5agvari-virtualbox-7.0.6.drv' failed with exit code 1
error: 1 dependencies of derivation '/nix/store/62gbrzjq4m8cvkvf4av2mk7ymg998nzc-nixos-system-nixos-23.05pre469482.e3652e0735f.drv' failed to build

Whereas this same derivation was built correctly before.