Modularize NixOS and Home Manager | Great Practices

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 พ.ย. 2024

ความคิดเห็น • 88

  • @Pistolpeterrussell
    @Pistolpeterrussell 7 หลายเดือนก่อน +45

    I wish I had this video when I first started learning Nix. Modules seemed so mysterious at first. Now I'm glad I can point people here.

  • @SnubDodecahedron
    @SnubDodecahedron 7 หลายเดือนก่อน +18

    Dude thank you so much, I’ve been ruminating about how to structure my config the perfect and kept getting decisions paralysis but this is exactly what I needed.

  • @attilao
    @attilao 7 หลายเดือนก่อน +28

    This is exactly what I wanted to see. I love these videos, great job.

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน +10

      One of the most requested topics, glad you liked it!

  • @mochreach
    @mochreach 7 หลายเดือนก่อน +9

    Thanks so much for your NixOS videos, they have been so useful for getting started. I'm already totally sold, NixOS has solved a bunch of long starting issues I've had managing some systems. Keep up the good work!

  • @axelcool1234
    @axelcool1234 7 หลายเดือนก่อน +8

    I was actually going to dedicate a big portion of my day today to finally modularizing and cleaning up my config. Perfect timing Vimjoyer, thank you!

  • @teamwolfyta
    @teamwolfyta 7 หลายเดือนก่อน +5

    Thanks so much, Struggling with this for the past few days! You're the best guy for all things Nix! Thanks once again.

  • @elpitbullhouse
    @elpitbullhouse 7 หลายเดือนก่อน +7

    Awesome video, as always. Video idea in case you're interested: A lot of people run home servers either using Cloud/AWS or some old hardware they have around the house. I do, and I'd love to see how you recommend adding a NixOS server config + something to deploy it like NixOps (if necessary) to the flake. 🙂

  • @callyral
    @callyral 7 หลายเดือนก่อน +5

    i love organising so much, I have large amounts of free time soon and I know how I'm gonna spend some of it now

  • @richardbennett4365
    @richardbennett4365 7 หลายเดือนก่อน +7

    Wow!
    😮
    This one was made to 1) blow us away or 2) so Yurii can show off a bit.
    Seriously, though, he's brilliant. He really knows how to swim around in nixland's many different lakes, pools, and streams, navigating any of them like a Master...
    Yurii, you are the best! I'm going to apply this tutorial to my Home Manager to make it do some work for me. 😅😊

  • @krupkat
    @krupkat 7 หลายเดือนก่อน +4

    Fantastic editing, showing just enough to explain the topic, but not overwhelming.

  • @andoui1649
    @andoui1649 7 หลายเดือนก่อน +3

    Disabled my ad-block, cause your videos are to-the-point, understandable, and informative. Thanks for the videos and keep them coming! I need all the help I can get.

  • @blzr8
    @blzr8 7 หลายเดือนก่อน +3

    Ok woow
    I am going to use this method for any modularity need
    Thank u

  • @Jatsekku2
    @Jatsekku2 หลายเดือนก่อน +1

    I'm using NixOS for few months already, I love content you are producing!
    The way informations are presented is so clean and has logical continuation as well as justification for certain solutions.
    Hope you'll grow big bro!

  • @kexec.
    @kexec. 3 หลายเดือนก่อน +2

    I don’t know why so many people have trouble with this setup tbh. It’s most up to date setup right now that uses module system properly and can’t see any wrong part in here.

  • @jamessparling3182
    @jamessparling3182 7 หลายเดือนก่อน +3

    The vidoes on this channel just keep getting more useful

  • @__viperML
    @__viperML 7 หลายเดือนก่อน +3

    2:12 yes there is! see disabledModules in the nixos manual. (Though still a pain to work with)
    Thank you for the video, very nice

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน

      Another Vimjoyer skill issue. Buy yeah, I don't think we should recommend anyone starting with NixOS to use it

  • @arthursmalle2276
    @arthursmalle2276 7 หลายเดือนก่อน +4

    this was exactly what I needed 🙏now I can stop bothering everyone with stupid question in discord (for now lol)

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน

      👍

  • @kylejamesross
    @kylejamesross 7 หลายเดือนก่อน +2

    These are some awesome tips. I will be using these when I cleanup my config.

  • @NicolasBPierron
    @NicolasBPierron 7 หลายเดือนก่อน +1

    Nice and well explained video! Glad to see more people discover the joy of splitting configuration in logical units.
    🖖Enjoy stability and modularity.
    However, it is possible to "remove" a module using `disabledModules = [ ./module2.nix ];` which was introduced as a mean to re-implement an existing module in case newer versions of the programs are not trivial to handle by extending the existing module. Enable options remain a better pattern when possible.

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน

      Cool!

  • @akibahmed229
    @akibahmed229 7 หลายเดือนก่อน +2

    There can never be enough NixOS videos!

  • @patomackcodes4093
    @patomackcodes4093 7 หลายเดือนก่อน +2

    As always, fantastic content. Time to start organizing my config.

  • @Red-Config
    @Red-Config 7 หลายเดือนก่อน +2

    How did you know this is exactly what I needed. Thanks for the good videos!

  • @gungun974
    @gungun974 7 หลายเดือนก่อน +2

    For now special folder with import is enough for me. But since I’m preparing my self for the third reinstallation of my main server to NixOS. (It’s currently running AlmaLinux).
    It’s time to adopt a structure more modular for my next generation infra.
    Nix is amazing, it’s maybe strange to understand but it’s so flexible and powerful that it’s the first time I have the feeling of control.

  • @mikefdorst
    @mikefdorst 7 หลายเดือนก่อน +5

    One major gotcha when doing this with home-manager is that to access an option declared in nixos from home-manager, you must use `osConfig`, not `config`. For example: `config = lib.mkIf osConfig.my.desktop.hyprland.enable`

  • @xvrqt
    @xvrqt 6 หลายเดือนก่อน +1

    I like using flakes to make modules which I can easily include in my configurations as needed. So most my boxes have my CLI tools flake. Some have a desktop flake, others my piracy stack, etc... and this way they all benefit from flakes version pinning.

    • @xvrqt
      @xvrqt 6 หลายเดือนก่อน +1

      That said, the way flakes are evaluated makes developing them a PITA until you're like 99% the way done. Tweaking afterwards is still annoying but not as bad.

  • @flokkq7931
    @flokkq7931 7 หลายเดือนก่อน +1

    Great Video, really helps to get started woth nixOS

  • @atemoc
    @atemoc 7 หลายเดือนก่อน +1

    I modularized my NixOS config with various imports that can be enabled/disabled via configuration.nix, all in their own category (software, config, drivers...). This is mostly useful for me for laptop/desktop configuration, gaming/non-gaming, nvidia drivers and if it has optimus/prime, etc.
    When I did that, I got a lot of backlash telling me that I was "ruining the point of NixOS" because it wasn't a single file any more but a directory. But heh, whatever, it's just so much better this way for me.

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน +1

      It is the point of NixOS. It's supposed to be declarative and reproducible first, and "possible with one file" second. Having the exact same configuration on two machines is pretty much pointless unless they have same hardware and purpose.

    • @uima_
      @uima_ 7 หลายเดือนก่อน +3

      Why someone complain it is a directory instead of a file? It doesn't matter as long as all the files are in the same repo.

    • @atemoc
      @atemoc 7 หลายเดือนก่อน +2

      @@uima_ Exactly. And it makes it super easy for anyone to just include/not include whatever they don't want, it's literally a single character change in configuration.nix. It's neater than having to go into a multi-thousands lines long configuration.nix and having to tweak things from here.

  • @mhemaungthuwin7916
    @mhemaungthuwin7916 5 หลายเดือนก่อน +1

    Thank you brother. You save tons of my time.

  • @livtown
    @livtown 7 หลายเดือนก่อน +3

    perfect timing

  • @jdigi78
    @jdigi78 6 หลายเดือนก่อน +1

    Instead of using ./../ you can declare the path in your flake like hostPath = (self + "/hosts") and import the files with (hostPath + "/module-name.nix")

  • @ytuser6276
    @ytuser6276 7 หลายเดือนก่อน +1

    Snowfall Lib can save you from the hassle of manually importing modules, defining hosts, homes, overlays, etc, given you follow a specific folder structure

    • @ruroruro
      @ruroruro 7 หลายเดือนก่อน

      I am also currently using Snowfall Lib, because the repetitive manual imports are extremely annoying, but there are a few things that really annoy me in Snowfall. Some of the features feel a bit bloated and over-engineered (while at the same time not being sufficiently extensible/customizable) and the fact that you have to put everything into blah/default.nix instead of just blah.nix is annoying. Does anyone know of any alternatives (other than declaring all the imports manually or rolling your own version of it)?

  • @Desmodious
    @Desmodious 7 หลายเดือนก่อน +1

    Well i was already planning on doing somethink like this this weekend, nice

  • @MrKristian252
    @MrKristian252 7 หลายเดือนก่อน +1

    Incredible, good video!

  • @belak512
    @belak512 7 หลายเดือนก่อน +2

    Do you have any recommendations for how to handle nix-darwin vs nixos hosts? At the moment, I'm using something similar to what you're doing here, but with modules/darwin, modules/home, and modules/nixos (and a similar layout for hosts), but it's already getting hard remembering what goes where. Also, if you're using both nixos and home-manager, how do you decide what to install with nixos and what to install with home-manager?

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน +1

      I usually try to put as much stuff into home-manager as possible because it is portable. The NixOS config mostly contains services, a display manager, sound, GPU stuff, and things I need root access for.
      As for nix-darwin, I haven't had the chance to use it yet, sorry.

  • @mars_0008
    @mars_0008 7 หลายเดือนก่อน +2

    Great video choice

  • @droydi
    @droydi 7 หลายเดือนก่อน +1

    Thanks for another great video, reminds me of Snowfall, will you cover it soon?

  • @marcuswest4572
    @marcuswest4572 7 หลายเดือนก่อน +1

    Brilliant 11/10

  • @nodupe
    @nodupe 7 หลายเดือนก่อน +1

    loved it

  • @demattejoao
    @demattejoao 7 หลายเดือนก่อน +2

    can you make a video showing how to install a specific package version? on my job i have to use maven 3.8.6, but nixpkgs provides me the latest one
    great video btw!

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน

      Sure! But until then, check out the "Nix Dev Environments" video on the channel where I briefly mention how to do it.

  • @felixbjerhemaronsson8253
    @felixbjerhemaronsson8253 3 หลายเดือนก่อน

    How would you create a directory tree like the one at the end (with home-manager, and different home.nix files for each machine) using a standalone install of home-manager? I found that to be pretty unclear...

  • @LegendEaterPSR
    @LegendEaterPSR 7 หลายเดือนก่อน +1

    Good shit Vimmy

  • @filipesilva2500
    @filipesilva2500 7 หลายเดือนก่อน +1

    I don't understand one thing. In the last dir tree, there is no mention of the "home-manager.nix" file. So where would it be in the dir tree? Would it be in "./homeManagerModules"?
    I think this video is great by the way. I think I finally understood imports and how to structure my nixos configuration, the only part missing is the mentioned above and the fact that I'm still trying to fully understand the concept of how inputs work...

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน +1

      It should either be in nixosModules or your configuration.nix

    • @filipesilva2500
      @filipesilva2500 7 หลายเดือนก่อน +1

      @@vimjoyer Thank you for the answer, keep on doing these great videos! They have been helping me a lot and you are one of my main references if someone asks me how to learn NixOS/Nix!

  • @BoopyTheFox
    @BoopyTheFox 7 หลายเดือนก่อน +1

  • @TumbleGamerTK
    @TumbleGamerTK 7 หลายเดือนก่อน +1

    Im working on an ncurses menu to edit stuff and enforce git committing
    I havnt even installed nixos yet

  • @xarcaz
    @xarcaz 2 หลายเดือนก่อน +1

    @ 3:14, is `config = lib.mkIf config.module1.enable {` correct? Shouldn't the second config be options?

    • @vimjoyer
      @vimjoyer  2 หลายเดือนก่อน +1

      nah, it's correct. config attribute defines config, but the `config` we are accessing there comes from the parameter at the top, not the same set.

  • @Grizzlywer
    @Grizzlywer 7 หลายเดือนก่อน +2

    10 million clicks when?

  • @wadecurry938
    @wadecurry938 2 หลายเดือนก่อน

    At 3:27 you have module1.nix open and you define `options = {module1.enable = ; }; `, then you refer to it in the next line as `config.module1.enable` . Why isn't it `options.module1.enable`, or even `config.options.module1.enable`? This kind of thing seems to happen fairly often and it confuses the hell out of me because I can't reliably predict how to refer to an attribute/option/etc., and finding information about it can be challenging if I don't know the actual full name of the attribute. I'm sure I'm making it harder than it has to be, but I need a clue, please. On the bright side, if I notice a little hell creeping into me, I can always just work on some nix module I don't really understand. 🙂

  • @SimonLauer-qu9ns
    @SimonLauer-qu9ns 7 หลายเดือนก่อน +1

    could you also create a kind of root options module to turn on certain modules for example for different window managers if and only if this option is set to true?

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน

      You can define and declare options in different modules, so yeah, possibilities are endless

  • @brunek1322
    @brunek1322 7 หลายเดือนก่อน +3

    Hey there! Just wanted to drop some feedback on the second video I watched from you. So, the first part was crystal clear, but then it kinda ramped up in difficulty real quick. Like, I found myself struggling to keep up towards the end. Probably gonna have to rewatch that last part a few times, like I did last time. But hey, just to be clear, this isn't me coming at you or anything. Just thought I'd share my thoughts!

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน

      Thanks for the feedback! Yeah, I wanted to get the video out quicker, so there are some pacing issues once again.

  • @MWLaboratories
    @MWLaboratories 3 หลายเดือนก่อน +1

    This seems very important but it's a bit too fast to get a fresh install up to this kind of config for a beginner. I do have a laptop and rpi and desktop I'd like to get into one config

  • @ioio82
    @ioio82 7 หลายเดือนก่อน +1

    It was not clear what the content of the default.nix would be within nixosModules, is this correct?
    # modules importer
    { pkgs, lib, ... }:{
    imports = [
    ./services/service1.nix
    ./programs/program1.nix
    ./programs/program2.nix
    ];
    }

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน

      yes

  • @offlinebot5453
    @offlinebot5453 6 หลายเดือนก่อน +1

    what is the pro of using the home-manager in this system?

    • @vimjoyer
      @vimjoyer  6 หลายเดือนก่อน

      You get to use home-manager options and configure programs with it

  • @faccc
    @faccc 7 หลายเดือนก่อน +1

    If you're gullible, click on the video and press '3'

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน

      lol

  • @SimonLauer-qu9ns
    @SimonLauer-qu9ns 7 หลายเดือนก่อน

    started making toggles for all the nixvim config I am currently running :P

  • @vaisakh_km
    @vaisakh_km 7 หลายเดือนก่อน +1

    Hi, can you please tell how you are managing services in devshells?
    for eg: i wanted mariadb service for a dev purposes, but when i checked i had to enable in for entire system... any way to do this through just with in a devshell

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน

      Check "nixos-shell" on GitHub

    • @vaisakh_km
      @vaisakh_km 7 หลายเดือนก่อน +1

      ​@@vimjoyerthanks.. i will check that out.. i were used devenv in the past...
      but it felt weird and really got frustrated setting some python environment..

    • @vaisakh_km
      @vaisakh_km 7 หลายเดือนก่อน +1

      ​@@vimjoyerisn't it just nix in docker...

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน

      @@vaisakh_kmyeah, kinda

  • @hierax49
    @hierax49 6 หลายเดือนก่อน

    If anyone knows a way to automatically import all modules instead of having to do it manually like the video says, please say so.
    The only thing I found that does this is Haumea, but I can't get it to work for some reason.

  • @realrickastley
    @realrickastley 7 หลายเดือนก่อน +6

    one view, 55 seconds ago, bro fell off :(

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน +4

      0 views 7 comments

  • @lage_lage
    @lage_lage 7 หลายเดือนก่อน +3

    first

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน +3

      indeed

  • @mixthos
    @mixthos 7 หลายเดือนก่อน +3

    I had to make some changes to get the home-manager module configuration to work:
    * flake.nix: Add home-manager.nixosModules.home-manager to nixosConfigurations.*.modules
    * home-manager.nix: home-manager.sharedModules = [ inputs.self.outputs.homeManagerModules.default ]; (home-manager."username".* (7:13) doesn't seem to work at all?)
    * This also allowed me to put the global home-manager configuration in nixosModules and the user-specific imports in hosts/*/configuration.nix

    • @swaggeroo
      @swaggeroo 4 หลายเดือนก่อน +1

      Saved my life

  • @notcorrect
    @notcorrect 7 หลายเดือนก่อน +1

    You've have been getting me up to speed very quickly with your videos.
    I've gotten home manager to work from a previous video and wanted to improve it with this video but I got stuck.
    I placed home-manager.nix inside nixosModules and imported it in nixosModules/default.nix like so imports = [ ./home-manager.nix ] but got an error.
    The option `home-manager' does not exist. Definition values: nixosModules/home-manager.nix
    I think its something about home-manager not being declared before it loads home-manager.nix

    • @vimjoyer
      @vimjoyer  7 หลายเดือนก่อน +1

      You need to import the actual home-manager module provided by home-manager flake inside your home-manager.nix.

    • @notcorrect
      @notcorrect 7 หลายเดือนก่อน

      @@vimjoyer Thank you very much it worked by importing `inputs.home-manager.nixosModules.default` but unfortunately home-manager. does not exist. I will keep digging, I must have imported the wrong module.
      I found an alternative that did work by using the first version of the home-manager.nix file from the video and imported both home.nix and and homeManagerModules.default.