crate2nix icon indicating copy to clipboard operation
crate2nix copied to clipboard

Is in-expression generation possible?

Open Fuuzetsu opened this issue 3 years ago • 4 comments

Currently whenever Cargo.lock changes, developer has to notice and run crate2nix manually.

This is annoying but I can't think of simple way to automate this away that's consistent for developers across. The simplest (but not simple enough) way would be to start some file-watching thing in nix shell hook and run crate2nix when Cargo.lock changes.

For now we'll probably just check in CI that Cargo.nix is up to date but it sucks to have failed CI because there was a manual step one forgot to do.

If it was possible to say something like

cargoNix = crate2nix ./Cargo.lock;

That'd be cool. We let nix deal with re-running crate2nix when lock file changes.

Is this doable in a pure expression (nix flake)? I am guessing that no but I haven't checked through the source.

Fuuzetsu avatar Apr 28 '21 00:04 Fuuzetsu

I tired this today. First, I tried runCommand but then realised I should be using tools.nix.

Sadly, even with populated crate-hashes.json, it seems that when crate2nix invokes cargo metadata, that tries to fetch a git dependency (one already specified in crate-hashes.json) and that obviously fails.

As per #102, I think this is supposed to just work?

Fuuzetsu avatar May 10 '21 01:05 Fuuzetsu

I believe this is fixed in this branch: https://github.com/yusdacra/crate2nix/tree/feat/builtinfetchgit

@yusdacra, would you be willing to upstream your changes?

NickHu avatar Mar 07 '22 12:03 NickHu

@Fuuzetsu how is this now for you? I added the ability in #257 to put in a plain path in the config file. I then create the config file in IFD, and it just works.

I don't think teaching crate2nix everything that, say, niv can do is a good separation of concerns long term, so this feels like a good low-level feature to avoid that.

Ericson2314 avatar Aug 26 '22 19:08 Ericson2314

@Ericson2314 Not sure what you're asking me to verify w.r.t. #257. As long as crate metadata is being invoked, IFD and similar approaches don't come into the picture, no?

Fuuzetsu avatar Aug 29 '22 07:08 Fuuzetsu