FHS environments in a builder

Hi,

is it possible to somehow emulate an FHS environment in the builder of a derivation? I’m currently trying to write a derivation for the Julia interpreter/compiler, but it seems to break due to NixOS being non-FHS (the errors seem pretty nightmare-ish, probably nothing that could be easily fixed). Manually building it with buildFHSUserEnv works fine, but that doesn’t seem to work inside a builder:

julia-build-env-shell-env> *** User chroot 'env' attributes are intended for interactive nix-shell sessions, not for building! ***

Is there any alternative to buildFHSUserEnv that could be used here?

1 Like

I made this thing a while ago but never submitted it to nixpkgs. It’s basically a function that takes a derivation as an argument and augments it to run in an FHS. So you can do something like this

runInFHSUserEnv pkgs.hello {
  # Extra buildFHSUserEnv arguments
  targetPkgs = _: [ ... ];
}

and it’ll build that package in an FHS env nested in the build sandbox. So you write a derivation as though it had FHS, and then pass it to this function to make it so.

2 Likes