nix-dot-dev / getting-started-devenv-template

Based on nix.dev tutorials, repository template to get you started with Nix.
https://nix.dev
473 stars 27 forks source link

update-niv: Explicitly fetch niv and pre-commit packages #35

Closed avdv closed 1 year ago

avdv commented 3 years ago

This avoids fetching all dev dependencies running the "Update niv" workflow, which is a bit wasteful and time consuming.

The time needed for the workflow went down from ~3 min to ~1 min for my project: https://github.com/avdv/replay/actions/workflows/update-niv.yml

Also, should we also use nix_path: nixpkgs=./nix/nixpkgs.nix action argument for the Test workflow, too?

And, I've found it useful to trigger the update-niv action manually sometimes (I am only running the job weekly). What do you think about that?

domenkozar commented 3 years ago

Also, should we also use nix_path: nixpkgs=./nix/nixpkgs.nix action argument for the Test workflow, too?

I don't think so, I'd like my CI to fail if it depends on $NIX_PATH.

And, I've found it useful to trigger the update-niv action manually sometimes (I am only running the job weekly). What do you think about that?

Yeah that sounds like a good idea, any ideas how to do that?

avdv commented 3 years ago

Also, should we also use nix_path: nixpkgs=./nix/nixpkgs.nix action argument for the Test workflow, too?

I don't think so, I'd like my CI to fail if it depends on $NIX_PATH.

Could you elaborate on that? Or, what's the alternative?

I was just put off about the warning: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I), at (string):1:9; will use bash from your environment message you get, e.g. when running nix-shell --run 'niv update'.

Would nix-shell -I nixpkgs=./nix/nixpkgs.nix ... work for you? (I guess not)

If not, how can I only "load" niv inside the shell just be using a nix expression. I tried something like nix-shell -A niv nix/nixpkgs.nix but that would pull all build dependencies for niv instead of niv itself, right? I probably need to put niv into a buildInputs attribute... ? Is that the way to go?

And, I've found it useful to trigger the update-niv action manually sometimes (I am only running the job weekly). What do you think about that?

Yeah that sounds like a good idea, any ideas how to do that?

You can use the workflow_dispatch trigger. See https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/

edit: I'll prepare a PR.

domenkozar commented 3 years ago

Would nix-shell -I nixpkgs=./nix/nixpkgs.nix ... work for you? (I guess not)

Yeah, that's fine.

Could you elaborate on that? Or, what's the alternative?

It's because it's not reproducible between local and CI setups then (it will work on CI). More at https://nix.dev/tutorials/towards-reproducibility-pinning-nixpkgs.html

You can use the workflow_dispatch trigger. See https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/

TIL :)

avdv commented 3 years ago

Would nix-shell -I nixpkgs=./nix/nixpkgs.nix ... work for you? (I guess not)

Yeah, that's fine.

Could you elaborate on that? Or, what's the alternative?

It's because it's not reproducible between local and CI setups then (it will work on CI). More at nix.dev/tutorials/towards-reproducibility-pinning-nixpkgs.html

Sorry, I don't fully get it. Since it's still pinned, in the same way it is locally, as it refers to the same nixpkgs definition.

But of course, it's referring to the NIX_PATH which is implicitly given inside the CI env. Is this what you mean? And if you explicitly specify the -I nixpkgs=./nix/nixpkgs.nix argument it is not..?!

But then, running without NIX_PATH, it will use the same nixpkgs... no?! I have to give this some thought.

PS: PR created: #36

domenkozar commented 3 years ago

But of course, it's referring to the NIX_PATH which is implicitly given inside the CI env. Is this what you mean?

Yes, it will work on CI, but not locally since NIX_PATH is not defined. You could export it in shell.nix, but I really don't think that's a good idea.

domenkozar commented 1 year ago

This template now uses https://devenv.sh so no more niv.