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
40 changes: 36 additions & 4 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ let
__functor = allInputs: outputs: f.__functor allInputs (may-import outputs);
};

with-inputs' = root: sources: with-inputs (may-import sources // { self.outPath = root; });
with-inputs' =
root: sources:
with-inputs (
may-import sources
// {
self = (root.sourceInfo or { }) // {
outPath = root.outPath or root;
};
}
);

from.niv = root: with-inputs' root (root + "/nix/sources.nix");

Expand Down Expand Up @@ -140,11 +149,12 @@ let
root:
let
lock = builtins.fromJSON (builtins.readFile (root + "/flake.lock"));
flake = import (root + "/flake.nix");
sources = builtins.mapAttrs fetch lock.nodes;

fetchedNodes = builtins.mapAttrs fetch lock.nodes;
fetch =
name: node:
(flake.inputs.${name} or { })
node.locked
// (if node ? flake then { inherit (node) flake; } else { })
// {
path.outPath = node.locked.path;
tarball.outPath = builtins.fetchTarball {
Expand All @@ -157,6 +167,28 @@ let
};
}
.${node.locked.type};

# Resolve a input spec into a node name. An input spec is
# either a node name, or a 'follows' path from the root
# node. Credit: https://github.com/NixOS/flake-compat
resolveInput =
inputSpec: if builtins.isList inputSpec then getInputByPath lock.root inputSpec else inputSpec;

# Follow an input path (e.g. ["dwarffs" "nixpkgs"]) from the
# root node, returning the final node. Credit: https://github.com/NixOS/flake-compat
getInputByPath =
nodeName: path:
if path == [ ] then
nodeName
else
getInputByPath
# Since this could be a 'follows' input, call resolveInput.
(resolveInput lock.nodes.${nodeName}.inputs.${builtins.head path})
(builtins.tail path);

sources = builtins.mapAttrs (
_: input: fetchedNodes.${resolveInput input}
) lock.nodes.${lock.root}.inputs;
in
with-inputs' root sources;

Expand Down
96 changes: 96 additions & 0 deletions fixtures/real-flake/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions fixtures/real-flake/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
home-manager.url = "github:nix-community/home-manager";
nixpkgs-hm.follows = "home-manager/nixpkgs";
den.url = "github:denful/den";
with-inputs.url = "github:denful/with-inputs";
with-inputs.flake = false;
};
outputs = _: { };
}
16 changes: 16 additions & 0 deletions tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,22 @@ in
expected = true;
};

functor-self.test-from-flake-get-inputs-right =
let
flakeInputs = (with-inputs.from.flake ./fixtures/real-flake) (inputs: {
nixpkgs-hm2 = (with-inputs.from.flake inputs.home-manager { }).nixpkgs;
home-manager.inputs.nixpkgs.follows = "nixpkgs-hm2";
});
in
{
expr =
flakeInputs.nixpkgs.outPath != flakeInputs.home-manager.inputs.nixpkgs.outPath
&& flakeInputs.nixpkgs-hm2.outPath == flakeInputs.nixpkgs-hm.outPath
&& flakeInputs.nixpkgs-hm.outPath == flakeInputs.home-manager.inputs.nixpkgs.outPath;

expected = true;
};

# ── Input Overrides Function ────────────────────────────────────────────────
input-overrides.test-input-function-overrides-foo = {
expr =
Expand Down
Loading