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

bug: mkOutOfStoreSymlink still links inside nix store for flake and toString input #2660

Closed
1 task done
yipengsun opened this issue Jan 23, 2022 · 4 comments
Closed
1 task done
Assignees
Labels

Comments

@yipengsun
Copy link

yipengsun commented Jan 23, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Issue description

I'm trying to link my fcitx config out-of-nix-store. I've searched the issues and it looks to me that for flake-based setup, I need to pass a string to mkOutOfStoreSymlink:

# omitted full name for brevity
xdg.configFile."bla".source = mkOutOfStoreSymlink "/home/me/bla";

And it worked like this:

~/.config/bla -> /nix/store/hash-bla -> /home/me/bla

so it's fine. I then want to make this more portable by doing this:

# say my project root is at /home/me
xdg.configFile."bla".source = mkOutOfStoreSymlink (builtins.toString ./bla);

Now it doesn't work. The link terminates at a nix store location.

I've read #589 #2085, and I'm confused on why a literal string works, but toString doesn't.

For my real setup, see https://github.com/yipengsun/nix-config/blob/d3268ce6c3feb6d2cdf56168333582fa476e5bf9/local/profiles/wm/default.nix#L41-L46

Maintainer CC

No response

System information

/nix/store/jaa5l5g36aj1wwlmk9lqhslclmdqms3x-bash-interactive-5.1-p12-dev
copying path '/nix/store/jaa5l5g36aj1wwlmk9lqhslclmdqms3x-bash-interactive-5.1-p12-dev' from 'https://cache.nixos.org'...
 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.16, NixOS, 22.05 (Quokka)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.6.0pre20211217_6e6e998`
 - channels(root): `"nixos-21.11pre292520.540dccb2aea"`
 - nixpkgs: `/nix/store/j5dard0z8nvg3ihsiyv4hkg4105pn1d2-source`
@yipengsun yipengsun added bug triage Issues or feature request that have not been triaged yet labels Jan 23, 2022
@berbiche berbiche added question and removed bug triage Issues or feature request that have not been triaged yet labels Jan 23, 2022
@berbiche
Copy link
Member

berbiche commented Jan 23, 2022

I then want to make this more portable by doing this:

# say my project root is at /home/me
xdg.configFile."bla".source = mkOutOfStoreSymlink (builtins.toString ./bla);

Now it doesn't work. The link terminates at a nix store location.

This is not possible with Flakes because it uses "pure evaluation"/"restricted evaluation".

Essentially, if builtins.toString ./. returned the absolute path of the a file outside of a nix builder's view, it would be impure and leak building information.

Nix Flakes are pure by nature, which makes it impossible to use the functionality you described.

edit: Flakes are also copied to the Nix store, so the relative directory is always relative to the store.

I hope this helps.

@yipengsun
Copy link
Author

I see. that makes sense.

@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-refer-to-current-directory-in-shell-nix/9526/9

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/getting-local-path-in-flake/19715/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants