In order to version-control the nix-shells I use for several projects (without committing nix files to the projects themselves), I created a separate repo to reference in nix-shell
invocations:
cd /path/to/use-db
nix-shell -A use-db \
https://github.com/ivanbrennan/nixels/archive/master.tar.gz
nixels
is just a minimal working example of such a repo. The examples within are not real-world projects.
cd /path/to/use-queue
nix-shell -A use-queue \
https://github.com/ivanbrennan/nixels/archive/master.tar.gz
Tagging git revisions like <project>-<version>
allows me to specify which version of the project I want an environment for:
cd /path/to/use-db
nix-shell -A use-db \
https://github.com/ivanbrennan/nixels/archive/use-db-0.1.0.tar.gz
Ideally though, I wanted a simpler interface, like:
$ cd /path/to/use-db
$ somecommand
where somecommand
detects the current project and version, and selects the right nix-shell derivation automatically.
So I wrote a CLI to do just that: shellbit. I’ve seen similar ideas floated in past threads. This was my take on it.
nix-env -iE '_:
let
url = https://github.com/ivanbrennan/shellbit/archive/0.1.0.0.tar.gz;
in
(import "${builtins.fetchTarball url}/nix" { }).minimal
'
The first time it’s used, it prompts for the url where it can find your nix-shell recipes.
$ cd use-db
$ shellbit
SHELLBIT_URL not found in environment or config.
It should identify a git repo where we can find nix derivations
for your project shells. E.g. git@github.com:Foo/nix-shells.git
Please enter SHELLBIT_URL: git@github.com:ivanbrennan/nixels.git
Config can be saved to /home/ivan/.config/shellbit/config.dhall
Save config? [Y/n] y
[nix-shell:~/Development/use-db]$
If you choose to save the config, subsequent uses will work without prompting.
$ cd use-queue
$ shellbit
[nix-shell:~/Development/use-queue]$
I’m curious for feedback, and I’d like to submit it to nixpkgs.
Maybe setting up a repo of nix-shell recipes is more work than some users will want to invest, but I’m getting good mileage out of this approach so far.
I put up a minimal example of such a repo at https://github.com/ivanbrennan/nixels so all the examples above will work.