From 9046d46ba57b8b1232ba2464ae8a0d0200343af9 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Thu, 26 May 2022 10:15:33 +0200 Subject: [PATCH] import callLocklessFlake This function was added to nixpkgs in https://github.com/NixOS/nixpkgs/pull/167947 by MatthewCroughan. And later reverted because it's for unstable flakes. So let's add it here, since a lot of projects are already importing flake-utils. --- README.md | 14 ++++++++++++++ call-lockless-flake.nix | 16 ++++++++++++++++ default.nix | 2 ++ 3 files changed, 32 insertions(+) create mode 100644 call-lockless-flake.nix diff --git a/README.md b/README.md index a1b43f6..81e6df9 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,20 @@ Input: }: null ``` +### `callLocklessFlake -> { path, inputs ? { } } -> attrs` + +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; }; +} +``` + #### Example Here is how it looks like in practice: diff --git a/call-lockless-flake.nix b/call-lockless-flake.nix new file mode 100644 index 0000000..93a76ea --- /dev/null +++ b/call-lockless-flake.nix @@ -0,0 +1,16 @@ +/* + 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; }; + } +*/ +{ path, inputs ? { } }: +let + self = { outPath = path; } // + ((import (path + "/flake.nix")).outputs (inputs // { self = self; })); +in +self diff --git a/default.nix b/default.nix index 8c2c729..9735284 100644 --- a/default.nix +++ b/default.nix @@ -192,6 +192,8 @@ let # } filterPackages = import ./filterPackages.nix { inherit allSystems; }; + callLocklessFlake = import ./call-lockless-flake.nix; + # Returns the structure used by `nix app` mkApp = { drv