Skip to content
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

lib: add callLocklessFlake #167947

Merged
merged 5 commits into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ let
callLibs = file: import file { lib = self; };
in {

# interacting with flakes
flakes = callLibs ./flakes.nix;

# often used, or depending on very little
trivial = callLibs ./trivial.nix;
fixedPoints = callLibs ./fixed-points.nix;
Expand Down Expand Up @@ -59,6 +62,7 @@ let
# linux kernel configuration
kernel = callLibs ./kernel.nix;

inherit (self.flakes) callLocklessFlake;
inherit (builtins) add addErrorContext attrNames concatLists
deepSeq elem elemAt filter genericClosure genList getAttr
hasAttr head isAttrs isBool isInt isList isString length
Expand Down
22 changes: 22 additions & 0 deletions lib/flakes.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{ lib }:

rec {

/* imports a flake.nix without acknowledging its lock file, useful for
referencing subflakes from a parent flake. The second argument allows
specifying the inputs of this flake.

Example:
callLocklessFlake {
path = ./directoryContainingFlake;
inputs = { inherit nixpkgs; };
}
*/
callLocklessFlake = { path, inputs ? { } }:
let
self = { outPath = path; } //
((import (path + "/flake.nix")).outputs (inputs // { self = self; }));
in
self;

}
8 changes: 8 additions & 0 deletions lib/tests/flakes/subflakeTest/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
outputs = { self, subflake, callLocklessFlake }: rec {
x = (callLocklessFlake {
path = subflake;
inputs = {};
}).subflakeOutput;
};
}
5 changes: 5 additions & 0 deletions lib/tests/flakes/subflakeTest/subflake/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
outputs = { self }: {
subflakeOutput = 1;
};
}
9 changes: 9 additions & 0 deletions lib/tests/misc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ in

runTests {

# FLAKES

testCallLocklessFlake = {
expr = callLocklessFlake {
path = ./flakes/subflakeTest;
inputs = { subflake = ./flakes/subflakeTest/subflake; inherit callLocklessFlake; };
};
expected = { x = 1; outPath = ./flakes/subflakeTest; };
};

# TRIVIAL

Expand Down