mirror of
https://github.com/NixOS/nix
synced 2025-06-25 06:31:14 +02:00
Merge pull request #12028 from DeterminateSystems/fail-on-unlocked
nix flake lock: Fail if there is an unlocked input
This commit is contained in:
commit
2baab6412f
4 changed files with 11 additions and 0 deletions
|
@ -672,6 +672,8 @@ LockedFlake lockFlake(
|
||||||
if (lockFlags.writeLockFile) {
|
if (lockFlags.writeLockFile) {
|
||||||
if (sourcePath || lockFlags.outputLockFilePath) {
|
if (sourcePath || lockFlags.outputLockFilePath) {
|
||||||
if (auto unlockedInput = newLockFile.isUnlocked()) {
|
if (auto unlockedInput = newLockFile.isUnlocked()) {
|
||||||
|
if (lockFlags.failOnUnlocked)
|
||||||
|
throw Error("cannot write lock file of flake '%s' because it has an unlocked input ('%s').\n", topRef, *unlockedInput);
|
||||||
if (state.fetchSettings.warnDirty)
|
if (state.fetchSettings.warnDirty)
|
||||||
warn("will not write lock file of flake '%s' because it has an unlocked input ('%s')", topRef, *unlockedInput);
|
warn("will not write lock file of flake '%s' because it has an unlocked input ('%s')", topRef, *unlockedInput);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -156,6 +156,11 @@ struct LockFlags
|
||||||
*/
|
*/
|
||||||
bool writeLockFile = true;
|
bool writeLockFile = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throw an exception when the flake has an unlocked input.
|
||||||
|
*/
|
||||||
|
bool failOnUnlocked = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to use the registries to lookup indirect flake
|
* Whether to use the registries to lookup indirect flake
|
||||||
* references like 'nixpkgs'.
|
* references like 'nixpkgs'.
|
||||||
|
|
|
@ -162,6 +162,7 @@ struct CmdFlakeLock : FlakeCommand
|
||||||
settings.tarballTtl = 0;
|
settings.tarballTtl = 0;
|
||||||
|
|
||||||
lockFlags.writeLockFile = true;
|
lockFlags.writeLockFile = true;
|
||||||
|
lockFlags.failOnUnlocked = true;
|
||||||
lockFlags.applyNixConfig = true;
|
lockFlags.applyNixConfig = true;
|
||||||
|
|
||||||
lockFlake();
|
lockFlake();
|
||||||
|
|
|
@ -30,3 +30,6 @@ git -C "$flake2Dir" add flake.nix
|
||||||
echo 456 > "$flake1Dir"/x.nix
|
echo 456 > "$flake1Dir"/x.nix
|
||||||
|
|
||||||
[[ $(nix eval --json "$flake2Dir#x" --override-input flake1 "$TEST_ROOT/flake1") = 456 ]]
|
[[ $(nix eval --json "$flake2Dir#x" --override-input flake1 "$TEST_ROOT/flake1") = 456 ]]
|
||||||
|
|
||||||
|
expectStderr 1 nix flake lock "$flake2Dir" --override-input flake1 "$TEST_ROOT/flake1" |
|
||||||
|
grepQuiet "cannot write lock file.*because it has an unlocked input"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue