nushell: Relative file resolution (FILE_PWD) not working in configs (env.nu, config.nu)

Describe the bug

My Nu config dir is symlinked to work around #893. I’m attempting to source-env default_env.nu to work around #7371. I’m seeing confusing error messages documented below.

I suspect there’s a bug and/or poor error message and/or misunderstanding on my part and/or all of the above ❓

First Attempt

# env.nu
source-env default_env.nu

Error

Error: nu::parser::sourced_file_not_found

  × File not found
   ╭─[/Users/texas/Library/Application Support/nushell/env.nu:1:1]
 1 │ source-env default_env.nu
   ·            ───────┬──────
   ·                   ╰── File not found: default_env.nu
   ╰────
  help: sourced files need to be available before your script is run

Same error with ./default_env.nu.

Context

> '/Users/texas/Library/Application Support/nushell/env.nu'
➜ | path join .. default_env.nu
➜ | ls --long $in
➜ | reject name
╭─────┬────────┬──────────┬────────────┬─────────────┬─────────────┬────────────┬────────┬────────┬──────────┬─────────────┬─────────────┬─────────────╮
│   # │  type  │  target  │  readonly  │    mode     │  num_links  │   inode    │  user  │ group  │   size   │   created   │  accessed   │  modified   │
├─────┼────────┼──────────┼────────────┼─────────────┼─────────────┼────────────┼────────┼────────┼──────────┼─────────────┼─────────────┼─────────────┤
│   0 │ file   │          │ false      │ rw-r--r--   │           1 │  110565660 │ texas  │ staff  │  4.3 KiB │ 2 days ago  │ 2 days ago  │ 2 days ago  │
╰─────┴────────┴──────────┴────────────┴─────────────┴─────────────┴────────────┴────────┴────────┴──────────┴─────────────┴─────────────┴─────────────╯

Aside: I was surprised I couldn’t pipe to ls.

Second Attempt

Supposing it was related to symlinks I tried to expand it.

# env.nu
source-env (default_env.nu | path expand)

Error

Error:   × Error: nu::shell::not_a_constant
  │ 
  │   × Not a constant.
  │    ╭─[/Users/texas/Library/Application Support/nushell/env.nu:1:1]
  │  1 │ source-env (default_env.nu | path expand)
  │    ·             ───────┬──────
  │    ·                    ╰── Value is not a parse-time constant
  │    ╰────
  │   help: Only a subset of expressions are allowed constants during parsing. Try using the 'const' command or typing the value literally.
  │ 
   ╭─[/Users/texas/Library/Application Support/nushell/env.nu:1:1]
 1 │ source-env (default_env.nu | path expand)
   ·            ───────────────┬──────────────
   ·                           ╰── Encountered error during parse-time evaluation
   ╰────

Same error with ./default_env.nu or assigning it to a const.

Final Attempt

I tried quoting it but it resolved relative to $env.PWD. That’s entirely reasonable since source isn’t doing the expansion.

# env.nu
source-env ('default_env.nu' | path expand)

Error

Error: nu::parser::sourced_file_not_found

  × File not found
   ╭─[/Users/texas/Library/Application Support/nushell/env.nu:1:1]
 1 │ source-env ('default_env.nu' | path expand)
   ·            ────────────────┬───────────────
   ·                            ╰── File not found: /Users/texas/default_env.nu
   ╰────
  help: sourced files need to be available before your script is run

Same error with './default_env.nu'.

Info

How to reproduce

Haven’t identified the root cause yet.

Expected behavior

Expect to load.

Screenshots

No response

Configuration

key value
version 0.88.1
branch
commit_hash
build_os macos-x86_64
build_target x86_64-apple-darwin
rust_version rustc 1.74.0 (79e9716c9 2023-11-13) (Homebrew)
cargo_version cargo 1.74.0
build_time 2023-12-14 17:14:47 +00:00
build_rust_channel release
allocator mimalloc
features dataframe, default, sqlite, trash, which, zip
installed_plugins

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 6 months ago
  • Comments: 20 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Yeah, I can reproduce it. Seems like the start file is not set correctly when evaluating the config files. This should be an easy fix: Add start_in_file() calls to the appropriate locations (see my previous comment).