summary refs log tree commit diff
diff options
context:
space:
mode:
authorArtturi <Artturin@artturin.com>2022-05-01 23:06:17 +0300
committerGitHub <noreply@github.com>2022-05-01 23:06:17 +0300
commita5357d06e40916b34a37782fcfa18b0fb6a645c0 (patch)
tree9bd50e63740dbaea523e78ad09e07d7bcb7d0c1f
parent917617801df8b1aabdca0aef0df47cab595a29c0 (diff)
parent3f128cc0247a95cfdcbb34a96c230422706b1715 (diff)
downloadnixpkgs-a5357d06e40916b34a37782fcfa18b0fb6a645c0.tar
nixpkgs-a5357d06e40916b34a37782fcfa18b0fb6a645c0.tar.gz
nixpkgs-a5357d06e40916b34a37782fcfa18b0fb6a645c0.tar.bz2
nixpkgs-a5357d06e40916b34a37782fcfa18b0fb6a645c0.tar.lz
nixpkgs-a5357d06e40916b34a37782fcfa18b0fb6a645c0.tar.xz
nixpkgs-a5357d06e40916b34a37782fcfa18b0fb6a645c0.tar.zst
nixpkgs-a5357d06e40916b34a37782fcfa18b0fb6a645c0.zip
Merge pull request #167947 from MatthewCroughan/mc/callLocklessFlake
lib: add callLocklessFlake
-rw-r--r--lib/default.nix4
-rw-r--r--lib/flakes.nix22
-rw-r--r--lib/tests/flakes/subflakeTest/flake.nix8
-rw-r--r--lib/tests/flakes/subflakeTest/subflake/flake.nix5
-rw-r--r--lib/tests/misc.nix9
5 files changed, 48 insertions, 0 deletions
diff --git a/lib/default.nix b/lib/default.nix
index e919509e724..22eb5440c28 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -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;
@@ -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
diff --git a/lib/flakes.nix b/lib/flakes.nix
new file mode 100644
index 00000000000..4dc027b6c9b
--- /dev/null
+++ b/lib/flakes.nix
@@ -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;
+
+}
diff --git a/lib/tests/flakes/subflakeTest/flake.nix b/lib/tests/flakes/subflakeTest/flake.nix
new file mode 100644
index 00000000000..3a8edd5e8c5
--- /dev/null
+++ b/lib/tests/flakes/subflakeTest/flake.nix
@@ -0,0 +1,8 @@
+{
+  outputs = { self, subflake, callLocklessFlake }: rec {
+    x = (callLocklessFlake {
+      path = subflake;
+      inputs = {};
+    }).subflakeOutput;
+  };
+}
diff --git a/lib/tests/flakes/subflakeTest/subflake/flake.nix b/lib/tests/flakes/subflakeTest/subflake/flake.nix
new file mode 100644
index 00000000000..41566b52090
--- /dev/null
+++ b/lib/tests/flakes/subflakeTest/subflake/flake.nix
@@ -0,0 +1,5 @@
+{
+  outputs = { self }: {
+    subflakeOutput = 1;
+  };
+}
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index c5d1d431677..f7e62a71eee 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -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