1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 06:31:14 +02:00
This commit is contained in:
Jörg Thalheim 2025-06-13 05:06:53 +00:00 committed by GitHub
commit 952cece5dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 68 additions and 6 deletions

View file

@ -45,7 +45,8 @@ struct Registry
void add( void add(
const Input & from, const Input & from,
const Input & to, const Input & to,
const Attrs & extraAttrs); const Attrs & extraAttrs,
bool exact);
void remove(const Input & input); void remove(const Input & input);
}; };

View file

@ -84,13 +84,15 @@ void Registry::write(const Path & path)
void Registry::add( void Registry::add(
const Input & from, const Input & from,
const Input & to, const Input & to,
const Attrs & extraAttrs) const Attrs & extraAttrs,
bool exact)
{ {
entries.emplace_back( entries.emplace_back(
Entry { Entry {
.from = from, .from = from,
.to = to, .to = to,
.extraAttrs = extraAttrs .extraAttrs = extraAttrs,
.exact = exact
}); });
} }
@ -144,7 +146,7 @@ void overrideRegistry(
const Input & to, const Input & to,
const Attrs & extraAttrs) const Attrs & extraAttrs)
{ {
getFlagRegistry(*from.settings)->add(from, to, extraAttrs); getFlagRegistry(*from.settings)->add(from, to, extraAttrs, false);
} }
static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, ref<Store> store) static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, ref<Store> store)

View file

@ -115,7 +115,7 @@ struct CmdRegistryAdd : MixEvalArgs, Command, RegistryCommand
fetchers::Attrs extraAttrs; fetchers::Attrs extraAttrs;
if (toRef.subdir != "") extraAttrs["dir"] = toRef.subdir; if (toRef.subdir != "") extraAttrs["dir"] = toRef.subdir;
registry->remove(fromRef.input); registry->remove(fromRef.input);
registry->add(fromRef.input, toRef.input, extraAttrs); registry->add(fromRef.input, toRef.input, extraAttrs, false);
registry->write(getRegistryPath()); registry->write(getRegistryPath());
} }
}; };
@ -193,7 +193,7 @@ struct CmdRegistryPin : RegistryCommand, EvalCommand
warn("flake '%s' is not locked", resolved.to_string()); warn("flake '%s' is not locked", resolved.to_string());
fetchers::Attrs extraAttrs; fetchers::Attrs extraAttrs;
if (ref.subdir != "") extraAttrs["dir"] = ref.subdir; if (ref.subdir != "") extraAttrs["dir"] = ref.subdir;
registry->add(ref.input, resolved, extraAttrs); registry->add(ref.input, resolved, extraAttrs, true);
registry->write(getRegistryPath()); registry->write(getRegistryPath());
} }
}; };

View file

@ -3,6 +3,7 @@ suites += {
'deps': [], 'deps': [],
'tests': [ 'tests': [
'flakes.sh', 'flakes.sh',
'registry-pin.sh',
'develop.sh', 'develop.sh',
'edit.sh', 'edit.sh',
'run.sh', 'run.sh',

View file

@ -0,0 +1,58 @@
#!/usr/bin/env bash
source ./common.sh
TODO_NixOS
requireGit
clearStore
rm -rf "$TEST_HOME/.cache" "$TEST_HOME/.config"
createFlake1
# Add a branch in flake1.
git -C "$flake1Dir" checkout -b branch1
echo > "$flake1Dir/some-file"
git -C "$flake1Dir" add "$flake1Dir/some-file"
git -C "$flake1Dir" commit -m 'Some change'
git -C "$flake1Dir" checkout master
nix registry add --registry "$registry" flake1 "git+file://$flake1Dir"
commit=$(nix flake metadata "git+file://$flake1Dir" --json | jq -r '.revision')
commit2=$(nix flake metadata "git+file://$flake1Dir?ref=refs/heads/branch1" --json | jq -r '.revision')
[[ "$commit" != "$commit2" ]]
nix registry list | grepQuiet '^global' # global flake1
commit=$(nix flake metadata flake1 --json | jq -r '.revision')
commit2=$(nix flake metadata flake1/branch1 --json | jq -r '.revision')
nix build -o "$TEST_ROOT/result" flake1#root
find "$TEST_ROOT/result/" | grepInverse some-file
nix build -o "$TEST_ROOT/result" flake1/branch1#root
find "$TEST_ROOT/result/" | grepQuiet some-file
[[ "$commit" != "$commit2" ]]
nix registry pin flake1
# new output something like:
# user flake:flake1 git+file:///tmp/nix-test/flakes/registry-pin/flake1?ref=refs/heads/master&rev=c55c61f18fa23762b1dc700af6f33af012ec6772
# global flake:flake1 git+file:///tmp/nix-test/flakes/registry-pin/flake1
nix registry list | grepQuiet '^global' # global flake1
nix registry list | grepQuiet '^user' # user flake1
nix registry remove --registry "$registry" flake1
nix build -o "$TEST_ROOT/result" flake1#root
find "$TEST_ROOT/result/" | grepInverse some-file
nix build -o "$TEST_ROOT/result" flake1/branch1#root
find "$TEST_ROOT/result/" | grepQuiet some-file
commit=$(nix flake metadata flake1 --json | jq -r '.revision')
# overriding the branch does still work
commit2=$(nix flake metadata flake1/branch1 --json | jq -r '.revision')
[[ "$commit" != "$commit2" ]]
nix registry remove flake1
nix registry list | grepInverse '^user' # no more pinned flake1
nix registry list | grepQuiet '^global' # global flake1 is still there