Spyke

Syndicated from the fediverse. Read and engage on the original instance.

View original on lemmy.world

shell.nix to run scripts?

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?

View original on lemmy.world
4

2 replies

zakoreply
lemmy.world

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).

1
#!/usr/bin/env nix-shell
#!nix-shell -i bash /path/to/shell.nix
echo "Hello, World!"

haven't tested, but it should work

2

You reached the end

shell.nix to run scripts? | Spyke