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/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/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..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 @@ -165,7 +169,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 +189,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;