nix-community / lorri

Your project’s nix-env [maintainer=@Profpatsch,@nyarly]
Apache License 2.0
638 stars 24 forks source link

Error running `lorri` with `nix 2.6.0` on `darwin` #78

Closed CorbanR closed 2 years ago

CorbanR commented 2 years ago

Describe the bug lorri shell --shell-file .shell.nix failing to build with error

lorri shell --shell-file .shell.nix
lorri: building environment... done
Feb 11 09:14:08.729 ERRO Build failed. No cached environment available.
Build error: Nix process returned exit code 1.
$ "nix-build" "--out-link" "/var/folders/zn/gkkzshhs4d7gnb13bms0mg5m0000gn/T/.tmpMLvZ9Y/result" "--" "/var/folders/zn/gkkzshhs4d7gnb13bms0mg5m0000gn/T/.tmpjzOeZc/result"
error: syntax error, unexpected ',', expecting ')'

       at /nix/store/65zpf8c3p178ynxnyvhxm2iz8kbji87b-lorri-keep-env-hack-tapestry.drv:1:15:

Additionally the same error show up when I enter the directory as I use direnv

Feb 11 09:01:41.287 INFO build status, message: BuildEvent(Started { nix_file: NixFile(AbsPathBuf("/Users/my/git/dev/coolname/.shell.nix")), reason: PingReceived })
Feb 11 09:01:45.925 INFO build status, message: BuildEvent(Failure { nix_file: NixFile(AbsPathBuf("/Users/my/git/dev/coolname/.shell.nix")), failure: Exit { cmd: "\"nix-build\" \"--out-link\" \"/var/folders/zn/gkkzshhs4d7gnb13bms0mg5m0000gn/T/.tmpn31i5Y/result\" \"--\" \"/var/folders/zn/gkkzshhs4d7gnb13bms0mg5m0000gn/T/.tmpThuRrd/result\"", status: Some(1), logs: [LogLine("error: syntax error, unexpected \',\', expecting \')\'"), LogLine(""), LogLine("       at /nix/store/65zpf8c3p178ynxnyvhxm2iz8kbji87b-lorri-keep-env-hack-tapestry.drv:1:15:")] } })

The above error only started when I upgraded to nix 2.6.0. I use direnv with lorri, however I get the same error, even when trying a lorri shell

To Reproduce My current setup is as follows

  1. Install direnv
  2. install nix version 2.6.0, experimental flake support is NOT enabled.(I use a separate wrapper nixFlakes for that`
  3. Create a folder mkdir lorri_test
  4. Create a .envrc with something like
    eval "$(lorri direnv --shell-file .shell.nix)"
    eval "$shellHook"
    unset PS1
    PATH_add ./.idea
  5. Create a .shell.nix with something like
    
    { pkgs ? import <nixpkgs> {system = "x86_64-darwin";}, ...}:

with pkgs;

let inherit (darwin.apple_sdk.frameworks) CoreServices ApplicationServices Security; darwinPackages = [ CoreServices ApplicationServices Security ];

nodejs = nodejs-12_x;

in mkShell rec { name = "tapestry";

buildInputs = [ nodejs (yarn.override { inherit nodejs; }) ] ++ darwinPackages;

shellHook = ''

Add additional folders to to XDG_DATA_DIRS if they exists, which will get sourced by bash-completion

for p in ''${buildInputs}; do
  if [ -d "$p/share/bash-completion" ]; then
    if [ -z ''${XDG_DATA_DIRS} ]; then
      XDG_DATA_DIRS="$p/share"
    else
      XDG_DATA_DIRS="$XDG_DATA_DIRS:$p/share"
    fi
  fi
done

NODE_ENV=development

source ${bash-completion}/etc/profile.d/bash_completion.sh

''; }

6. run `direnv allow` in the folder
7. watch `lorri` logs

**Expected behavior**
lorri builds

**Metadata**

```console
$ lorri info --shell-file .shell.nix
lorri version: 1.5
GC roots do not exist. Has the project been built with lorri yet?
$ uname -a
Darwin My-MacBook-Pro 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000 arm64 arm Darwin

Additional context I've tried clearing out all lorri cache, nix cache, restarting etc. Running a nix-shell .shell.nix or even a nix shell -f .shell.nix

sudo nix-collect-garbage && nix-collect-garbage && sudo nix-store --verify --check-contents --repair &&  sudo nix-store --optimise

I tested this same scenario inside a linux container running nix 2.6.0 and am NOT seeing the same issue. It appears to be specific to OSX

thefloweringash commented 2 years ago

I think this is a nix 2.6.0 bug involving directory symlinks. I've commented on the nix issue about symlinks causing ambiguity (https://github.com/NixOS/nix/issues/1958#issuecomment-1040029485). As for why it only occurs on macOS, the problem requires a directory symlink, and on macOS, /tmp is a link to private/tmp.

hedefalk commented 2 years ago

I have the same issue after upgrading nix. nix-shell works fine but lorri chokes:

🐟 lorri shell --shell-file ../shell.nix                                                                                                                                                  oasys 
lorri: building environment.... done
Feb 16 10:07:53.288 ERRO Build failed. No cached environment available.
Build error: Nix process returned exit code 1.
$ "nix-build" "--out-link" "/var/folders/s_/qdwr96yj3zv0vy21sdzzlx3m0000gn/T/.tmp0zAx9R/result" "--" "/var/folders/s_/qdwr96yj3zv0vy21sdzzlx3m0000gn/T/.tmpsVsKBI/result"
error: syntax error, unexpected ',', expecting ')'

       at /nix/store/f0zbb12xlk0hhx3l44xz4gv98ynw31vk-lorri-keep-env-hack-nix-shell.drv:1:15:
🐟 head  /nix/store/f0zbb12xlk0hhx3l44xz4gv98ynw31vk-lorri-keep-env-hack-nix-shell.drv:

Derive([("out","/nix/store/dabpckpi3wa5cd689pzkj3rshm92igca-lorri-keep-env-hack-nix-shell","","")],
………
CorbanR commented 2 years ago

I tried this on nix 2.6.1 and the issue appears to be resolved, albeit I'm seeing lorri crash occasionally, which hasn't been the norm for me.