Best Way To Manage Project Dependencies | Nix Shells

Поделиться
HTML-код
  • Опубликовано: 2 ноя 2024

Комментарии • 158

  • @dejangegic
    @dejangegic Месяц назад +155

    Why would I write a Dockerfile in a minute or two, when I can spen the afternoon doing the same thing in Nix?

  • @gregf3021
    @gregf3021 Месяц назад +39

    Every time I sit down and think hmm I really want a new vimjoyer video it appears. Thank you for your hard work.

  • @lowgos0606
    @lowgos0606 Месяц назад +10

    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

  • @ベース-l1f
    @ベース-l1f Месяц назад +18

    I like the new visual style you have for your videos

    • @vimjoyer
      @vimjoyer  Месяц назад +3

      Didn't quite have enough time to polish it for this one, hope it's going to look even better in the next one

  • @kinzoku-dev
    @kinzoku-dev Месяц назад +31

    vimjoyer never fails to make our toes wiggle

    • @vimjoyer
      @vimjoyer  Месяц назад +5

      Oh hi kinzoku

    • @kinzoku-dev
      @kinzoku-dev Месяц назад +2

      ​@@vimjoyer greetings fellow vim enthusiast

  • @Dominik-K
    @Dominik-K Месяц назад +2

    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

  • @MrVampify
    @MrVampify Месяц назад +3

    This video showed up right on time. I just started learning how to make derivations. This is PERFECT.

  • @Bvngee
    @Bvngee Месяц назад +15

    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.

    • @vimjoyer
      @vimjoyer  Месяц назад +2

      facts

    • @simquinoa2030
      @simquinoa2030 Месяц назад +2

      I NEVER KNEW ABOUT -c. That's so useful thank you

    • @saitheninja
      @saitheninja Месяц назад +2

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

  • @benjaminwagner4597
    @benjaminwagner4597 Месяц назад +1

    Your videos are always 10/10. Thank you for your contributions to the community!

  • @WaterGame7777
    @WaterGame7777 Месяц назад +1

    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!

  • @mastermach50
    @mastermach50 Месяц назад +5

    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.

    • @yash1152
      @yash1152 Месяц назад

      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"

  • @LucianThorr
    @LucianThorr 4 дня назад

    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.

  • @lieywe3438
    @lieywe3438 Месяц назад +3

    I really enjoy your videos! I think mentioning lorri (to prevent certain shells' packages from being garbage collected) would've been informational too 🤔

    • @vimjoyer
      @vimjoyer  Месяц назад +2

      I think I can make a general video for useful tools from nix-community

  • @NabekenProG87
    @NabekenProG87 Месяц назад +1

    Yoooooo, thx for introducing me to build shells. I just got started making derivations, this seems to be a much more efficient way

  • @codeman99-dev
    @codeman99-dev Месяц назад +1

    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.

  • @Gilded_Seraphim
    @Gilded_Seraphim Месяц назад +15

    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

  • @XDtaylormagic
    @XDtaylormagic Месяц назад +1

    Great video! Always look forward to when you post! Hope you have a great day!

  • @doce3609
    @doce3609 Месяц назад +1

    you are truly the nix god our world needed

  • @SebastianLopez-nh1rr
    @SebastianLopez-nh1rr Месяц назад +1

    Awesome work!

  • @callanambulancebutnotforme5702
    @callanambulancebutnotforme5702 Месяц назад +1

    Loved the explanation 👏

  • @coramuirgen2959
    @coramuirgen2959 Месяц назад +1

    your videos are helpful overviews, thanks

  • @JokingChickenn
    @JokingChickenn Месяц назад +3

    Yes! Was literally just researching this. Are u a mindreader?
    Thx for video

  • @Majiy00
    @Majiy00 Месяц назад +1

    As always amazing video!!!!

  • @HiramBarrozo
    @HiramBarrozo Месяц назад +1

    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!

    • @vimjoyer
      @vimjoyer  Месяц назад +1

      I use neovim, use whatever you feel most comfortable with.

  • @berkano4617
    @berkano4617 Месяц назад +4

    Every time i rebuild my NixOS new father appears. Btw, now i have 112 version🥳😝

  • @diego55
    @diego55 Месяц назад +1

    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!

    • @vimjoyer
      @vimjoyer  Месяц назад

      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

  • @edhyjoxenbyl1409
    @edhyjoxenbyl1409 Месяц назад +3

    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;`)

    • @yash1152
      @yash1152 Месяц назад

      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 "_

  • @darux268
    @darux268 Месяц назад +1

    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

  • @anticrisis9006
    @anticrisis9006 Месяц назад +1

    How can I upvote this twice? I've come back to review it multiple times. Very helpful, thank you!

  • @CoinedBeatz
    @CoinedBeatz Месяц назад +1

    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.

  • @gabrielnuetzi
    @gabrielnuetzi Месяц назад +1

    to the point ❤ well done!!

  • @rodrigof.5956
    @rodrigof.5956 Месяц назад +4

    I recommend using lorri, it autoloads the nix-shell when opening the directory, and it's also useful for using shells different to bash

  • @enriquecasas4001
    @enriquecasas4001 Месяц назад +1

    Awesome content!

  • @cyrus01337
    @cyrus01337 Месяц назад +1

    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.

  • @yash1152
    @yash1152 Месяц назад +1

    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

    • @vimjoyer
      @vimjoyer  Месяц назад +2

      I like the newer one more, it focuses on the devshells, and leaves the flakes explanation to the flakes video

  • @tortilla-dev
    @tortilla-dev Месяц назад +2

    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! 💪🚀

  • @guifuentes8
    @guifuentes8 Месяц назад +1

    Amazing, bro.

  • @s1n7ax
    @s1n7ax Месяц назад +1

    Boii waiting for this

  • @ruroruro
    @ruroruro Месяц назад +2

    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.

    • @alyti
      @alyti Месяц назад

      actually useful yt comments, wild, thanks for info

    • @NabekenProG87
      @NabekenProG87 Месяц назад

      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

    • @ruroruro
      @ruroruro Месяц назад +1

      @@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
      @NabekenProG87 Месяц назад

      @@ruroruro thx for the tip, but fuck me for not using bash lmao

    • @ruroruro
      @ruroruro Месяц назад +1

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

  • @BaiDamqn
    @BaiDamqn Месяц назад +1

    I love your videos !!!

  • @starving207
    @starving207 Месяц назад +4

    ХФФІХвзхфізвфхівхїфі
    ЛУчший Продолжай
    мой любимый ютубер по NIXOS

    • @vimjoyer
      @vimjoyer  Месяц назад +2

      thanks

    • @starving207
      @starving207 Месяц назад

      @@vimjoyer I LOVE U MY CRUSADER BOY

  • @anakin1337
    @anakin1337 Месяц назад +1

    i see a nix video i instantly press 👍

  • @dezly-macauley
    @dezly-macauley Месяц назад +2

    Any way to ensure that dynamically linked binaries work with this setup? Certain NixOS packages are a headache to use.

    • @vimjoyer
      @vimjoyer  Месяц назад +2

      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

    • @dezly-macauley
      @dezly-macauley Месяц назад

      @@vimjoyer Thanks!!!

  • @Heshamelfakharani
    @Heshamelfakharani Месяц назад +2

    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

    • @vimjoyer
      @vimjoyer  Месяц назад +1

      You can use nixos-shell, it's like nix-shell but with docker

    • @Heshamelfakharani
      @Heshamelfakharani Месяц назад

      @@vimjoyer thank you!!

  • @MonSteh
    @MonSteh Месяц назад +1

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

  • @pupip55
    @pupip55 Месяц назад +4

    that thumbnail though

    • @vimjoyer
      @vimjoyer  Месяц назад +3

      Clickbait 👍👍👍

    • @pupip55
      @pupip55 Месяц назад +2

      @@vimjoyer it definitely worked

  • @yash1152
    @yash1152 Месяц назад +1

    6:22 > _" pkgs.mkShell.inputsFrom "_
    how to specify a local mkDerivation.nix file inside the inputsFrom list?

    • @vimjoyer
      @vimjoyer  Месяц назад

      Those are just packages, so you can add your local packages there by wrapping callPackage in some parentheses().

  • @ThomasBrowne-bf9zi
    @ThomasBrowne-bf9zi Месяц назад +2

    Thanks!

  • @rishivora1076
    @rishivora1076 Месяц назад +2

    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.

  • @Cypekeh
    @Cypekeh Месяц назад +2

    What is the easiest way to always run the same shell with nix develop (like zsh), without always specifying the -c flag?

  • @bulldoser2610
    @bulldoser2610 Месяц назад +1

    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.

    • @vimjoyer
      @vimjoyer  Месяц назад

      Unstable version is perfectly fine. The name is scary, but it's very much reproducible, and more stable than most distros repos

    • @bulldoser2610
      @bulldoser2610 Месяц назад

      @@vimjoyer does flake.lock pin every package version from unstable branch?

    • @panchohorrillo509
      @panchohorrillo509 Месяц назад

      @@bulldoser2610 Yes it does. That's how I live 🙂

  • @bobmcbob4399
    @bobmcbob4399 Месяц назад +2

    But you also get isolation of your home data in containers. You don't get that with nix shell.

    • @vimjoyer
      @vimjoyer  Месяц назад +5

      But you can still achieve that, I'll make a video about that soon

    • @bobmcbob4399
      @bobmcbob4399 Месяц назад

      @@vimjoyer ok, that would be interesting. My main motivation for dev containers is to stop the data hoovering from software within the container.

  • @xlustx5591
    @xlustx5591 Месяц назад +4

    Man but python packages in nix make me cry every time

    • @RobertFletcherOBE
      @RobertFletcherOBE Месяц назад

      yeah python packaging was bad enough, using python on nix is a complete pain.

    • @anonymouscommentator
      @anonymouscommentator Месяц назад

      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

    • @nobody-bt3iwnobod
      @nobody-bt3iwnobod Месяц назад

      You could use nix shell for installing python interpreter and then create a virtual envrionment for project specific packages. Similar to pyenv + venv

    • @MWLaboratories
      @MWLaboratories Месяц назад

      Im stuck on installing npm packages not available in nix pkgs like vuetify.

  • @anticrisis9006
    @anticrisis9006 Месяц назад +1

    Thanks

  • @nicholasantidormi6238
    @nicholasantidormi6238 Месяц назад +1

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

    • @vimjoyer
      @vimjoyer  Месяц назад

      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

  • @3ChunkyPL
    @3ChunkyPL Месяц назад +3

    Alright, so now we can talk about nix-direnv

  • @madol3728
    @madol3728 Месяц назад +1

    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

  • @Resursator
    @Resursator Месяц назад +4

    > solves "it work for my machine" problem
    Yeah, instead you will have "it doesn't work for any machine" problem :D

    • @NabekenProG87
      @NabekenProG87 Месяц назад

      Thats a possibility for all software. I can write a Python program that craps itself in 1min, tremble mortals

  • @martianhunter7168
    @martianhunter7168 Месяц назад +3

    I started my minor programming hobby with nix shells, I don’t know real devs live without them.

  • @nasang7478
    @nasang7478 Месяц назад +2

    What if nixpkgs doesn't have a specific dependency?

    • @vimjoyer
      @vimjoyer  Месяц назад +5

      You can package it, it's much easier on nixos. I'll make a better video about it soon

    • @MWLaboratories
      @MWLaboratories Месяц назад

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

  • @v3rm1n
    @v3rm1n Месяц назад +1

    I like devenvs that way I can start services haven’t found a ways to do it in a flake devshell

  • @alejandrobonilla7759
    @alejandrobonilla7759 Месяц назад +1

    Hey just one thing the aliases do not go from your shell to the new one (at least with zsh does not happen)

    • @alejandrobonilla7759
      @alejandrobonilla7759 Месяц назад +1

      Nice video, I got into nixos thanks to you keep it up

    • @alejandrobonilla7759
      @alejandrobonilla7759 Месяц назад

      So I tested it and it is because the -p invokes bash but the flakes way opens your default shell (in my case zsh)

    • @vimjoyer
      @vimjoyer  Месяц назад

      You can use add `--command $SHELL` at the end to get into your favorite shell

    • @ruroruro
      @ruroruro Месяц назад

      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.

  • @alyti
    @alyti Месяц назад +2

    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

  • @Folvin-x1o
    @Folvin-x1o Месяц назад +2

    Пон пон пон пон Согл согл согл Баз база Основа основа

  • @isaacaymerich2741
    @isaacaymerich2741 Месяц назад +1

    you forget an important thing, what about pining package versions :) ?

    • @vimjoyer
      @vimjoyer  Месяц назад +1

      I have a whole 15 minute video about it, it's linked in the description

  • @ДашаГолік
    @ДашаГолік Месяц назад +1

    Nice

  • @imnotchinese6235
    @imnotchinese6235 Месяц назад +1

    do you daily drive nixos?

  • @alexander13094
    @alexander13094 Месяц назад +1

    And you need to figure out how to run it unprivileged. For docker it is just adding yourself into docker group

    • @vimjoyer
      @vimjoyer  Месяц назад

      you do not need any privileges to use nix shells

    • @alexander13094
      @alexander13094 Месяц назад

      Yeah, didn't noticed there is nix-users group. Will test

  • @jabahuntercrypto
    @jabahuntercrypto Месяц назад +1

    hmmm

  • @Bvngee
    @Bvngee Месяц назад +2

    7 seconds ago wtf

  • @cbleslie
    @cbleslie Месяц назад +1

    Wait until these fools learn about nix-pre-commit-hooks.

  • @doce3609
    @doce3609 Месяц назад +1

    0:12 you have a grammatical issue.
    2. should be than not then.

  • @jamesgphillips91
    @jamesgphillips91 Месяц назад

    meh... why do this when you can wasi use shims?

    • @vimjoyer
      @vimjoyer  Месяц назад +1

      This is a completely different concept

  • @justadude8716
    @justadude8716 Месяц назад +1

    regards, guy who never worked with proprietary systems and assumes usecase for webshitters is best usecase for rest of us. Nice click bait title.