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

Derivation: src with symbolic link behaves strange #1232

Open
ck3d opened this issue Feb 12, 2017 · 9 comments
Open

Derivation: src with symbolic link behaves strange #1232

ck3d opened this issue Feb 12, 2017 · 9 comments
Assignees
Labels
documentation UX The way in which users interact with Nix. Higher level than UI.

Comments

@ck3d
Copy link

ck3d commented Feb 12, 2017

I defined a derivation where src is a path to a symbolic link which itself points to a directory.
I tried to use a symbolic link to keep the Nix expression untouched, while I am able to change src path with normal command line tools.

By using this mechanism you get following behavior:

  • the build is performed in src path. Patches are applied in your source folder and the intermediate build output is stored also there.
  • once a build was successful, no re-build can be triggered, although the content of that src path changed. Nix do use the path as drv input.
  • in multi-user Nix store mode, the build is performed by nix-daemon, which needs full access to that path to perform building the derivation

Resolving the symbolic link with Nix functions is not possible (as far I understand).

@ck3d
Copy link
Author

ck3d commented Feb 25, 2017

Some related issues are #145 and #897 .

@ck3d
Copy link
Author

ck3d commented Mar 2, 2017

The following minimal derivation realization shows on a multi-user nix store that the symbolic link is copied and not the directory it self:

$ ln -s $(mktemp -d) symlink
$ nix-store -r $(nix-instantiate -E 'derivation {name="test-symlink"; src=./symlink; builder="/bin/sh"; args = ["-xec" "cd $src"]; system=builtins.currentSystem; }')
warning: you did not specify ‘--add-root’; the result might be removed by the garbage collector
these derivations will be built:
  /nix/store/q5jh7c3wzcsa07cld77dnj52xbcssi78-test-symlink.drv
building path(s) ‘/nix/store/qilsbhimnj83wyvxgwys7j5lz0i7r0p9-test-symlink’
+ cd /nix/store/98ndpdd41ccp3373bc3sxs74hm9d8hzb-symlink
sh: line 0: cd: /nix/store/98ndpdd41ccp3373bc3sxs74hm9d8hzb-symlink: Permission denied
builder for ‘/nix/store/q5jh7c3wzcsa07cld77dnj52xbcssi78-test-symlink.drv’ failed with exit code 1
error: build of ‘/nix/store/q5jh7c3wzcsa07cld77dnj52xbcssi78-test-symlink.drv’ failed

The cd command can not be performed, because /nix/store/98ndpdd41ccp3373bc3sxs74hm9d8hzb-symlink is a symbolic link to the created temp directory which is exclusively owned by the calling user.

@TomSmeets
Copy link

This issue is annoys me a lot.
The target directory of symbolic links should be copied directly to the store.

@lheckemann
Copy link
Member

I'm pretty sure allowing symlinks pointing out of the store is intended — it allow referring to paths outside the store for programs that rely on being able to modify parts of their working directories, like gitlab does. Admittedly this is far from being a beautiful solution…

@zimbatm
Copy link
Member

zimbatm commented Jan 16, 2019

I am using this trick in a few private packages as well. Rails and Java apps.

At build time, it's too late to resolve symlinks. The build sandbox is not supposed to be able to go outside.

@ck3d
Copy link
Author

ck3d commented Sep 3, 2019

This issue is still valid for nix version 2.2.2 .

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/how-to-stop-nix-from-unpacking-a-directory/6866/4

@stale
Copy link

stale bot commented Feb 15, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 15, 2021
@fricklerhandwerk fricklerhandwerk added UX The way in which users interact with Nix. Higher level than UI. documentation labels Sep 12, 2022
@fricklerhandwerk
Copy link
Contributor

This could partially alleviated by documenting the behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation UX The way in which users interact with Nix. Higher level than UI.
Projects
None yet
Development

No branches or pull requests

9 participants