From e1a817fb1bd8e622172800258000820d7d0c8092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 31 May 2024 10:38:55 +0200 Subject: [PATCH 1/2] fix nix edit in pure mode FilteringSourceAccessor was not delegating getPhysicalPath to its inner accessor. --- src/libfetchers/filtering-source-accessor.cc | 6 ++++++ src/libfetchers/filtering-source-accessor.hh | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/libfetchers/filtering-source-accessor.cc b/src/libfetchers/filtering-source-accessor.cc index dfd9e536d..d4557b6d4 100644 --- a/src/libfetchers/filtering-source-accessor.cc +++ b/src/libfetchers/filtering-source-accessor.cc @@ -2,6 +2,12 @@ namespace nix { +std::optional FilteringSourceAccessor::getPhysicalPath(const CanonPath & path) +{ + checkAccess(path); + return next->getPhysicalPath(prefix / path); +} + std::string FilteringSourceAccessor::readFile(const CanonPath & path) { checkAccess(path); diff --git a/src/libfetchers/filtering-source-accessor.hh b/src/libfetchers/filtering-source-accessor.hh index 9ec7bc21f..1f8d84e53 100644 --- a/src/libfetchers/filtering-source-accessor.hh +++ b/src/libfetchers/filtering-source-accessor.hh @@ -30,6 +30,8 @@ struct FilteringSourceAccessor : SourceAccessor displayPrefix.clear(); } + std::optional getPhysicalPath(const CanonPath & path) override; + std::string readFile(const CanonPath & path) override; bool pathExists(const CanonPath & path) override; From 69c159811ea280836d01f2968ae1c7bf3bda1a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 31 May 2024 11:04:50 +0200 Subject: [PATCH 2/2] add regression test for nix edit --- tests/functional/flakes/edit.sh | 13 +++++++++++++ tests/functional/local.mk | 1 + tests/functional/simple.nix | 1 + 3 files changed, 15 insertions(+) create mode 100755 tests/functional/flakes/edit.sh diff --git a/tests/functional/flakes/edit.sh b/tests/functional/flakes/edit.sh new file mode 100755 index 000000000..0fdf8b95a --- /dev/null +++ b/tests/functional/flakes/edit.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +source ./common.sh + +requireGit + +flake1Dir=$TEST_ROOT/flake1 + +createGitRepo "$flake1Dir" +createSimpleGitFlake "$flake1Dir" + +export EDITOR=cat +nix edit "$flake1Dir#" | grepQuiet simple.builder.sh diff --git a/tests/functional/local.mk b/tests/functional/local.mk index a94c5712c..5be2cddb2 100644 --- a/tests/functional/local.mk +++ b/tests/functional/local.mk @@ -2,6 +2,7 @@ nix_tests = \ test-infra.sh \ flakes/flakes.sh \ flakes/develop.sh \ + flakes/edit.sh \ flakes/run.sh \ flakes/mercurial.sh \ flakes/circular.sh \ diff --git a/tests/functional/simple.nix b/tests/functional/simple.nix index 4223c0f23..2035ca294 100644 --- a/tests/functional/simple.nix +++ b/tests/functional/simple.nix @@ -5,4 +5,5 @@ mkDerivation { builder = ./simple.builder.sh; PATH = ""; goodPath = path; + meta.position = "${__curPos.file}:${toString __curPos.line}"; }