Is Nix right for our use? Custom path and custom directory

Hi all,

I am in need to build quite a lot of software in a reproducible way while being as fast as possible.

Nix seems a perfect fit, however, I do have also some other restrictions.

  1. All the build artefact must be placed inside a specific directory, I don’t care about the name of the artefact as long as they are placed under /foo/bar/...whatever..., it cannot be /.nix/store
  2. I need to create a specific dir structure, still under the same directory of above, something like:
    /foo/bar/gcc7/lib/...all_the_libraries_compiled_with_gcc7... and then /foo/bar/gcc8/lib/...all_the_libraries_compiled_with_gcc8... and then /foo/bar/gcc7/bin/...all_the_binaries_compiled_with_gcc7... and so on and so forth.
    This structure is quite more complex than this one, but similar.
    This structure can very well being created using symlink.

So, before I dive deeper into Nix I am wondering if it is possible at all and if it is actually practical.

Cheers,

My first reaction was to respond with “Nix allows for stores in
arbitrary places”, but, even if that solved your wanted directory
problem, you would lose any speed benefit because every dependency would
have to be recompiled to live in that store.

I don’t think Nix’s design allows for anything to work outside the Nix
Store. However, your requirements may be addressed with nix-shell. You
could, in theory, write a shell.nix that puts your required binaries
in scope, then (if possible inside Nix, or with a shell hook) build a
tree made of symlinks (looking at the source code for
buildFHSUserEnv
may be useful, and probably tells us that the possible approach is the
shell hook).

If you really need /foo/bar to be at /,
steam-run
does some additional magic with a chroot. Although it still seems weird
to put the tree directly under /, but maybe that was just for the sake
of simplification?

I would need to compile nix myself passing --with-store-dir flag the as describe here: Introduction - Nix Reference Manual is that correct?

I don’t really care to recompile everything from scratch, as long as I need to compile it only once. I can have massive jobs that compiles everything, but it is important that is done only once.

No actually will be very very similar to /foo/bar.

Compile Nix with a custom store location, and then (optionally) use Nix to create/manage your custom folders with symbolic links.

I’m doing something quite similar at my workplace (or at least I am trying as I can’t use sandbox builds as user namespaces are not enabled).

1 Like

You don’t need to recompile nix with your custom path. Nix can be told to use another directory with environment variables: see the nix test suite for example
https://github.com/NixOS/nix/blob/master/tests/common.sh.in#L8

Thanks, that would be definitely useful, at the very least in testing.

I think we’re missing some information on the requirements. Can you develop the reasons behind the strict folder structure?

There was a discussion about using a different directory for the Nix store, maybe this has pointers that can help you?