Hi again, I just wanted to report back here that I have a solution to this problem now. I’ve noticed that the reason why nix build doesn’t work inside recursive-nix is that it tries to fetch its inputs during eval time, similar to how builtins.fetchTarball does. This fails because the recursive-nix derivation’s build environment doesn’t have access to the internet (unless you disable Nix’s sandboxing entirely). However, I’ve discovered since then that it’s possible to make it not fail at that.
One approach is to artificially inject these dependencies into the build closure of the recursive-nix derivation, you can see an example of that here. In this case, I’ve assembled that evalTimeDependencies.nix by attempting to build the recursive-nix derivation and figuring out, based on the error message, what it’s trying to download. Anything that’s in the build-time closure of the recursive-nix derivation will be visible to it in the /nix/store it sees during the build, so when it tries to fetchTarball, it finds the result there and doesn’t try to access the internet.
Another approach that’s actually much more ergonomic for flakes is to instead make the flake fetch its inputs using pkgs.fetchzip instead of fetchTarball. This way, you don’t have to mess with the recursive-nix derivation to inject anything. The way I’ve managed to do this is to build the flake inside recursive-nix with nix-build using flake-compat instead of the usual nix build, but I’ve used a modified version of flake-compat that allowed me to override the fetchTarball with pkgs.fetchzip. The flake builds fine inside recursive-nix, because unlike fetchTarball, pkgs.fetchzip performs the actual download as part of the build of a fixed-output derivation. So, what happens is that the nix-build running inside the recursive-nix offloads the download to an independent build that has access to the internet since it is a fixed-output derivation. I find this approach to be much more ergonomic, because I’ve been able to encapsulate it entirely so that I can expose these recursive-nix derivations easily from existing haskell.nix projects.
5 Likes