Best Way To Manage Project Dependencies | Nix Shells

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

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

  • @dejangegic
    @dejangegic 2 месяца назад +164

    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 2 месяца назад +42

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

  • @ベース-l1f
    @ベース-l1f 2 месяца назад +20

    I like the new visual style you have for your videos

    • @vimjoyer
      @vimjoyer  2 месяца назад +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

    • @LuxioTheMan
      @LuxioTheMan 16 дней назад

      @@vimjoyer you're good, great even

  • @lowgos0606
    @lowgos0606 2 месяца назад +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

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

    vimjoyer never fails to make our toes wiggle

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

      Oh hi kinzoku

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

      ​@@vimjoyer greetings fellow vim enthusiast

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

    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 месяца назад +3

      facts

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

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

    • @saitheninja
      @saitheninja 2 месяца назад +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.)

  • @mastermach50
    @mastermach50 2 месяца назад +6

    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 2 месяца назад

      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"

  • @Dominik-K
    @Dominik-K 2 месяца назад +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 2 месяца назад +3

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

  • @WaterGame7777
    @WaterGame7777 2 месяца назад +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!

  • @Gilded_Seraphim
    @Gilded_Seraphim 2 месяца назад +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

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

      I'm in your walls

    • @bencarmichael790
      @bencarmichael790 2 месяца назад +5

      ​@@vimjoyerIn my shell more like

    • @jheregreign
      @jheregreign 2 месяца назад

      @@bencarmichael790 👻

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

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

  • @lieywe3438
    @lieywe3438 2 месяца назад +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 месяца назад +2

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

  • @computing1
    @computing1 4 дня назад +1

    love this channel, please keep going!

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

    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.

  • @NabekenProG87
    @NabekenProG87 2 месяца назад +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 2 месяца назад +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.

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

    you are truly the nix god our world needed

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

    Awesome work!

  • @edhyjoxenbyl1409
    @edhyjoxenbyl1409 2 месяца назад +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 2 месяца назад

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

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

    Loved the explanation 👏

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

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

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

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

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

    As always amazing video!!!!

  • @diego55
    @diego55 2 месяца назад +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  2 месяца назад

      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

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

    your videos are helpful overviews, thanks

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

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

  • @tortilla-dev
    @tortilla-dev 2 месяца назад +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! 💪🚀

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

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

  • @darux268
    @darux268 2 месяца назад +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

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

    to the point ❤ well done!!

  • @CoinedBeatz
    @CoinedBeatz 2 месяца назад +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.

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

    Boii waiting for this

  • @HiramBarrozo
    @HiramBarrozo 2 месяца назад +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  2 месяца назад +1

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

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

    Awesome content!

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

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

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

      thanks

    • @starving207
      @starving207 2 месяца назад

      @@vimjoyer I LOVE U MY CRUSADER BOY

  • @cyrus01337
    @cyrus01337 2 месяца назад +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.

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

    i see a nix video i instantly press 👍

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

    Amazing, bro.

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

    that thumbnail though

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

      Clickbait 👍👍👍

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

      @@vimjoyer it definitely worked

  • @rodrigof.5956
    @rodrigof.5956 2 месяца назад +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

  • @ruroruro
    @ruroruro 2 месяца назад +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 2 месяца назад

      actually useful yt comments, wild, thanks for info

    • @NabekenProG87
      @NabekenProG87 2 месяца назад

      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 2 месяца назад +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 2 месяца назад

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

    • @ruroruro
      @ruroruro 2 месяца назад +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 2 месяца назад +1

    I love your videos !!!

  • @yash1152
    @yash1152 2 месяца назад +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 месяца назад +2

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

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

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

    • @vimjoyer
      @vimjoyer  2 месяца назад +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 2 месяца назад

      @@vimjoyer Thanks!!!

  • @madol3728
    @madol3728 2 месяца назад +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

  • @rishivora1076
    @rishivora1076 2 месяца назад +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.

  • @MonSteh
    @MonSteh 2 месяца назад +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).

  • @alyti
    @alyti 2 месяца назад +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

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

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

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

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

  • @Heshamelfakharani
    @Heshamelfakharani 2 месяца назад +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  2 месяца назад +1

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

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

      @@vimjoyer thank you!!

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

    Man but python packages in nix make me cry every time

    • @RobertFletcherOBE
      @RobertFletcherOBE 2 месяца назад

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

    • @anonymouscommentator
      @anonymouscommentator 2 месяца назад

      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 2 месяца назад

      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 2 месяца назад

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

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

    Thanks

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

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

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

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

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

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

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

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

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

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

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

      Make an alias

  • @bulldoser2610
    @bulldoser2610 2 месяца назад +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  2 месяца назад

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

    • @bulldoser2610
      @bulldoser2610 2 месяца назад

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

    • @panchohorrillo509
      @panchohorrillo509 2 месяца назад

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

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

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

    • @NabekenProG87
      @NabekenProG87 2 месяца назад

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

  • @alejandrobonilla7759
    @alejandrobonilla7759 2 месяца назад +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 2 месяца назад +1

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

    • @alejandrobonilla7759
      @alejandrobonilla7759 2 месяца назад

      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  2 месяца назад

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

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

      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.

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

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

  • @nicholasantidormi6238
    @nicholasantidormi6238 2 месяца назад +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  2 месяца назад

      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

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

    What if nixpkgs doesn't have a specific dependency?

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

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

    • @MWLaboratories
      @MWLaboratories 2 месяца назад

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

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

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

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

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

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

    Alright, so now we can talk about nix-direnv

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

    Nice

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

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

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

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

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

      you do not need any privileges to use nix shells

    • @alexander13094
      @alexander13094 2 месяца назад

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

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

    do you daily drive nixos?

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

      Of course

    • @imnotchinese6235
      @imnotchinese6235 2 месяца назад

      @@vimjoyer i tried and failed, but i'll be back

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

    hmmm

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

    7 seconds ago wtf

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

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

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

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

  • @jamesgphillips91
    @jamesgphillips91 2 месяца назад

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

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

      This is a completely different concept

  • @justadude8716
    @justadude8716 2 месяца назад +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.