Closed blakecalvin closed 1 month ago
Hi, I'm also new to Nix but I think I can provide some guidance or at least get you on the right track. I believe shell.nix is the old non flake way of doing things. use nix develop
to start a nix shell, check line 39 in flake.nix devShell
, this is where the packages installed in the nix shell after running nix develop are defined. You should be able to add packages here and nix develop will install them in a shell when the command is run. Check https://zero-to-nix.com/start/nix-develop and https://nix.dev/manual/nix/2.17/command-ref/new-cli/nix3-develop for more info
According to https://nix.dev/manual/nix/2.17/command-ref/new-cli/nix3-develop you can also run nix develop nixpkgs#hello
which, I believe, is equivalent to nix-shell -p hello
@AVGVSTVS96 Ah that makes sense, I had been seeing nix develop
around but I thought it had a different purpose. Thanks so much for the help, this cleared a lot up for me!
@blakecalvin This can also be done with nix shell
, this is what I've learned so far about nix shell
and nix develop
:
nix shell nixpkgs#git
: Creates an ephemeral shell with git package availablenix develop nixpkgs#git
: Makes git package available and creates a development environment based on git's build inputs in nixpkgs. Equivalent to nix-shell -p git
nix develop .
: Creates a dev environment based on devShells
config in current flakeIn short:
# Non flakes
nix-shell -p git vim # Development environment for packages
# Flakes
nix shell nixpkgs#git nixpkgs#vim # Ephemeral Shell with packages
nix shell nixpkgs#{git,vim} # Shorthand for multiple packages in posix shells
nix develop nixpkgs#git nixpkgs#vim. # Development environment for packages
nix develop nixpkgs#{git,vim} # Shorthand for multiple packages in posix shells
nix develop . # Development environment for flake
I am very new to nix and just recently used this template to setup nix on my m2 Mac. One of the features I was very keen on using with nix was the project specific shells on my projects (eg
nix-shell -p ripgrep...
andshell.nix
). After setting everything up to my liking and rebuilding I noticed that when creating a new shell I would get the error:After some looking around I see that
extra-nix-path = nixpkgs=flake:nixpkgs
is removed after this template is used, and to my understanding (I could be wrong) having this in the config defeats part of the purpose of using flakes? Which I can understand why its removed then. So if this is the case how do we go about creating these development shells?I saw that you can use
nix shell nixpkgs#[PACKAGE]
but I'm unsure how to utilize something likeshell.nix
in my project directories.