Skip to content
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
16 changes: 9 additions & 7 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ 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:
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:
Expand Down Expand Up @@ -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:
Expand All @@ -156,7 +158,7 @@ let
}
.${node.locked.type};
in
with-inputs sources;
with-inputs' root sources;

in
{
Expand Down
2 changes: 1 addition & 1 deletion fixtures/with-inputs-flake/flake.nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ outputs = inputs: import ./. { inputsOverrides = removeAttrs inputs [ "self" ]; }; }
{ outputs = inputsOverrides: import ./. { inherit inputsOverrides; }; }
8 changes: 8 additions & 0 deletions tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
20 changes: 14 additions & 6 deletions with-inputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand Down
Loading