New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added flags to override the lockfile #2943
Conversation
tests/flakes.sh
Outdated
@@ -274,3 +274,5 @@ nix build -o $TEST_ROOT/result --flake-registry $registry flake3:sth | |||
mv $flake2Dir.tmp $flake2Dir | |||
mv $nonFlakeDir.tmp $nonFlakeDir | |||
nix build -o $TEST_ROOT/result --flake-registry $registry flake3:xyzzy flake3:fnord | |||
|
|||
(! nix build -o $TEST_ROOT/result --flake-registry $registry flake3:xyzzy --override-lockfile flake2 flake1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add some tests that succeed? Otherwise we won't notice if --override-lockfile
is completely broken :-)
src/nix/build.cc
Outdated
@@ -55,6 +55,7 @@ struct CmdBuild : MixDryRun, InstallablesCommand | |||
|
|||
auto evalState = std::make_shared<EvalState>(searchPath, store); | |||
evalState->addRegistryOverrides(registryOverrides); | |||
evalState->addLockFileOverrides(lockFileOverrides); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be changed to use getEvalState()
, then we don't need any special handling in CmdBuild
anymore.
src/libexpr/common-eval-args.cc
Outdated
.description("override a lockfile value") | ||
.arity(2) | ||
.handler([&](std::vector<std::string> ss) { | ||
lockFileOverrides.insert_or_assign(FlakeRef(ss[0]), FlakeRef(ss[1])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably should be added to EvalCommand
rather than MixEvalArgs
. The latter is also used by legacy commands (nix-env
etc) which don't implement flake-related stuff.
Fixed |
tests/config.nix
Outdated
PATH = path; | ||
} // removeAttrs args ["builder" "meta"]) | ||
// { meta = args.meta or {}; }; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/config.nix
added accidentally again. Feel free to add it to .gitignore
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently using --override-lockfile
causes the lockfile to be rewritten, which I think is not what we want. Otherwise you would just use --override-flake ... --recreate-lock-file
.
For example, in a clone of NixOS/nixos-homepage/flake
, I get:
$ /nix build --override-lockfile nixpkgs github:edolstra/nixpkgs/77baa898afa0fab609598a91dc150da825207d27
... some expected errors ...
$ git diff --staged
diff --git a/flake.lock b/flake.lock
index df97306..5281849 100644
--- a/flake.lock
+++ b/flake.lock
@@ -48,9 +48,9 @@
"nixpkgs": {
"id": "nixpkgs",
"inputs": {},
- "narHash": "sha256-HQ/wXOy6POACr5BIDoUeFYThgqHxtVfrXVQi95yIljw=",
+ "narHash": "sha256-/BKIFPqT2qqHCvaLXRxoEtMypIL/Hrg95SXGzwZkDmg=",
"nonFlakeInputs": {},
- "uri": "github:edolstra/nixpkgs/a0e1f50e6f72e5037d71a0b65c67cf0605349a06"
+ "uri": "github:edolstra/nixpkgs/77baa898afa0fab609598a91dc150da825207d27"
}
},
"nonFlakeInputs": {},
src/libexpr/common-eval-args.hh
Outdated
@@ -1,6 +1,7 @@ | |||
#pragma once | |||
|
|||
#include "args.hh" | |||
#include "flake/flakeref.hh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This #include
is unnecessary here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can take the import away here and add it to nix/command.hh
, where it's needed to define the registry and lockfile overrides in EvalCommand
.
@@ -6,6 +6,7 @@ | |||
#include "symbol-table.hh" | |||
#include "hash.hh" | |||
#include "config.hh" | |||
#include "flake/flakeref.hh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import is necessary here, the FlakeRef
concept is used now because registryOverrides
are stored in the EvalState
.
src/nix/installables.cc
Outdated
}); | ||
|
||
mkFlag() | ||
.longName("override-lockfile") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think --override-lock
is a better name, since we're overriding a specific lock, not an entire lockfile.
Fixes #2837