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

dirOf should work with relative paths #2251

Closed
pvgoran opened this issue Jun 24, 2018 · 6 comments
Closed

dirOf should work with relative paths #2251

pvgoran opened this issue Jun 24, 2018 · 6 comments

Comments

@pvgoran
Copy link

pvgoran commented Jun 24, 2018

Cross-posting from NixOS/nixpkgs#42340.

Issue description

nix's built-in function dirOf only works for strings which are absolute paths, for some reason. This looks like a completely arbitrary (and quite unfortunate) restriction, and the documentation doesn't mention it.

The related function baseNameOf does work for all kinds of strings.

Steps to reproduce

nix-instantiate --eval --expr 'dirOf "dir/abc.txt"'                                                        ~
error: string 'dir/abc.txt' doesn't represent an absolute path, at (string):1:1

Technical details

  • system: "x86_64-linux"
  • host os: Linux 4.14.49, NixOS, 18.03.132687.14c248a4ab7 (Impala)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.0.4
  • channels(paul): ""
  • channels(root): "nixos-18.03.132687.14c248a4ab7"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs
@pvgoran
Copy link
Author

pvgoran commented Jun 24, 2018

Posted here as suggested in NixOS/nixpkgs#42340 (comment).

@edolstra
Copy link
Member

I disagree. This would introduce an impurity into the evaluator (namely, the current directory), which would cause evaluation to produce a different result depending on the cwd.

@pvgoran
Copy link
Author

pvgoran commented Jun 25, 2018

Why would it need to depend on the current directory?? It should be just a text processing operation which doesn't care about the filesystem or environment.

dirOf "dir/abc.txt" == "dir"
dirOf "abc.txt" == "."
dirOf "../abc.txt" == ".."

@lheckemann
Copy link
Member

Some oddities — what would you expect map dirOf ["." ".." "../.."] to result in? There's precedent for ["." "." ".."] in the behaviour of coreutils dirname, but that might not be the least confusing thing to do since it won't always get the parent directory.

@pvgoran
Copy link
Author

pvgoran commented Aug 13, 2018

["." "." ".."] seems to be appropriate.

The goal is not to get a parent directory. The goal is to get a directory name which, when combined with the result of baseNameOf, would be the logical equivalent of the initial path.

@lheckemann
Copy link
Member

This seems like sensible behaviour to me. Implemented in #2349.

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

No branches or pull requests

3 participants