Skip to content

Add reference to vic/with-inputs#30

Merged
aanderse merged 1 commit intoaanderse:mainfrom
vic:patch-1
Apr 8, 2026
Merged

Add reference to vic/with-inputs#30
aanderse merged 1 commit intoaanderse:mainfrom
vic:patch-1

Conversation

@vic
Copy link
Copy Markdown
Contributor

@vic vic commented Apr 5, 2026

with-inputs is related (alternative to nix flakes) in the sense that it allows flake-like inputs for projects using npins or other non-flake locking mechanism.

@aanderse
Copy link
Copy Markdown
Owner

aanderse commented Apr 6, 2026

hi @vic 👋

i'm trying to play around with with-inputs and lon - i think i am missing something obvious...

nix repl
Nix 2.31.3
Type :? for help.
nix-repl> sources = import ./lon.nix

nix-repl> sources
{
  ndg = "/nix/store/l115h1xyaacyaac0j08id7srd2wwpjl1-source";
  nixpkgs = "/nix/store/s08d9f5avsqs69r1y2gyivxgfwv4a88c-source";
}

nix-repl> with-inputs = import ./with-inputs.nix sources { }

nix-repl> outputs = inputs: { }

nix-repl> (with-inputs outputs).inputs
{
  __functor = «lambda __functor @ /home/aaron/nix/framework/with-inputs.nix:136:5»;
  ndg = «error: expected a set but found a string with context: "/nix/store/l115h1xyaacyaac0j08id7srd2wwpjl1-source"»;
  nixpkgs = «error: expected a set but found a string with context: "/nix/store/s08d9f5avsqs69r1y2gyivxgfwv4a88c-source"»;
  self = { ... };
}

any advice you can provide would be greatly appreciated 🙇‍♂️

@vic
Copy link
Copy Markdown
Contributor Author

vic commented Apr 6, 2026

Hey, @aanderse. I did not know of Lon, thanks for pointing to it.

From your code, looks like sources is an attrset of string paths. with-inputs expects values to have outPath at least. (like those sources from npins), so perhaps the following can help:

sources = mapAttrs (_: outPath: { inherit outPath; }) (import ./lon.nix);

I will also try to add another example at with-inputs using lon, we currently have examples for npins, unflake, and nixlock.

@aanderse
Copy link
Copy Markdown
Owner

aanderse commented Apr 6, 2026

ah, outPath was the missing piece, thank you

any idea on this one?

image

here are the details of the flake i am importing:

    "ndg": {
      "type": "GitHub",
      "fetchType": "tarball",
      "owner": "feel-co",
      "repo": "ndg",
      "branch": "main",
      "revision": "0c898318cdb7b8288a58f6393b1d8ba0dd6b0a09",
      "url": "https://github.com/feel-co/ndg/archive/0c898318cdb7b8288a58f6393b1d8ba0dd6b0a09.tar.gz",
      "hash": "sha256-BedBcz5+dDHhNWMY4JndabYUMSOMusKzFGLV1PxvwBQ="
    }

@vic
Copy link
Copy Markdown
Contributor Author

vic commented Apr 6, 2026

Yep, with-inputs takes the following args:

with-inputs sources follows outputsFn

Try using:

with-inputs sources { } lib.id

that would be like outputs = inputs: inputs in a flake, returning inputs for inspection. I guess the missing part in your code is the follows that can be just { }, with-inputs does auto-follows from the flake dependencies so in most cases you don't need to specify follows unless deps use uncommon names.

@aanderse
Copy link
Copy Markdown
Owner

aanderse commented Apr 8, 2026

thanks for your help so far @vic - and apologies for the delay, i am traveling so a little bit slower to respond than i would like

i didn't know about with-inputs and i am very curious about it! looks like an amazing project.

if i have a dependency on flake a but not flake b, and flake a has a dependent on flake b does this mean i need to add flake b to my list of things to fetch and then override the follow?

@vic
Copy link
Copy Markdown
Contributor Author

vic commented Apr 8, 2026

if i have a dependency on flake a but not flake b, and flake a has a dependent on flake b does this mean i need to add flake b to my list of things to fetch and then override the follow?

Not necessarily, that is the point of not using flakes (for me), I don't want all inputs of my dependencies to be downloaded, for example, some flakes like nix-unit have a dependency on nix-github-actions that I don't need to download.

So if I have a pinned nix-unit, I can use it without having nix-github-actions as long as the code path does not try to evaluate that.

So if you have no flake b it is just like if you had this:

with-inputs sources { a.inputs.b.follows = ""; } outputs;

that one explicitly disables a.inputs.b, but same happens if b is not part of sources automatically.

@aanderse
Copy link
Copy Markdown
Owner

aanderse commented Apr 8, 2026

right, understood. but my question was about scenarios where flake a definitely needs flake b - the idea is that i should fetch it, right?

@vic
Copy link
Copy Markdown
Contributor Author

vic commented Apr 8, 2026

Oh yes, in that case b needs to be at sources, or

# follows.nix
inputs:
{
   a.inputs = {
     b.follows = "b-with-other-name-at-sources";
     
     # or directly implement a shim for it 
     b.lib = n: n + 1;
     
     # or provide an alternative outPath (eg, another fetcher)
     b = if pathExists /my/b then { outPath = /my/b; } else inputs.nixpkgs.lib.fetchFromFoo { ... };

     # or adapt the `b` from source
     b = source: source // { rev = "HEAD"; };
   };
}

In my personal infra I use vic/flake-file that allows me to automatically extract input definitions from my modules and writes them to npins, I might also add support at flake-file for Lon since it looks very similar to npins.

@aanderse
Copy link
Copy Markdown
Owner

aanderse commented Apr 8, 2026

amazing. i want to try and port my config to this. i will do so once i get a chance.

@aanderse aanderse merged commit 9556562 into aanderse:main Apr 8, 2026
@aanderse
Copy link
Copy Markdown
Owner

aanderse commented Apr 8, 2026

i am very happy to recommend this project. great work @vic !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants