Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the installation prefix #7771

Open
2 tasks done
fricklerhandwerk opened this issue Feb 7, 2023 · 5 comments
Open
2 tasks done

Document the installation prefix #7771

fricklerhandwerk opened this issue Feb 7, 2023 · 5 comments
Labels
documentation good first issue Quick win for first-time contributors

Comments

@fricklerhandwerk
Copy link
Contributor

fricklerhandwerk commented Feb 7, 2023

Problem

Many environment variables rely on a prefix that is not further explained, and it's not clear where it is defined and what value it has. In practice we observe it to be /nix.

Grepping the source one only finds one relevant occurrence in the Makefile, which defaults to /usr/local in the makefile, but this is just the location to place the build result in, and is set to $out in the Nix-based build.

Proposal

Document what prefix defaults to, and how and where it can be set.

Checklist

Priorities

Add 👍 to issues you find important.

@roberth
Copy link
Member

roberth commented Feb 7, 2023

Might this be a more typical autotools+nixpkgs solution, that should be documented in Nixpkgs and referenced here?

Taking a minute, I could only find something about dontAddPrefix and the configure phase just above it. Nixpkgs doesn't seem to elaborate much on this; although maybe I missed one of the scattered reference bits that are grouped by technical class instead of domain topic.

@fricklerhandwerk
Copy link
Contributor Author

fricklerhandwerk commented Feb 8, 2023

From multiple half-hearted attempts of navigating the code, it's not evident to me how and where that prefix is ever set to a non-default at all. It appears that building Nix as the installer would is defined outside this repository, but I'm probably missing something obvious.

@fricklerhandwerk fricklerhandwerk changed the title Document the build prefix Document the installation prefix Feb 10, 2023
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/tweag-nix-dev-update-44/25546/1

@michaelCTS
Copy link

michaelCTS commented Aug 18, 2023

I'm running into this issue too. We would like to use google workstations and only the /home mount is persisted across restarts which means installing to /nix will not persist.

How can I set the prefix to e.g /home/user/nix ?

Edit:

Editing this line for single-user installs still fails

/nix is hardcoded it seems, even for single-user installs. Probably a bind mount of the prefix to /nix/store should work, but that wouldn't work for users without admin rights...

Edit2:

So, it's probably because nix has hard coded paths to /nix/store and expects to find dependencies there.

user@michaels-workstation:~/nix/store/3wqasl97rjiza3vd7fxjnvli2w9l30mk-nix-2.17.0/bin$ ll
total 3752
dr-xr-xr-x 2 user user    4096 Jan  1  1970 ./
dr-xr-xr-x 7 user user    4096 Jan  1  1970 ../
-r-xr-xr-x 1 user user 3831976 Jan  1  1970 nix*
lrwxrwxrwx 1 user user       3 Jan  1  1970 nix-build -> nix*
lrwxrwxrwx 1 user user       3 Jan  1  1970 nix-channel -> nix*
lrwxrwxrwx 1 user user       3 Jan  1  1970 nix-collect-garbage -> nix*
lrwxrwxrwx 1 user user       3 Jan  1  1970 nix-copy-closure -> nix*
lrwxrwxrwx 1 user user       3 Jan  1  1970 nix-daemon -> nix*
lrwxrwxrwx 1 user user       3 Jan  1  1970 nix-env -> nix*
lrwxrwxrwx 1 user user       3 Jan  1  1970 nix-hash -> nix*
lrwxrwxrwx 1 user user       3 Jan  1  1970 nix-instantiate -> nix*
lrwxrwxrwx 1 user user       3 Jan  1  1970 nix-prefetch-url -> nix*
lrwxrwxrwx 1 user user       3 Jan  1  1970 nix-shell -> nix*
lrwxrwxrwx 1 user user       3 Jan  1  1970 nix-store -> nix*
user@michaels-workstation:~/nix/store/3wqasl97rjiza3vd7fxjnvli2w9l30mk-nix-2.17.0/bin$ ./nix-store
-bash: ./nix-store: No such file or directory
user@michaels-workstation:~/nix/store/3wqasl97rjiza3vd7fxjnvli2w9l30mk-nix-2.17.0/bin$ ldd nix
./nix: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./nix)
./nix: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by ./nix)
./nix: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by ./nix)
./nix: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by ./nix)
        linux-vdso.so.1 (0x00007ffd0eb63000)
        libsodium.so.23 => /lib/x86_64-linux-gnu/libsodium.so.23 (0x00007f069f5f3000)
        libeditline.so.1 => not found
        libnixexpr.so => not found
        libgc.so.1 => /lib/x86_64-linux-gnu/libgc.so.1 (0x00007f069f580000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f069f55b000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f069f555000)
        libnixmain.so => not found
        libnixfetchers.so => not found
        libnixstore.so => not found
        libnixutil.so => not found
        libnixcmd.so => not found
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f069f371000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f069f222000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f069f207000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f069f015000)
        /nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f069f655000)

Edit 3:

sudo mkdir /nix
sudo mount --bind /home/user/nix /nix

Worked (unsurprisingly), but it's not a viable solution for users that don't have root privileges when installing nix.

@roberth
Copy link
Member

roberth commented Aug 18, 2023

My understanding of a term "installation prefix" would be something like the ./configure --prefix option when building Nix from source.
I don't think that's what most people would want to know about, unless they're packaging Nix as an FHS package in a traditional distro.

@michaelCTS brings up a similar question whose answer would include the storedir parameter (default: /nix/store). Iiuc, this is a parameter of LocalStore, so that you can use Nix to bootstrap a store with any storedir.

So, it's probably because nix has hard coded paths to /nix/store and expects to find dependencies there.

This project itself does not assume that it is built by Nix, and we generally don't hardcode the storedir. We do have defaults though, and some third party code might make the assumption. Those should be really minor issues that are easily fixed, so the only structural disadvantage is that you won't be able to reuse cache.nixos.org with it.

Furthermore it's possible to use Linux namespaces to provide a "virtual" store that resides in a different physical location such as your homedir, without having to change all those paths.
This is the preferred solution because you can use cache.nixos.org with it. Linux namespaces are widely available nowadays. If you can run docker or podman, you can run Nix in this mode.

Apologies for the lack of concrete details; I hope this braindump is at least somewhat helpful until we resolve this issue properly.

Also did I just expand the scope of the issue?..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation good first issue Quick win for first-time contributors
Projects
None yet
Development

No branches or pull requests

4 participants