From e1821f1076a085e58dd23de4015f5c86c1aeb6c2 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 1 Sep 2026 18:38:55 +0200 Subject: [PATCH 1/2] feat: allow passing self.outPath via sources. Andd set it to `root` when using `from.*`` functions. Previously outPath had to be set manually, even though with-inputs already know it when using `from.*`.` --- default.nix | 16 +++++++++------- tests.nix | 8 ++++++++ with-inputs.nix | 14 +++++++++----- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/default.nix b/default.nix index e3cefee..577be16 100644 --- a/default.nix +++ b/default.nix @@ -18,9 +18,11 @@ let __functor = allInputs: outputs: f.__functor allInputs (may-import outputs); }; - from.niv = root: with-inputs (root + "/nix/sources.nix"); + with-inputs' = root: sources: with-inputs (may-import sources // { self.outPath = root; }); - from.npins = root: with-inputs (root + "/npins"); + from.niv = root: with-inputs' root (root + "/nix/sources.nix"); + + from.npins = root: with-inputs' root (root + "/npins"); from.lon = root: @@ -28,9 +30,9 @@ let lon = import (root + "/lon.nix"); sources = builtins.mapAttrs (_: outPath: { inherit outPath; }) lon; in - with-inputs sources; + with-inputs' root sources; - from.unflake = root: with-inputs (root + "/unflake.nix"); + from.unflake = root: with-inputs' root (import (root + "/unflake.nix")); from.tack = root: @@ -130,9 +132,9 @@ let ) (builtins.attrNames allFollow) ); in - with-inputs (pinned // aliases); + with-inputs' root (pinned // aliases); - from.nixtamal = root: with-inputs (import (root + "/nix/tamal") { }); + from.nixtamal = root: with-inputs' root (import (root + "/nix/tamal") { }); from.flake = root: @@ -156,7 +158,7 @@ let } .${node.locked.type}; in - with-inputs sources; + with-inputs' root sources; in { diff --git a/tests.nix b/tests.nix index ab4e644..dc85ecb 100644 --- a/tests.nix +++ b/tests.nix @@ -259,6 +259,14 @@ in expected = true; }; + functor-self.test-outputs-function-receives-inputs-with-self-outPath = { + expr = + (with-inputs { self.outPath = ./.; } { } (inputs: { + selfOutPath = inputs.self.outPath; + })).selfOutPath; + expected = ./.; + }; + functor-self.test-inputs-is-the-with-inputs-attrset = { expr = (with-inputs { foo = mkSrc "/foo"; } { } (_: { })).inputs.foo.outPath; expected = "/foo"; diff --git a/with-inputs.nix b/with-inputs.nix index 6ec90d7..c449c81 100644 --- a/with-inputs.nix +++ b/with-inputs.nix @@ -165,7 +165,8 @@ let in self; - resolvedSources = builtins.mapAttrs mkInput sources; + selfSources = sources.self or { }; + resolvedSources = builtins.mapAttrs mkInput (builtins.removeAttrs sources [ "self" ]); # Shallow merge is correct: each key is fully resolved before this point. # Sub-input overrides (inputs.foo.inputs.bar.follows) are injected into # resolvedSources at resolution time via overrideSubSpec, so no deep merge @@ -184,10 +185,13 @@ let outputs = outputsFn inputs; # self exposes .inputs, .outputs and ._type like a real flake self, with all # output attributes merged at top level for direct attribute access. - self = outputs // { - inherit inputs outputs; - _type = "flake"; - }; + self = + selfSources + // outputs + // { + inherit inputs outputs; + _type = "flake"; + }; in self; From 16bc4b52ba763f3d1064873ed70a6579fbaa40b6 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 1 Sep 2026 18:59:23 +0200 Subject: [PATCH 2/2] feat: automatically remove `self` from `inputsOverrides` to simplify usage as real flake. --- fixtures/with-inputs-flake/flake.nix | 2 +- with-inputs.nix | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fixtures/with-inputs-flake/flake.nix b/fixtures/with-inputs-flake/flake.nix index 3ea9e28..4a3f569 100644 --- a/fixtures/with-inputs-flake/flake.nix +++ b/fixtures/with-inputs-flake/flake.nix @@ -1 +1 @@ -{ outputs = inputs: import ./. { inputsOverrides = removeAttrs inputs [ "self" ]; }; } +{ outputs = inputsOverrides: import ./. { inherit inputsOverrides; }; } diff --git a/with-inputs.nix b/with-inputs.nix index c449c81..dedc559 100644 --- a/with-inputs.nix +++ b/with-inputs.nix @@ -16,7 +16,11 @@ sources: inputsOverrides: let inputs = let - f = io: if builtins.isAttrs io then io else (__functor allInputs io).outputs; + f = + io: + builtins.removeAttrs (if builtins.isAttrs io then io else (__functor allInputs io).outputs) [ + "self" + ]; in if builtins.isList inputsOverrides then builtins.foldl' (x: y: x // (f y)) { } inputsOverrides