I’ve been trying nixos recently and after watching a bunch of tutorials from various people, I have managed to enable home-manager and flakes.

My question is: where should I write the packages I want to install? In home.nix? In flakes.nix? In configuration.nix (probably not)? I’m probably only gonna have a single user on this machine.

So far, I think the only difference between writing the packages in home.nix compared to flakes.nix is that in the 1st senario, the apps will only be available for the user, while in the 2nd, it will be available for the whole system. Also, I could use the home.nix for non-nixos systems too. Other than that, I can probably write them the same way either on home.nix or flakes.nix and have the same result on my machine.

PS. On search.nixos.org there is an option to search for flakes. What is this? I am planing to get my packages from the packages tab, but I’m wondering that maybe I should search in the flakes tab instead (though it doesn’t seem to have many packages).

PPS. Those are some resources I’ve found (I’ve mainly watched the videos and have started reading some of the guides):

  • vividspecter@lemm.ee
    link
    fedilink
    English
    arrow-up
    7
    ·
    9 days ago

    System packages in configuration.nix, user packages in home.nix. I’d say anything that is non-interactive and/or requires root access is a good rule of thumb for system packages. Beyond that I try to use modules for configuring packges and there is usually only one of nixos and home manager options (sometimes there are duplicates).

    As for flakes I mostly use it to handle a bunch of different systems from one config and any flake specific configs. I also use standalone flakes for dev environments but that’s not related to the system config.

    • Blastboom StriceOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      9 days ago

      Ay, thanks for answering! I need some help understanding this😅

      there is usually only one of nixos and home manager options (sometimes there are duplicates).

      This means usually I only have to add options only in home.nix or configuration.nix, not both. (What about options in flakes.nix? Should I search those on the flakes/options tab?)

      As for flakes I mostly use it to handle a bunch of different systems from one config and any flake specific configs.

      Would it be the same if I put the system packages in flakes.nix instead of configuration.nix? Will it have a different result? Will I have to write them differently?

      Extra questions:

      1. Does putting a package in home.nix have the same version control flakes provides?

      2. Once I enabled home-manager, I saw that in ~/.config/nixos a flakes.nix and a home.nix files appeared. I already have a flake.nix and a home.nix files in my etc/nixos directory. What’s going on?

      3. Does putting packages in configuration.nix use the version control flakes provide?

      • vividspecter@lemm.ee
        link
        fedilink
        English
        arrow-up
        2
        ·
        edit-2
        9 days ago

        (What about options in flakes.nix? Should I search those on the flakes/options tab?)

        Not quite sure what you mean here. I normally only configure out-of-tree packages as flake modules (or whatever the term is), and I don’t think there is an official collection/search page for these. It’s mainly that certain packages require it like lanzaboote, and home-manager for that matter.

        Once I enabled home-manager, I saw that in ~/.config/nixos a flakes.nix and a home.nix files appeared. I already have a flake.nix and a home.nix files in my etc/nixos directory. What’s going on?

        It sounds like you configured home-manager system wide, probably through /etc/nixos/flake.nix, but then called the home-manager executable. If you did configure it like this then you do not need to call home-manager ever since nixos-rebuild etc commands will handle this for you.

        Does putting packages in configuration.nix use the version control flakes provide?

        Typically, it will be configured to follow inputs.nixpkgs so packages will use versions of whatever revision is currently pulled. In my system that is:

        inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
        

        and then you essentially pass that to configuration.nix, and home.nix.

        And although you seem to already be using flakes, when you call:

        nix flake update
        

        a new revision of input.nixpkgs will be pulled, and so packages configured in configuration.nix will be updated when you next call

        nixos-rebuild switch
        

        or whatever you used to update your system.

        Refer to: https://nixos-and-flakes.thiscute.world/

        if you haven’t already as there is where I got started from for the most part. There’s a lot more detail I missed since nix and flakes are pretty complex (and I don’t fully understand much of it either).

        • Blastboom StriceOP
          link
          fedilink
          English
          arrow-up
          2
          ·
          8 days ago

          Oh thank you, that’s a lot of important info you gave me :)

          You probably solved some/many of my problems, I’ll keep digging. Thanks again!

  • Klaymore@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    3
    ·
    8 days ago

    Personally I just put all my packages in configuration.nix (well, broken up into different files but all in environment.systemPackages). I only use home manager for extra config options for programs like Git, Neovim, or VSCodium. I only have one user so I see no reason for me to separate them.

    I never use the flakes search, if I find a flake on github or somewhere then it will say how to add it as a flake input and enable it. That’s mostly for extra modules or things like beta versions of software that haven’t been added to the official repos yet, almost all of my packages are from the standard packages.

    • Blastboom StriceOP
      link
      fedilink
      English
      arrow-up
      3
      ·
      8 days ago

      I should suppose that you have flakes enabled and have imported the configuration.nix inside flakes.nix, thus keeping everything versioned with flakes.lock, right?

      • Klaymore@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        3
        ·
        8 days ago

        Yeah, and I have home-manager as the nixos module, not standalone. My config is here if you were interested. Some of it is a little messy but it’s pretty good.

        • Blastboom StriceOP
          link
          fedilink
          English
          arrow-up
          2
          ·
          7 days ago

          Oh thank you! Will take a look and see what I can use for mine:)

          It’s so cool that you can do all these with nixos