Quick nix shell file generation

Like I’m sure many nix users I love being able to quickly use nix shell commands to bring in dependencies for whatever I need to run. I do this by directly specifying package names on the command line which I find really quick and easy, e.g. I run nix shell nixpkgs#asciidoc, make use of asciidoc and then break out of my shell. Once I’ve done this, 9 times out of 10 I feel I should generate a shell.nix (and ideally a flake.nix) so I and others can come back later and reproduce the environment quickly and reliably. In practice though I rarely do.

To fix my behavior I wrote a little tool that takes the same arguments I pass to nix shell that generates the shell.nix and optionally flake.nix for me. It supports both the older nix-shell and newer nix shell command formats. In both cases I just quickly edit the command name using tab completion and let it kick out the necessary files for me. I find this workflow very quick and once I’ve got these files generated I can modify and extend them naturally without depending on my tool or anything else but nix. I’ve added protections so I don’t accidentally overwrite existing files.

I’ve found this way of working to be a good gateway from nix-shell to nix shell where I found the first has quicker, simpler commands but the second promotes reproducibility with flakes. I added a --with-flake command to add a flake even when using the older syntax.

Is this tool of any use to anybody? Please feel free to raise issues. I’d also be interested to know if others have different workflows to solve this problem.

The tool is on GitHub at:

7 Likes

Sounds useful. Mind adding it to nixpkgs for me?

1 Like

Sure thing @mightyiam. Give me a few weeks and I’ll get it added.

1 Like