Custom Options and If-else Statements in Your NixOS Config

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ต.ค. 2024
  • Join as a Channel Member:
    / @librephoenix
    Join Liberapay: liberapay.com/...
    Join Patreon: / librephoenix
    Hello everyone! Merry Christmas! I haven't posted in a while.. I'm back again today with another NixOS video (which I admittedly made a long time ago, but just haven't had a chance to post).
    This discussion is about custom options and if-else statements for your NixOS configuration. Thanks for watching! Please subscribe for more NixOS/Linux/FOSS content!
    Associated Blog Post: librephoenix.c...
    Previous Tutorial: • How to Start Adding Mo...
    Links referenced:
    Types in Nixpkgs Source Code: github.com/Nix...
    Nix Pills: nixos.org/guid...
    MyNixOS: mynixos.com/
    My configuration (if you're curious):
    GitHub: github.com/lib...
    GitLab: gitlab.com/lib...
    Codeberg: codeberg.org/l...
    Wallpaper backgrounds were found on freepik.com.

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

  • @NicolasBPierron
    @NicolasBPierron 9 หลายเดือนก่อน +12

    Just a few notes:
    - Options are declared in the `options` attribute set, and defined in the `config` attribute set.
    - Presenting `if .. then .. else ..` in the context of modules is a recipe for infinite loop as soon as you want to wrap more than a single option definition, which is why `mkIf` got introduced.
    Apart from that, this is a nice walk-through on how to add variability to existing`configuration.nix` / `home.nix` modules, which starts to make sense as soon as you want to reuse code with some minor differences.

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

    This video just saved me hours of tinkering... especially the part that explains why a config set must be created when some option declaration exist.

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

    Best Series on nix ever Period
    😭 For fist time in my life, i actually understood nix and declarative....
    i have been using nix for 6-8 months having no idea what's going on, today i understood

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

      Forgot to say thank you ❤️

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

    I honestly couldn't find a list of lib.types besides your blog post. Reading source code isn't very friendly for sure.

  • @pldcanfly
    @pldcanfly 8 หลายเดือนก่อน +2

    Thank you for your videos. How you explain NixOS really makes it click for me and helps to organize the initial confusion about what the configs job is, what a flake does differently (and especially that it's not a 1:1 replacement for the configuration.nix-file, but rather another way to read it) and where home-manager comes in, and what it does.

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

    hello Librephoenix i love to see a video on nixos neovim config as there are many ways configuration nvim on nix but i cant find the a reliable way to do so and there are things like nixvim but dot hove support of lazy . i would love to see how you manger your nvim config , i know you use Emacs and your primary editor .

  • @ibrahimKaraagac
    @ibrahimKaraagac 10 วันที่ผ่านมา

    Very nice series of videos. Thank you for doing this!

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

    Excellent. What I really like about your explanations is that they include *what's really happening*.
    So the config/options things and how omitting both is really a shortcut makes everything make sense.
    And even the little things, such as : "attribute set containing an attribute set" where others say slightly inaccurate things like "nesting curly braces is a shorthand for the dots".
    Btw: how different data types merge would be an interesting thing to go over at some point.

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

    Love your videos, you are a great teach ie explaining everything thoroughly and how different components connect to each other.
    Would love to see videos going through source code and explaining and teaching and building awesome stuff
    😃

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

    Maybe one thing you could have mentioned in this video is how to do string concatenation in Nix. But great video again.

  • @biscotty6669
    @biscotty6669 5 หลายเดือนก่อน

    If-then-else in nix is like the ternary operator in scripting languages.

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

    Amaizing, Thank you so much! Questioin: what is the browser you are using in the video when browsing github 11:25 ?

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

      Glad you found it helpful! Qutebrowser is my browser of choice: qutebrowser.org/

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

    You are doing the Lords work here. Thanks for these vids. I am using these as my primary source to setup my Nixos config coming from just having a single home-manager setup

    • @librephoenix
      @librephoenix  9 หลายเดือนก่อน

      Thanks! I'm glad the videos have been helpful to you :)

  • @mars_0008
    @mars_0008 4 หลายเดือนก่อน

    how did you get qutebrowser top open in the terminal?

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

      I understand that's not inside a terminal. He launched the browser and he have x-ray defined in Hyprland so you're able to see through the window. Seems that he's also using emacs so that's probably from where he launched it. For more in-depth he must have this configured somewhere in his dotfiles.

  • @abelgerli
    @abelgerli 8 หลายเดือนก่อน

    The context how to use modularity is very important to manage your settings for the settings that are important to you. The context shows how to use the nix programming language in real use cases that can benefit development as well als corporate as home lab environments. 😊
    Showing the modularity with NixOs on a rasberry Pi and a x64 architecture could show that the work of modularity pays of big time in heterogenous NixOS environments.
    As a proxmox user i would love to see debian replaced as a base distro some day. But right now we should use NixOS to share our configurations without hazzle.

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

    Love the content. Helped me understand a lot.
    But literally sounds normal at 1.25x 😂

  • @plebiannn
    @plebiannn 9 หลายเดือนก่อน

    Exactly what I have been looking for, thanks!

  • @papanito4802
    @papanito4802 8 หลายเดือนก่อน

    Cool video, very nicely explained

  • @bonfireatnight3998
    @bonfireatnight3998 8 หลายเดือนก่อน

    There is one thing that confuses me ever since I've started reading up on NixOS. We write this system configuration file. The file defines a lambda expression. That is, if we would import the file manually, we would have to provide an attribute set with the arguments for the function parameters. As return value we would receive an set whose attributes Nix "understands".
    Now, of course this is not what we actually do. We run `nixos-rebuild` based on the content of this file. So, where to the arguments for the parameters come from?
    Until watching your videos I thought that the input `config` value comes from the _previous_ system generation. I thought it was there to make aspects of the _coming_ configuration depend on how things previously were. However, after your video I suspect things are much more... circular?!
    Take the example where packages are installed based on the Window Manager that is to be used. In `if config.` gets its value from the _output_, doesn't it? I mean, it asks whether _in the configuration we are currently defining_ we will use this or that window manager?
    Something about this I find very confusing. I guess it works somehow because of the lazy property of the Nix language. Still, would this mean that I wouldn't be able to produce the output if I removed `config` from the inputs? And would this mean that this wouldn't work because the output couldn't be its own input anymore?
    Anyway, thanks very much for your great videos! With every new production things are gradually making more sense.

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

      I'm not sure I follow your question, but I think your concept of inputs and outputs is off. There is no in and out, there is no before and after. There are just attributes with values. The order you declare them makes no difference. If you declare thing A in terms of thing B, all that matters is B is declared somewhere.

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

      What I got from these videos is that the NixOS utilities import the function exported by your configuration and call them with the attribute set, then makes use of the result.
      In the JavaScript world, this would be like Webpack or ESLint making use of an exported function:
      const createConfig = (webpackContextOrSomething) => ({ ... /* webpack options */ });
      export default createConfig;

  • @haru02w89
    @haru02w89 9 หลายเดือนก่อน

    First 🎉. Thanks

  • @akibahmed229
    @akibahmed229 9 หลายเดือนก่อน

    We'll explore every angle

  • @davidjeters
    @davidjeters 9 หลายเดือนก่อน

    How would something like this work if you were using startx and wanted to switch between two window managers such as awesome or xmonad? How would you pass an option to change both the xinitrc and the window managers?

    • @librephoenix
      @librephoenix  9 หลายเดือนก่อน

      Hmm.. That sounds like something different entirely, because with this framework it would imply that you have one wm installed at a time, and you merely are rebuilding your system to switch to a different wm. You could try making wrapper scripts using pkgs.writeShellScriptBin. For example, if you include both of these in environment.systemPackages or home.packages, it might do what you're thinking: (pkgs.writeShellScriptBin "startxmonad" ''# write a script here to use startx to start xmonad''') and (pkgs.writeShellScriptBin "startawesome" ''# write script here to use startx to start awesome'')

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

    Of all the Nix instructors out there, I find myself coming back to LP. Very methodical. Why do you rebuild? You can just test Do you have some sort of 'learning hub'?

  • @nullifi3r
    @nullifi3r 9 หลายเดือนก่อน

    Your work in this playlist on NixOS is reeeeeeealy helpful. I got to know NixOS from like 3 weeks ago and without a doubt, your content is easily one of the best 3 educational resources I found online. Thank You, I really appreciate your work.
    With your technical explanation superpowers , I hope you make a playlist about emacs for total beginners 😅.
    keep rolling this great content