mirror of
https://github.com/NixOS/nix.git
synced 2024-11-22 06:42:28 +00:00
Merge pull request #11447 from DeterminateSystems/nix-flake-metadata-chroot-store
nix flake {metadata,archive}: Fix chroot stores
This commit is contained in:
commit
894da59186
@ -751,6 +751,21 @@ LockedFlake lockFlake(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<StorePath, Path> sourcePathToStorePath(
|
||||||
|
ref<Store> store,
|
||||||
|
const SourcePath & _path)
|
||||||
|
{
|
||||||
|
auto path = _path.path.abs();
|
||||||
|
|
||||||
|
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>()) {
|
||||||
|
auto realStoreDir = store2->getRealStoreDir();
|
||||||
|
if (isInDir(path, realStoreDir))
|
||||||
|
path = store2->storeDir + path.substr(realStoreDir.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
return store->toStorePath(path);
|
||||||
|
}
|
||||||
|
|
||||||
void callFlake(EvalState & state,
|
void callFlake(EvalState & state,
|
||||||
const LockedFlake & lockedFlake,
|
const LockedFlake & lockedFlake,
|
||||||
Value & vRes)
|
Value & vRes)
|
||||||
@ -768,17 +783,7 @@ void callFlake(EvalState & state,
|
|||||||
|
|
||||||
auto lockedNode = node.dynamic_pointer_cast<const LockedNode>();
|
auto lockedNode = node.dynamic_pointer_cast<const LockedNode>();
|
||||||
|
|
||||||
// FIXME: This is a hack to support chroot stores. Remove this
|
auto [storePath, subdir] = sourcePathToStorePath(state.store, sourcePath);
|
||||||
// once we can pass a sourcePath rather than a storePath to
|
|
||||||
// call-flake.nix.
|
|
||||||
auto path = sourcePath.path.abs();
|
|
||||||
if (auto store = state.store.dynamic_pointer_cast<LocalFSStore>()) {
|
|
||||||
auto realStoreDir = store->getRealStoreDir();
|
|
||||||
if (isInDir(path, realStoreDir))
|
|
||||||
path = store->storeDir + path.substr(realStoreDir.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
auto [storePath, subdir] = state.store->toStorePath(path);
|
|
||||||
|
|
||||||
emitTreeAttrs(
|
emitTreeAttrs(
|
||||||
state,
|
state,
|
||||||
|
@ -214,6 +214,16 @@ void callFlake(
|
|||||||
const LockedFlake & lockedFlake,
|
const LockedFlake & lockedFlake,
|
||||||
Value & v);
|
Value & v);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map a `SourcePath` to the corresponding store path. This is a
|
||||||
|
* temporary hack to support chroot stores while we don't have full
|
||||||
|
* lazy trees. FIXME: Remove this once we can pass a sourcePath rather
|
||||||
|
* than a storePath to call-flake.nix.
|
||||||
|
*/
|
||||||
|
std::pair<StorePath, Path> sourcePathToStorePath(
|
||||||
|
ref<Store> store,
|
||||||
|
const SourcePath & path);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void emitTreeAttrs(
|
void emitTreeAttrs(
|
||||||
|
@ -214,7 +214,7 @@ struct CmdFlakeMetadata : FlakeCommand, MixJSON
|
|||||||
auto & flake = lockedFlake.flake;
|
auto & flake = lockedFlake.flake;
|
||||||
|
|
||||||
// Currently, all flakes are in the Nix store via the rootFS accessor.
|
// Currently, all flakes are in the Nix store via the rootFS accessor.
|
||||||
auto storePath = store->printStorePath(store->toStorePath(flake.path.path.abs()).first);
|
auto storePath = store->printStorePath(sourcePathToStorePath(store, flake.path).first);
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
nlohmann::json j;
|
nlohmann::json j;
|
||||||
@ -1079,7 +1079,7 @@ struct CmdFlakeArchive : FlakeCommand, MixJSON, MixDryRun
|
|||||||
|
|
||||||
StorePathSet sources;
|
StorePathSet sources;
|
||||||
|
|
||||||
auto storePath = store->toStorePath(flake.flake.path.path.abs()).first;
|
auto storePath = sourcePathToStorePath(store, flake.flake.path).first;
|
||||||
|
|
||||||
sources.insert(storePath);
|
sources.insert(storePath);
|
||||||
|
|
||||||
|
@ -184,6 +184,9 @@ nix registry list | grepInverse '^user' # nothing in user registry
|
|||||||
nix flake metadata flake1
|
nix flake metadata flake1
|
||||||
nix flake metadata flake1 | grepQuiet 'Locked URL:.*flake1.*'
|
nix flake metadata flake1 | grepQuiet 'Locked URL:.*flake1.*'
|
||||||
|
|
||||||
|
# Test 'nix flake metadata' on a chroot store.
|
||||||
|
nix flake metadata --store $TEST_ROOT/chroot-store flake1
|
||||||
|
|
||||||
# Test 'nix flake metadata' on a local flake.
|
# Test 'nix flake metadata' on a local flake.
|
||||||
(cd "$flake1Dir" && nix flake metadata) | grepQuiet 'URL:.*flake1.*'
|
(cd "$flake1Dir" && nix flake metadata) | grepQuiet 'URL:.*flake1.*'
|
||||||
(cd "$flake1Dir" && nix flake metadata .) | grepQuiet 'URL:.*flake1.*'
|
(cd "$flake1Dir" && nix flake metadata .) | grepQuiet 'URL:.*flake1.*'
|
||||||
|
Loading…
Reference in New Issue
Block a user