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

resolve TempDir paths before passing them to the flake bin #233

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

valkum
Copy link
Contributor

@valkum valkum commented Oct 24, 2024

On macOS /tmp is a symlink to /private/tmp.
TempDir creates a dir and returns the path as /tmp/.... nix is unhappy with symlink dirs when calling nix flake metadata --json path:...

error (ignored): error: end of string reached
error:
       … while fetching the input 'path:/tmp/colmena-assets-XHHAXJ'

       error: path '/tmp' is a symlink
thread 'main' panicked at src/cli.rs:286:38:
Failed to get flake or hive: ChildFailure { exit_code: 1, backtrace:    0: backtrace::capture::Backtrace::new
   1: colmena::nix::flake::FlakeMetadata::resolve::{{closure}}
   2: colmena::nix::flake::Flake::from_uri::{{closure}}
   3: colmena::cli::run::{{closure}}
   4: tokio::runtime::park::CachedParkThread::block_on
   5: colmena::main
   6: std::sys_common::backtrace::__rust_begin_short_backtrace
   7: std::rt::lang_start::{{closure}}
   8: std::panicking::try
   9: std::rt::lang_start_internal
  10: _main
 }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

To fix this we canonicalize the path first, resolving any symlinks on the way.

@valkum
Copy link
Contributor Author

valkum commented Oct 24, 2024

Regarding the CI test failures: These are also present on main!

@@ -51,7 +51,10 @@ impl Assets {
// We explicitly specify `path:` instead of letting Nix resolve
// automatically, which would involve checking parent directories
// for a git repository.
let uri = format!("path:{}", temp_dir.path().to_str().unwrap());
let uri = format!(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a few usages of this: #236

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if those are relevant, but my thinking was that it might resolve other future regressions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this near the point where the data (the temp path) leaves our control as this isn't a bug in the Rust side of things but at the boundary to a different system.
This only affects paths that we pass to nix (so ideally we would canonicalize the paths in FlakeMetadata::resolve). We could do that by passing something like a FlakePath to that function instead of the str.

enum FlakePath<'s> {
Path(&'s Path),
Git(&'s str)
}

<Display impl that canonicalizes before creating the `path:{}` string>

This would allow us to keep the simple temp dir paths in places where it could get debug printed without causing any irritation why the tmp dir looks weird. The symlinks for tempdirs on macos are an implementation detail and should not be exposed in level-1 debug output (such as a dbg!()) print, IMHO.

On MacOS /tmp is a symlink to /private/tmp.
TempDir creates a dir and returns the path as /tmp.
nix is unhappy with symlink dirs when calling nix flake metadata --json

To fix this we canonicalize the path first, resolving any symlinks on the way.

Fixes zhaofengli#190.
Sadly it breaks CI in fork-originated PRs if the author doesn't enable
Actions on the fork itself.

This reverts commit ce1aa41.
Copy link
Owner

@zhaofengli zhaofengli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested that it fixes evaluation on macOS. Will add a test to keep it working later.

@zhaofengli zhaofengli enabled auto-merge November 8, 2024 18:34
@zhaofengli zhaofengli merged commit 6821976 into zhaofengli:main Nov 8, 2024
17 checks passed
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

Successfully merging this pull request may close these issues.

3 participants