Skip to content

edit: Allow opening paths that don't exist on disk in EDITOR - #15686

Merged
Mic92 merged 1 commit into
masterfrom
edit-temp-paths
Apr 16, 2026
Merged

Mic92 merged 1 commit into
masterfrom
edit-temp-paths

Conversation

@xokdvium

Copy link
Copy Markdown
Contributor

Motivation

Since #14050 we now mount over the store paths in the rootFS accessor in the evaluator. This broke :e and nix edit on something like :e "${outPath}/src/nix-manual/utils.nix" when having the github:nixos/nix flake loaded in a --pure-eval repl. nix edit was also broken similarly with: because it has no physical path.

For regular files, we can copy the outputs into a temporary read-only file and open that instead. For directories, we could open a directory listing in the editor, but I haven't implemented that here. Copying the whole directory tree seems a bit wasteful to me, so we can't truthfully mimic the old behavior of :e on directories (that editors usually allow the user to traverse when opened).

This also implements some infrastructure for getting a writable file descriptor for the file that would get edited - I intend to use it for #15633.

Context

This got reported by @bryango in #14050 (comment).


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@xokdvium
xokdvium requested a review from edolstra as a code owner April 14, 2026 20:23
@github-actions github-actions Bot added new-cli Relating to the "nix" command with-tests Issues related to testing. PRs with tests have some priority repl The Read Eval Print Loop, "nix repl" command and debugger labels Apr 14, 2026
Comment thread src/nix/edit.cc
Comment on lines +47 to +57
auto [args, tempFd, delTemp] = editorFor(file, line, /*readOnly=*/true);
auto program = args.front();
args.pop_front();

runProgram2(
RunOptions{
.program = program,
.lookupPath = true,
.args = std::move(args),
.isInteractive = true,
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had to change this up because we need the destructor of delTemp to run if we want to clean up the temp files. This seems a bit nicer overall too.

@xokdvium
xokdvium force-pushed the edit-temp-paths branch 2 times, most recently from 61b97ef to 391ca2c Compare April 14, 2026 20:26
@xokdvium

Copy link
Copy Markdown
Contributor Author

This also has the nice effect of making this work too, which provides a really nice way of looking at the primitive operations that we bundle with in-memory files:

:e <nix/fetchurl.nix>
:e derivation

@xokdvium
xokdvium force-pushed the edit-temp-paths branch 2 times, most recently from 48740f5 to 530c1b4 Compare April 14, 2026 20:53
Since #14050 we now mount over the store
paths in the rootFS accessor in the evaluator. This broke :e and nix edit
on something like `:e "${outPath}/src/nix-manual/utils.nix"` when having the
`github:nixos/nix` flake loaded in a `--pure-eval` repl. `nix edit` was also
broken similarly with: `because it has no physical path`.

For regular files, we can copy the outputs into a temporary read-only file and open
that instead. For directories, we could open a directory listing in the editor, but
I haven't implemented that here. Copying the whole directory tree seems a bit wasteful
to me, so we can't truthfully mimic the old behavior of `:e` on directories (that editors
usually allow the user to traverse when opened).

This also implements some infrastructure for getting a writable file descriptor for the
file that would get edited - I intend to use it for #15633.
@xokdvium

Copy link
Copy Markdown
Contributor Author

Ok I think I fixed the mingw build now.

@Mic92
Mic92 added this pull request to the merge queue Apr 16, 2026
Merged via the queue into master with commit b05a6f3 Apr 16, 2026
20 checks passed
@Mic92
Mic92 deleted the edit-temp-paths branch April 16, 2026 12:42
@xokdvium xokdvium mentioned this pull request Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-cli Relating to the "nix" command repl The Read Eval Print Loop, "nix repl" command and debugger with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants