this post was submitted on 04 Aug 2023
4 points (100.0% liked)

nixos

1256 readers
1 users here now

All about NixOS - https://nixos.org/

founded 4 years ago
 

I have a personal source project I created a shell.nix file for. However, in the project I have also scripts I want to execute periodically non-interactively. Could I use the nix-shell shebang pointing to shell.nix file in order to have the same programs when I use nix-shell interactively and when I launch the scripts?

you are viewing a single comment's thread
view the rest of the comments
[–] ck_@discuss.tchncs.de 2 points 1 year ago (2 children)

So what I understood here is:

  • you have a shell.nix file that puts packages on your path for working on your package
  • you have a script with a nix-shell shebang that puts the same packages as your shell.nix on the script path because you call it when not being "in the shell"
  • you want your script to "source" the packages from the shell.nix instead of having to specific them twice in the shebang

Is that correct so far?

[–] zako@lemmy.world 1 points 1 year ago (1 children)

Yes, you explain better :-) The idea is that shell.nix is my development environment so I would like to use that shell.nix to interactive shells (nix-shell) and to run scripts (non-interactive use). I understand I could use a nix-shell shebang in every script, but that requires maintenance (when I modify the shell.nix file, modify the shellbang of all my scripts) and it is prune to errors (for example, modify the shell.nix and forget to modify the shebang of my scripts).

[–] ck_@discuss.tchncs.de 2 points 1 year ago

I cannot really verify this, but I think insteas of passing a list of packages you can just point the shebang to the shell.nix file, eg.

#!nix-shell -i bash ../../shell.nix