zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
51.04k stars 3.17k forks source link

No env at all when opening _inside_ a direnved nix flake folder. #21269

Open hedefalk opened 6 days ago

hedefalk commented 6 days ago

Check for existing issues

Describe the bug / provide steps to reproduce it

This is a weird one that just started happening.

1) First off I get "Auto update failed" and I guess that's because zed can't find rsync?

2) Also, if I start a terminal, it seems to use bash and not honoring my settings. I guess there's something very wrong that just strated happened here.

I have:

  "shell": {
    "with_arguments": {
      "program": "/run/current-system/sw/bin/fish",
      "arguments": ["--login"]
    }
  },

both in root and under "terminal". The latter worked fine until latest update. Now I get:

bash: line 6: compgen: command not found
set: Tried to modify the special variable 'PWD' with the wrong scope
set: Tried to modify the special variable 'SHLVL' with the wrong scope
warning: Could not set up terminal.
warning: TERM environment variable not set.
warning: Using fallback terminal type 'xterm-256color'.
warning: Could not set up terminal.
warning: TERM environment variable not set.
warning: Using fallback terminal type 'xterm-256color'.
/nix/store/sk8z3kdy6iaky6sg972k6fkh3iw2rn3d-bash-5.2p37/bin/bash: line 1: env: command not found
/nix/store/sk8z3kdy6iaky6sg972k6fkh3iw2rn3d-bash-5.2p37/bin/bash: line 1: env: command not found

so its using bash all of a sudden.

Reason I post these issues together is I really think its related. Something with the env just broken resulting in both issues…? Not sure how to debug this…

Environment

Zed: v0.162.5 (Zed) OS: macOS 15.1.1 Memory: 64 GiB Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

Zed.log ``` 2024-11-28T10:06:03.774576+01:00 [ERROR] oneshot canceled 2024-11-28T10:06:03.774761+01:00 [ERROR] oneshot canceled 2024-11-28T10:06:03.774896+01:00 [ERROR] oneshot canceled 2024-11-28T10:06:03.77503+01:00 [ERROR] oneshot canceled 2024-11-28T10:06:06.139598+01:00 [INFO] ========== starting zed ========== 2024-11-28T10:06:06.206568+01:00 [INFO] Opening main db 2024-11-28T10:06:06.207776+01:00 [INFO] Opening main db 2024-11-28T10:06:06.23475+01:00 [INFO] Using git binary path: Some("/Applications/Zed.app/Contents/MacOS/git") 2024-11-28T10:06:06.405664+01:00 [INFO] No prompt template overrides directory found at /Users/viktor/.config/zed/prompt_overrides. Using built-in prompts. 2024-11-28T10:06:06.406876+01:00 [INFO] extensions updated. loading 13, reloading 0, unloading 0 2024-11-28T10:06:06.448693+01:00 [INFO] Opening main db 2024-11-28T10:06:06.452159+01:00 [INFO] set status on client 0: Authenticating 2024-11-28T10:06:06.45402+01:00 [INFO] building git repository, `.git` path in the worktree: ".git" 2024-11-28T10:06:06.454925+01:00 [INFO] set status on client 132376: Connecting 2024-11-28T10:06:06.466024+01:00 [INFO] set environment variables from shell:/run/current-system/sw/bin/fish, path:/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin 2024-11-28T10:06:06.476665+01:00 [INFO] Opening main db 2024-11-28T10:06:06.483368+01:00 [INFO] open paths ["/Users/viktor/.config/zed/settings.json"] 2024-11-28T10:06:06.484051+01:00 [INFO] Opening main db 2024-11-28T10:06:06.510716+01:00 [ERROR] auto-update failed: error:Aborting. Could not find rsync which is required for auto-updates. 2024-11-28T10:06:06.512387+01:00 [INFO] using project environment variables from CLI. PATH="/nix/store/xsrf9zwlb7mmiyqmwyax665radvz90bp-build-local-console/bin:/nix/store/035ndybx6hmw4219xs4cgm8vprfh5v23-dev.kalix/bin:/nix/store/gbb2xam9ql3fi05xbgb4x3wzl0lcckwh-scale.management-api.down.and.up/bin:/nix/store/d9njgsn66662p77sj68dkrxgzrbgkbzg-wb.k/bin:/nix/store/08cb23maf064fmgc7zj54z84z2734vpz-wb.kalix/bin:/nix/store/9iv3zq45jsmws7lq38bn4470yxqgj978-zulu-ca-jdk-21.0.2/bin:/nix/store/07d0n697sl7zv61bs1dfc8kfh72d5p49-postgresql-13.15/bin:/nix/store/0xxfc57n7ifa64pzmgr9hqzl3idlvh22-scala-2.13.12/bin:/nix/store/j9rha9dzxx75b4bmcz8mgpd99w515ysz-scala-cli-1.3.2/bin:/nix/store/kaqihm6yh3syg1yq6yvzq3b2l5lxc910-sbt-1.10.0/bin:/nix/store/znp40wcn5xa2ayr11mxm656xhgahik85-ncurses-6.4-dev/bin:/nix/store/dhfrwrfj2ndhj5z4riy9wrz6mb1wnmvp-ncurses-6.4/bin:/nix/store/ryz5m9pfjydwh2jn8rnhmbiy1hl1q3qp-nodejs-18.20.2/bin:/nix/store/zfqhk8xddn9z9dfhqxpazwfbg6ax0hxc-apache-maven-3.9.6/bin:/nix/store/3i93wdvkay14n8y90dfnp1fkm5jk6s7z-terraform-1.1.0/bin:/nix/store/s7mhjkvkshh3kqr206jabkq0zk8gb690-google-cloud-sdk-452.0.1/bin:/nix/store/68s205iqz4x1fvry7nkhg8g270v1vcy4-jq-1.7.1-bin/bin:/nix/store/6dysg86604nl3cqw6wxsdawwf80cwz84-cargo-1.77.2/bin:/nix/store/w99j5fqpc8dz0m732b40pk6kfdq4gsh1-libiconv-99/bin:/nix/store/lihfrxvch34hpmb1ww4bcvdrsnfrsspl-perl5.38.2-pgformatter-5.5/bin:/nix/store/l1q46czfrz2p70x1mmk79rpw7c8j3g7f-bun-1.1.10/bin:/nix/store/khaq50v4shpjjldg62r6qzmgmpc5gh79-pnpm-9.1.1/bin:/nix/store/s82a1ks98cpfldwvnaqqbw62mx4f7c29-kustomize-5.4.2/bin:/nix/store/ql694ssf4947k20hsrvspnbjs59a21sy-devenv/bin:/nix/store/b5hlaiv3vg8qgr3vhsw78cjh5s2zrph9-pkg-config-wrapper-0.29.2/bin:/nix/store/c1ib07kj7baid3s3wf5m98hcpbvgs8mk-clang-wrapper-16.0.6/bin:/nix/store/09wcswiav8pc54w87r6vx1ylfgq4m2ah-clang-16.0.6/bin:/nix/store/4q1ilwxg18vyz4p1mp7k9wv0wrycn325-coreutils-9.5/bin:/nix/store/ylj6rc5qs7xl6m2dr5h09l88pcjirh8h-cctools-binutils-darwin-wrapper-16.0.6-973.0.1/bin:/nix/store/dxi4ss61svmkfr02299kfplj4i63lar8-cctools-binutils-darwin-16.0.6-973.0.1/bin:/nix/store/4q1ilwxg18vyz4p1mp7k9wv0wrycn325-coreutils-9.5/bin:/nix/store/v2f2czixsg2vqjck84n879whz8bc1zg5-findutils-4.9.0/bin:/nix/store/zc2r2ph0wd5nwbhrx3bhpinj4c59qh1g-diffutils-3.10/bin:/nix/store/gnq3l6ixidmzhb93fx0lk11l9622iwc4-gnused-4.9/bin:/nix/store/kp35gjhszl722f6mi2889y1b8m96j5h9-gnugrep-3.11/bin:/nix/store/4gdsyghh0g0d40cxn9p1ykcaj954qj31-gawk-5.2.2/bin:/nix/store/r8zjcvgc612pbkz4zjcrdvg5680s1jil-gnutar-1.35/bin:/nix/store/g67jzdjwck8985nc6vwvd4nhyiayra6w-gzip-1.13/bin:/nix/store/bmf02sfvvnvasxh0p82pa7gm7zari9n9-bzip2-1.0.8-bin/bin:/nix/store/ka4fg0rm5hmaji7vwnvzk4qg4dhksg7v-gnumake-4.4.1/bin:/nix/store/60qp4q78hlg1fsvq4np6iv0gpqrl4v4p-bash-5.2p26/bin:/nix/store/h18r6fzyhbja3kf1xfa9ybr7vg4a3w3a-patch-2.7.6/bin:/nix/store/2g288xzj6lcccrnwr18z6jn0hima0p08-xz-5.4.6-bin/bin:/nix/store/jiwmhzzks8m6yblw8ba3b6dmgcn167k2-file-5.45/bin:/Users/viktor/dev/lightbend/.direnv/bin:/Users/viktor/dev/lightbend/bin:/Users/viktor/go1.22.5/bin:/Users/viktor/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/etc/profiles/per-user/viktor/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/Users/viktor/.nix-profile/bin:/Users/viktor/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin:/Users/viktor/Library/Application Support/Coursier/bin" ```
notpeter commented 2 days ago

Yes we require rsync for auto-update. It looks like your current path does not include /usr/bin and so we can't find rsync at /usr/bin/rsync:

2024-11-28T10:06:06.466024+01:00
[INFO] set environment variables from
shell:/run/current-system/sw/bin/fish,
path:/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin

Yes, the settings for shell should be under terminal, but the correct key is args not arguments`. Docs: Configuring Zed: Terminal Shell

  "terminal": {
    "shell": {
      "with_arguments": {
        "program": "/run/current-system/sw/bin/fish",
        "args": ["--login"]
      }
    }
  }
hedefalk commented 1 day ago

Okay, somewhat of progress to understand this.

I've updated conf to be:

  "shell": {
    "with_arguments": {
      "program": "/run/current-system/sw/bin/fish",
      "args": ["--login"]
    }
  },

but that is probably a red herring, I've used "arguments" instead of "args" for quite some time in my dotfiles and I guess the args hasn't been working, but this new problem seems to be something else.

I'm starting zed from terminal. Up till last week this worked fine, but is now broken if I start zed from any folder that is direnv:ed . I typically use direnv and nix/devenv with flakes on all my dev folders. This was working fine up till last week or so.

Somewhat minified repro here: https://github.com/hedefalk/zed-devenv-issue

I'll repaste the readme I just wrote:

If I open zed from the root:

zed flaketest

things work fine.

If I instead:

cd flaketest
zed .

I get the following in a terminal:

bash: line 6: compgen: command not found
set: Tried to modify the special variable 'PWD' with the wrong scope
set: Tried to modify the special variable 'SHLVL' with the wrong scope
warning: Could not set up terminal.
warning: TERM environment variable not set.
warning: Using fallback terminal type 'xterm-256color'.
warning: Could not set up terminal.
warning: TERM environment variable not set.
warning: Using fallback terminal type 'xterm-256color'.
/nix/store/sk8z3kdy6iaky6sg972k6fkh3iw2rn3d-bash-5.2p37/bin/bash: line 1: env: command not found
/nix/store/sk8z3kdy6iaky6sg972k6fkh3iw2rn3d-bash-5.2p37/bin/bash: line 1: env: command not found
Error: $HOME must be set to run brew.
fish: Unknown command: starship
/Users/viktor/.config/fish/config.fish (line 25):
starship init fish | source
^~~~~~~^
from sourcing file /Users/viktor/.config/fish/config.fish
    called during startup
/nix/store/mmwqalliqz09swrrgiy8r4sf95v51rdq-any-nix-shell-2.0.1/bin/.any-nix-shell-wrapped: line 55: cat: command not found
/Users/viktor/dev/lightbend/kalix/infra-aws/scripts/aws-auth-functions.sh: line 8: dirname: command not found
bash: line 6: awk: command not found
bash: line 6: awk: command not found
bash: line 6: awk: command not found
direnv: error couldn't find a cache directory for direnv
@studio ~/U/v/d/z/flaketest (main)>

seems just like the entire env is broken.

An .envrc without nix flakes seems to work just fine:

cd nonflaketest
zed .

This was all working fine about a week ago.

If I open zed from the root:

zed flaketest

things work fine.

If I instead:

cd flaketest
zed .

I get the following in a terminal:

bash: line 6: compgen: command not found
set: Tried to modify the special variable 'PWD' with the wrong scope
set: Tried to modify the special variable 'SHLVL' with the wrong scope
warning: Could not set up terminal.
warning: TERM environment variable not set.
warning: Using fallback terminal type 'xterm-256color'.
warning: Could not set up terminal.
warning: TERM environment variable not set.
warning: Using fallback terminal type 'xterm-256color'.
/nix/store/sk8z3kdy6iaky6sg972k6fkh3iw2rn3d-bash-5.2p37/bin/bash: line 1: env: command not found
/nix/store/sk8z3kdy6iaky6sg972k6fkh3iw2rn3d-bash-5.2p37/bin/bash: line 1: env: command not found
Error: $HOME must be set to run brew.
fish: Unknown command: starship
/Users/viktor/.config/fish/config.fish (line 25):
starship init fish | source
^~~~~~~^
from sourcing file /Users/viktor/.config/fish/config.fish
    called during startup
/nix/store/mmwqalliqz09swrrgiy8r4sf95v51rdq-any-nix-shell-2.0.1/bin/.any-nix-shell-wrapped: line 55: cat: command not found
/Users/viktor/dev/lightbend/kalix/infra-aws/scripts/aws-auth-functions.sh: line 8: dirname: command not found
bash: line 6: awk: command not found
bash: line 6: awk: command not found
bash: line 6: awk: command not found
direnv: error couldn't find a cache directory for direnv
@studio ~/U/v/d/z/flaketest (main)>

seems just like the entire env is broken.

An .envrc without nix flakes seems to work just fine:

cd nonflaketest
zed .

This was all working fine about a week ago.

hedefalk commented 1 day ago

It's not the nix plugin. I've uninstalled that and problem remains:

image
hedefalk commented 1 day ago

For clarity, the .envrc is just:

watch_file flake/flake.nix
watch_file flake/flake.lock
use flake path:flake --impure

and the flake itself pretty minimal, I don't think its anything related to its content:

{
  description = "Viktor's Shell";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    systems.url = "github:nix-systems/default";
    devenv.url = "github:cachix/devenv";
  };
  outputs = {  nixpkgs, devenv, systems, ... } @ inputs:
    let
      forEachSystem = nixpkgs.lib.genAttrs (import systems);
    in
    {
      devShells = forEachSystem
        (system:
          let
            pkgs = nixpkgs.legacyPackages.${system};
          in
          {
            default = devenv.lib.mkShell
              {
                inherit inputs pkgs;
                modules = [
                  {
                    # https://devenv.sh/reference/options/
                    packages = [
                    ];
                  }
                ];
              };
          });
    };
}