-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
builtins.getFlake: Support path values #15290
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| synopsis: "`builtins.getFlake` now supports path values" | ||
| prs: [15290] | ||
| --- | ||
|
|
||
| `builtins.getFlake` now accepts path values in addition to flakerefs, allowing you to write `builtins.getFlake ./subflake` instead of having to use ugly workarounds to construct a pure flakeref. | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -416,19 +416,15 @@ static LockFile readLockFile(const fetchers::Settings & fetchSettings, const Sou | |||||
| : LockFile(); | ||||||
| } | ||||||
|
|
||||||
| /* Compute an in-memory lock file for the specified top-level flake, | ||||||
| and optionally write it to file, if the flake is writable. */ | ||||||
| LockedFlake | ||||||
| lockFlake(const Settings & settings, EvalState & state, const FlakeRef & topRef, const LockFlags & lockFlags) | ||||||
| LockedFlake lockFlake( | ||||||
| const Settings & settings, EvalState & state, const FlakeRef & topRef, const LockFlags & lockFlags, Flake flake) | ||||||
| { | ||||||
| experimentalFeatureSettings.require(Xp::Flakes); | ||||||
|
|
||||||
| auto useRegistries = lockFlags.useRegistries.value_or(settings.useRegistries); | ||||||
| auto useRegistriesTop = useRegistries ? fetchers::UseRegistries::All : fetchers::UseRegistries::No; | ||||||
| auto useRegistriesInputs = useRegistries ? fetchers::UseRegistries::Limited : fetchers::UseRegistries::No; | ||||||
|
|
||||||
| auto flake = getFlake(state, topRef, useRegistriesTop, {}); | ||||||
|
|
||||||
| if (lockFlags.applyNixConfig) { | ||||||
| flake.config.apply(settings); | ||||||
| state.store->setOptions(); | ||||||
|
|
@@ -908,6 +904,22 @@ lockFlake(const Settings & settings, EvalState & state, const FlakeRef & topRef, | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| LockedFlake | ||||||
| lockFlake(const Settings & settings, EvalState & state, const FlakeRef & topRef, const LockFlags & lockFlags) | ||||||
| { | ||||||
| auto useRegistries = lockFlags.useRegistries.value_or(settings.useRegistries); | ||||||
| auto useRegistriesTop = useRegistries ? fetchers::UseRegistries::All : fetchers::UseRegistries::No; | ||||||
| return lockFlake(settings, state, topRef, lockFlags, getFlake(state, topRef, useRegistriesTop, {})); | ||||||
| } | ||||||
|
|
||||||
| LockedFlake | ||||||
| lockFlake(const Settings & settings, EvalState & state, const SourcePath & flakeDir, const LockFlags & lockFlags) | ||||||
| { | ||||||
| /* We need a fake flakeref to put in the `Flake` struct, but it's not used for anything. */ | ||||||
| auto fakeRef = parseFlakeRef(state.fetchSettings, "flake:get-flake"); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose this simply might not fly and isn't worth changing, but if it does work,
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately that doesn't work because it's not a support input scheme: |
||||||
| return lockFlake(settings, state, fakeRef, lockFlags, readFlake(state, fakeRef, fakeRef, fakeRef, flakeDir, {})); | ||||||
| } | ||||||
|
|
||||||
| static ref<SourceAccessor> makeInternalFS() | ||||||
| { | ||||||
| auto internalFS = make_ref<MemorySourceAccessor>(MemorySourceAccessor{}); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,8 @@ writeSimpleFlake() { | |
| baseName = builtins.baseNameOf ./.; | ||
|
|
||
| root = ./.; | ||
|
|
||
| number = 123; | ||
| }; | ||
| } | ||
| EOF | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| source ./common.sh | ||
|
|
||
| createFlake1 | ||
|
|
||
| mkdir -p "$flake1Dir/subflake" | ||
| cat > "$flake1Dir/subflake/flake.nix" <<EOF | ||
| { | ||
| outputs = { self }: | ||
| let | ||
| # Bad, legacy way of getting a flake from an input. | ||
| parentFlake = builtins.getFlake (builtins.flakeRefToString { type = "path"; path = self.sourceInfo.outPath; narHash = self.narHash; }); | ||
| # Better way using a path value. | ||
| parentFlake2 = builtins.getFlake ./..; | ||
| in { | ||
| x = parentFlake.number; | ||
| y = parentFlake2.number; | ||
| }; | ||
| } | ||
| EOF | ||
| git -C "$flake1Dir" add subflake/flake.nix | ||
|
|
||
| [[ $(nix eval "$flake1Dir/subflake#x") = 123 ]] | ||
|
|
||
| [[ $(nix eval "$flake1Dir/subflake#y") = 123 ]] |
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.
"Subflake" has not been defined and only used informally. So far we've kept even the informal use out of the manual, which is a good thing in case we want to ever define it.