Note that any nix-shell command _can_ be replaced by nix develop. For example, `nix-shell -E "with import ; …"` can be replaced with `nix develop -expr "with import ; …"`. Also see nix develop -f. Another immensely useful option is nix-shell’s -command (or just -c for nix develop). This lets you, for example, use zsh instead of bash.
I like to use `shellHook = ''exec $SHELL''` in my file. Then `nix develop` will open your configured shell automatically, without having to type the extra flag. (Not sure if this works with `nix-shell` because I'm using flakes exclusively.)
Note that if you use `nix-shell` (no flakes) only the packages and dependencies specified in shell.nix get added to the /nix/store, but if you use `nix shell` (flakes) the entire folder that contains flake.nix gets added to /nix/store. So if there are many large files in your project (like some AI models) those also get added to /nix/store taking up a lot of space.
thanks a lot for sharing this. the obvious difference between those is default channel, but thanks for sharing this too.... but also, it feels counter intuitive for even the ... umh wait, so, there's "nix shell" and "nix develop"... are these two same? 9:41 but kinda not clear what's the difference in "shell" and "build shell"
Wow, I know FOSS developers especially always talk about how prompting people to donate works, but this really made it click with me. Love your videos, it just never appeared in my mind that you take donations. so yay! PS: your videos are absolutely amazing and are how I got into Nix. Without them I might have ended up giving up on it again. Every time someone asks for advice on learning Nix(OS) I always recommend your videos!
I really enjoy your videos! I think mentioning lorri (to prevent certain shells' packages from being garbage collected) would've been informational too 🤔
I've wanted to have a quick way to run a Jupyter notebook without having to deal with python virtual environments on my home computer. This seems like the perfect way to keep things clean and reproducible without having to worry about my python package manager going breaking itself every few months. Thanks for the pointers.
2:30 Thank you stating right up front why I won't switch. The isolation is paramount. Not only are devcontainers easy to share, but you are forced to update that configuration. Nothing is worse than a dev configuration that only one person on the team cares about.
Setting environment variable in the mkShell scope is a legacy behavior. The recommended way is to use `env` sub attribute set. (like `env.MY_VAR = 1;`)
thanks for sharing this. the "every not recognised var is considered env-var" thing is super yucky for me. > _" recommended way is to use `env` sub attribute set "_
Nice video! It would be great if you could use a specific version of Node, especially an older one. For example, I have a project running Node v12.22.2. Thank you for your videos, I'm starting to love Nixos thanks to you!
Hey! I just wanted to congratulate you on the amazing work you're doing with Nix, your explanations are super clear and helpful. It would be awesome if you could create a tutorial on Prisma since it has some conflicts on NixOS when used as a dependency in Node projects. Thanks for all the great content you share, and keep up the fantastic work! 💪🚀
Being able to launch gui applications without having to fuck around with the x server is great, this sounds super useful on nix os but I don't think it'll kill dev containers anytime soon. If you want to share a dev environment with someone else it's much more likely they already have docker and docker knowledge than nix and nix knowledge
this video some weeks ago would have helped me quite a bit :P. I really like the approach nix shells provide to specify project based dependencies especially with flakes to even lock those versions. I'm trying to switch fully to NixOS but my work environment prevents me from doing so. The main reason being that `schroot` is not available in nixpkgs. I'm currently trying to package that but get quite some resistance along the way. After all I'm not even sure if `schroot` will work as expected. That's why I'm pursuing distrobox for my work environment which I could more or less plug-in-replace the schroot calls. But then again the nix store gets mounted to my container, which creates conflicts... (most likely due to home-manager). So right now I'm trying to get a pure podman command that does the trick for now until I'm done with writing a dozen derivations for all the stuff that's missing. But every new project I'll create will be based on dev shells.
Hi! I really enjoy your videos, they're super helpful! I have a question: I'm starting to learn Nix (I love flakes) but sometimes I get stuck. What IDE would you recommend for a beginner like me? Thanks in advance!
Since I already use Docker and Devpods, I don't see much use case for NixOS and it's various Nix* tooling, though it's quite the exotic distro that I'd love to trial in a VM some day.
I strongly recommend using the nix3 cli in this case ("nix shell" with a space, it is enabled by the nix-command experimental feature). nix-shell isn't actually equivalent to "nix shell", it's equivalent to "nix develop". The older nix-shell command was originally intended to be used for developing/debugging nix derivations, not for ephemeral shells. If you want ephemeral shells (basically, if you want to temporarily emulate actually "installing" the packages) then "nix shell" is much better compared to nix-shell. For example, "nix shell nixpkgs#gcc" would use YOUR default shell and it would also populate a bunch of environment variables so that stuff like "man gcc" works inside that ephemeral shell. On the other hand "nix-shell" would always use bash and you won't be able to access the man pages.
Thx for the tip. But I guess now I have to type "nix shell nixpkgs#python312 nixpkgs#python312Packages." instead of "nix shell python312 python312Packages."? Seems kinda verbose
@@NabekenProG87 you can significantly reduce the amount of typing required by 1) creating an alias for nix shell 2) creating a shorter name for nixpkgs in the flake registry and 3) using bash brace expansions. Applying all 3 tricks will result in something along the lines of ns pkgs#{hello,gcc,gnumake,python3.12}
@@NabekenProG87 What shell are you using? Brace expansions are also available in zsh and fish. Of the shells I know, only dash doesn't support them. Try running echo x{a,b}y in your shell. You should get "xay xby" if your shell supports brace expansions.
hi! what's the summary difference in * this current video titled: " Best Way To Manage Project Dependencies | Nix Shells " and * the older one titled: " Nix Dev Environments | Declare Your Coding Projects " i've watched these both, but can't recall the differences in these, and hence, can't decide which one to refer some other person to for which situation
All nixos packages will work just fine, but if you want to run foreign binaries, there are many ways to do it. You can try nix-ld/nix-alien, steam-run, or patch the binaries yourself
Man. I was just setting my new project with docker. I really just pushed the changes, closed my terminal and went to youtube. Yeah I'm opening my terminal up again
i still havent figured out how to work with python and its libraries using nix shell. for now, i just use devenv, but it doesnt protect installed packages from garbage collection.
i know this kinda goes against the purpose of nix shell but can i use docker insid them? would the docker instance be isolated in that shell? im working with big docker compose setups that i don't have the time to move entirely to nix
when you find out you have to recompile the entire cuda toolchain just because you wanted to use pytorch right after you had to compile the entire cuda toolchain because you wanted to use ollama
Just one question. If i use the unstable branch in flake is my system really reproducable? if not how do I acheive absolute reproducibility including package with exact versions? Thanks.
or just use the nix3 cli (the ones with the spaces, enabled by the nix-command experimental feature) nix-shell isn't actually equivalent to "nix shell", it's equivalent to "nix develop". nix-shell was originally intended to be used for developing/debugging nix derivations. If you want ephemeral shells (basically, if you want to temporarily emulate actually "installing" the packages) then "nix shell" is much better compared to nix-shell. For example, "nix shell nixpkgs#gcc" would use YOUR default shell and it would also populate a bunch of environment variables so that stuff like "man gcc" works inside that ephemeral shell. On the other hand "nix-shell" would always use bash and you won't be able to access the man pages.
How to manage different projects, with different nodejs versions (usually .nvmrc) and different package managers (in the last one usually done by specifying it in the package.json and using corepack)?
Why would I write a Dockerfile in a minute or two, when I can spen the afternoon doing the same thing in Nix?
Exactly
chatGPT writes nix files not me
@@vojtechralis6075dear god
@@vojtechralis6075who’s writing gpt prompts for you?
@@vojtechralis6075chatgpt sucks at nix 😂
Every time I sit down and think hmm I really want a new vimjoyer video it appears. Thank you for your hard work.
👍
I like the new visual style you have for your videos
Didn't quite have enough time to polish it for this one, hope it's going to look even better in the next one
@@vimjoyer you're good, great even
You are the best. I love how you show both the flake and classic ways, this is really helpful. And the building debug technique is great
vimjoyer never fails to make our toes wiggle
Oh hi kinzoku
@@vimjoyer greetings fellow vim enthusiast
Note that any nix-shell command _can_ be replaced by nix develop. For example, `nix-shell -E "with import ; …"` can be replaced with `nix develop -expr "with import ; …"`. Also see nix develop -f.
Another immensely useful option is nix-shell’s -command (or just -c for nix develop). This lets you, for example, use zsh instead of bash.
facts
I NEVER KNEW ABOUT -c. That's so useful thank you
I like to use
`shellHook = ''exec $SHELL''`
in my file.
Then `nix develop` will open your configured shell automatically, without having to type the extra flag.
(Not sure if this works with `nix-shell` because I'm using flakes exclusively.)
Note that if you use `nix-shell` (no flakes) only the packages and dependencies specified in shell.nix get added to the /nix/store, but if you use `nix shell` (flakes) the entire folder that contains flake.nix gets added to /nix/store.
So if there are many large files in your project (like some AI models) those also get added to /nix/store taking up a lot of space.
thanks a lot for sharing this. the obvious difference between those is default channel, but thanks for sharing this too....
but also, it feels counter intuitive for even the ... umh wait, so, there's "nix shell" and "nix develop"... are these two same? 9:41 but kinda not clear what's the difference in "shell" and "build shell"
Thanks a bunch for this video. This is one of the super powers of nix and those shells are just way easier to use than any container setup I know
This video showed up right on time. I just started learning how to make derivations. This is PERFECT.
Wow, I know FOSS developers especially always talk about how prompting people to donate works, but this really made it click with me. Love your videos, it just never appeared in my mind that you take donations. so yay!
PS: your videos are absolutely amazing and are how I got into Nix. Without them I might have ended up giving up on it again. Every time someone asks for advice on learning Nix(OS) I always recommend your videos!
You terrify me you mind reader, keep your dark magic away from me, CAUSE THERE AINT NO WAY you could know EXACTLY what I am struggling with
I'm in your walls
@@vimjoyerIn my shell more like
@@bencarmichael790 👻
Your videos are always 10/10. Thank you for your contributions to the community!
I really enjoy your videos! I think mentioning lorri (to prevent certain shells' packages from being garbage collected) would've been informational too 🤔
I think I can make a general video for useful tools from nix-community
love this channel, please keep going!
I've wanted to have a quick way to run a Jupyter notebook without having to deal with python virtual environments on my home computer. This seems like the perfect way to keep things clean and reproducible without having to worry about my python package manager going breaking itself every few months. Thanks for the pointers.
Yoooooo, thx for introducing me to build shells. I just got started making derivations, this seems to be a much more efficient way
2:30 Thank you stating right up front why I won't switch.
The isolation is paramount. Not only are devcontainers easy to share, but you are forced to update that configuration. Nothing is worse than a dev configuration that only one person on the team cares about.
you are truly the nix god our world needed
Awesome work!
Setting environment variable in the mkShell scope is a legacy behavior. The recommended way is to use `env` sub attribute set. (like `env.MY_VAR = 1;`)
thanks for sharing this. the "every not recognised var is considered env-var" thing is super yucky for me.
> _" recommended way is to use `env` sub attribute set "_
Loved the explanation 👏
Great video! Always look forward to when you post! Hope you have a great day!
Every time i rebuild my NixOS new father appears. Btw, now i have 112 version🥳😝
As always amazing video!!!!
Nice video! It would be great if you could use a specific version of Node, especially an older one. For example, I have a project running Node v12.22.2.
Thank you for your videos, I'm starting to love Nixos thanks to you!
That's what flakes allow you to do! You can check the nixpkgs package version history, and find nixpkgs that contain the version you need
your videos are helpful overviews, thanks
Yes! Was literally just researching this. Are u a mindreader?
Thx for video
Nice
Hey! I just wanted to congratulate you on the amazing work you're doing with Nix, your explanations are super clear and helpful. It would be awesome if you could create a tutorial on Prisma since it has some conflicts on NixOS when used as a dependency in Node projects. Thanks for all the great content you share, and keep up the fantastic work! 💪🚀
How can I upvote this twice? I've come back to review it multiple times. Very helpful, thank you!
Being able to launch gui applications without having to fuck around with the x server is great, this sounds super useful on nix os but I don't think it'll kill dev containers anytime soon. If you want to share a dev environment with someone else it's much more likely they already have docker and docker knowledge than nix and nix knowledge
to the point ❤ well done!!
this video some weeks ago would have helped me quite a bit :P.
I really like the approach nix shells provide to specify project based dependencies especially with flakes to even lock those versions. I'm trying to switch fully to NixOS but my work environment prevents me from doing so. The main reason being that `schroot` is not available in nixpkgs. I'm currently trying to package that but get quite some resistance along the way. After all I'm not even sure if `schroot` will work as expected.
That's why I'm pursuing distrobox for my work environment which I could more or less plug-in-replace the schroot calls. But then again the nix store gets mounted to my container, which creates conflicts... (most likely due to home-manager). So right now I'm trying to get a pure podman command that does the trick for now until I'm done with writing a dozen derivations for all the stuff that's missing.
But every new project I'll create will be based on dev shells.
Boii waiting for this
Hi! I really enjoy your videos, they're super helpful! I have a question:
I'm starting to learn Nix (I love flakes) but sometimes I get stuck. What IDE would you recommend for a beginner like me? Thanks in advance!
I use neovim, use whatever you feel most comfortable with.
Awesome content!
ХФФІХвзхфізвфхівхїфі
ЛУчший Продолжай
мой любимый ютубер по NIXOS
thanks
@@vimjoyer I LOVE U MY CRUSADER BOY
Since I already use Docker and Devpods, I don't see much use case for NixOS and it's various Nix* tooling, though it's quite the exotic distro that I'd love to trial in a VM some day.
i see a nix video i instantly press 👍
Amazing, bro.
that thumbnail though
Clickbait 👍👍👍
@@vimjoyer it definitely worked
I recommend using lorri, it autoloads the nix-shell when opening the directory, and it's also useful for using shells different to bash
I strongly recommend using the nix3 cli in this case ("nix shell" with a space, it is enabled by the nix-command experimental feature).
nix-shell isn't actually equivalent to "nix shell", it's equivalent to "nix develop". The older nix-shell command was originally intended to be used for developing/debugging nix derivations, not for ephemeral shells.
If you want ephemeral shells (basically, if you want to temporarily emulate actually "installing" the packages) then "nix shell" is much better compared to nix-shell. For example, "nix shell nixpkgs#gcc" would use YOUR default shell and it would also populate a bunch of environment variables so that stuff like "man gcc" works inside that ephemeral shell. On the other hand "nix-shell" would always use bash and you won't be able to access the man pages.
actually useful yt comments, wild, thanks for info
Thx for the tip. But I guess now I have to type "nix shell nixpkgs#python312 nixpkgs#python312Packages." instead of "nix shell python312 python312Packages."? Seems kinda verbose
@@NabekenProG87 you can significantly reduce the amount of typing required by 1) creating an alias for nix shell 2) creating a shorter name for nixpkgs in the flake registry and 3) using bash brace expansions. Applying all 3 tricks will result in something along the lines of
ns pkgs#{hello,gcc,gnumake,python3.12}
@@ruroruro thx for the tip, but fuck me for not using bash lmao
@@NabekenProG87 What shell are you using? Brace expansions are also available in zsh and fish. Of the shells I know, only dash doesn't support them.
Try running echo x{a,b}y in your shell. You should get "xay xby" if your shell supports brace expansions.
I love your videos !!!
hi! what's the summary difference in
* this current video titled: " Best Way To Manage Project Dependencies | Nix Shells " and
* the older one titled: " Nix Dev Environments | Declare Your Coding Projects "
i've watched these both, but can't recall the differences in these, and hence, can't decide which one to refer some other person to for which situation
I like the newer one more, it focuses on the devshells, and leaves the flakes explanation to the flakes video
Any way to ensure that dynamically linked binaries work with this setup? Certain NixOS packages are a headache to use.
All nixos packages will work just fine, but if you want to run foreign binaries, there are many ways to do it. You can try nix-ld/nix-alien, steam-run, or patch the binaries yourself
@@vimjoyer Thanks!!!
Man. I was just setting my new project with docker. I really just pushed the changes, closed my terminal and went to youtube.
Yeah I'm opening my terminal up again
i still havent figured out how to work with python and its libraries using nix shell. for now, i just use devenv, but it doesnt protect installed packages from garbage collection.
First comment, but have to say I like the speed at which you present in this video is the best (I'm a pretty slow guy tho).
shout out to devenv flake and it's pre-commit-hooks and background process stuff, great for bootstrapping more complex envs than a few packages
6:22 > _" pkgs.mkShell.inputsFrom "_
how to specify a local mkDerivation.nix file inside the inputsFrom list?
Those are just packages, so you can add your local packages there by wrapping callPackage in some parentheses().
i know this kinda goes against the purpose of nix shell but can i use docker insid them? would the docker instance be isolated in that shell? im working with big docker compose setups that i don't have the time to move entirely to nix
You can use nixos-shell, it's like nix-shell but with docker
@@vimjoyer thank you!!
Man but python packages in nix make me cry every time
yeah python packaging was bad enough, using python on nix is a complete pain.
when you find out you have to recompile the entire cuda toolchain just because you wanted to use pytorch right after you had to compile the entire cuda toolchain because you wanted to use ollama
You could use nix shell for installing python interpreter and then create a virtual envrionment for project specific packages. Similar to pyenv + venv
Im stuck on installing npm packages not available in nix pkgs like vuetify.
Thanks
But you also get isolation of your home data in containers. You don't get that with nix shell.
But you can still achieve that, I'll make a video about that soon
@@vimjoyer ok, that would be interesting. My main motivation for dev containers is to stop the data hoovering from software within the container.
I like devenvs that way I can start services haven’t found a ways to do it in a flake devshell
What is the easiest way to always run the same shell with nix develop (like zsh), without always specifying the -c flag?
Make an alias
Just one question. If i use the unstable branch in flake is my system really reproducable? if not how do I acheive absolute reproducibility including package with exact versions? Thanks.
Unstable version is perfectly fine. The name is scary, but it's very much reproducible, and more stable than most distros repos
@@vimjoyer does flake.lock pin every package version from unstable branch?
@@bulldoser2610 Yes it does. That's how I live 🙂
> solves "it work for my machine" problem
Yeah, instead you will have "it doesn't work for any machine" problem :D
Thats a possibility for all software. I can write a Python program that craps itself in 1min, tremble mortals
Hey just one thing the aliases do not go from your shell to the new one (at least with zsh does not happen)
Nice video, I got into nixos thanks to you keep it up
So I tested it and it is because the -p invokes bash but the flakes way opens your default shell (in my case zsh)
You can use add `--command $SHELL` at the end to get into your favorite shell
or just use the nix3 cli (the ones with the spaces, enabled by the nix-command experimental feature)
nix-shell isn't actually equivalent to "nix shell", it's equivalent to "nix develop". nix-shell was originally intended to be used for developing/debugging nix derivations.
If you want ephemeral shells (basically, if you want to temporarily emulate actually "installing" the packages) then "nix shell" is much better compared to nix-shell. For example, "nix shell nixpkgs#gcc" would use YOUR default shell and it would also populate a bunch of environment variables so that stuff like "man gcc" works inside that ephemeral shell. On the other hand "nix-shell" would always use bash and you won't be able to access the man pages.
I started my minor programming hobby with nix shells, I don’t know real devs live without them.
How to manage different projects, with different nodejs versions (usually .nvmrc) and different package managers (in the last one usually done by specifying it in the package.json and using corepack)?
You can get different versions of nodejs/npm/yarn in your shell with flakes. You just need to include additional inputs with correct versions for them
What if nixpkgs doesn't have a specific dependency?
You can package it, it's much easier on nixos. I'll make a better video about it soon
@@vimjoyer sounds like the same problems I'm facing with adding vue/vite/vuetify to my nodejs dev shell. It isn't to be found in nixpkgs.
you forget an important thing, what about pining package versions :) ?
I have a whole 15 minute video about it, it's linked in the description
Alright, so now we can talk about nix-direnv
Nice
Пон пон пон пон Согл согл согл Баз база Основа основа
And you need to figure out how to run it unprivileged. For docker it is just adding yourself into docker group
you do not need any privileges to use nix shells
Yeah, didn't noticed there is nix-users group. Will test
do you daily drive nixos?
Of course
@@vimjoyer i tried and failed, but i'll be back
hmmm
7 seconds ago wtf
Wait until these fools learn about nix-pre-commit-hooks.
0:12 you have a grammatical issue.
2. should be than not then.
meh... why do this when you can wasi use shims?
This is a completely different concept
regards, guy who never worked with proprietary systems and assumes usecase for webshitters is best usecase for rest of us. Nice click bait title.