Hello everyone, I’m very close to finishing my configuration files for NixOS. I have those working on my nixos installation on my external drive, but before I officially move to nixos I’d like to make sure that I’m not doing something wrong.

Could someone please check my config files? (I only use flakes.nix, configuration.nix, home.nix and hardware.nix and I’d say they aren’t much complicated.)

My main concearn is that I probably use the import and modules functions wrong (yet somehow they work?). I’ve read and watched numerous guides for the last 3 months, but I think I still mess this up😅. I think following a bunch of different guides and videos added to the confusion a bit. (A recent guide I read made me have doubts about my set up.)

This is the link to my nixos configs:

https://codeberg.org/BlastboomStrice/dotfiles/src/branch/main/.config/nixos-conf

Hopefully by the end of the next week I’ll be posting here about having transitioned to linux/nixos:)

Sample of probably wrong usage of modules in flakes.nix
    outputs = {self, nixpkgs, ... }@inputs: {
      nixosConfigurations = {
      nixos = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        specialArgs = { inherit inputs; };
        modules = [
          ./hosts/default/configuration.nix

          inputs.home-manager.nixosModules.home-manager
          {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;

            home-manager.users.bs = import ./hosts/default/home.nix;

            home-manager.extraSpecialArgs = { inherit inputs; };
          }

#           inputs.spicetify-nix.nixosModules.default
Sample of probably wrong usage of imports in configuration.nix
imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      #inputs.home-manager.nixosModules.default
    ];

(I think I’m not using home manager in configuration.nix, that’s why I’ve commented it out, and I’m importing it directly in flakes.nix.)

  • rycee@lemmy.world
    link
    fedilink
    English
    arrow-up
    3
    ·
    17 hours ago

    Agree that there doesn’t seem to be anything weird here, the only suggestion I can add is that you could make it a bit more idiomatic by changing

    home-manager.users.bs = import ./hosts/default/home.nix;
    

    to

    home-manager.users.bs.imports = [ ./hosts/default/home.nix ];
    
  • algernon@lemmy.ml
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 day ago

    I’m not seeing anything wrong in the samples you provided. That’s pretty much how my own NixOS configuration looks (except mine’s a single monolithic flake.nix generated from Org Roam sources, but… the effect is the same anyway).

    • Blastboom Strice@mander.xyzOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 day ago

      Yo, thanks for this, I was a bit anxious that I might had been starting really wrong.😅😅

      May I ask a few more things (either directed to you or whoever wants to reply):

      1. As you can see, I pass the inputs argument in both specialArgs and extraSpecialArgs to be used in configuration.nix and home.nix. Do I make use of this argument inside those 2 files?
      2. In configuration.nix and home.nix I start with { config, pkgs, inputs, ... }: arguments. Should I do that? Should I remove/add anything? I suppose this uses config, pkgs and inputs from flakes.nix, making the specialArgs = { inherit inputs; }; and home-manager.extraSpecialArgs = { inherit inputs; }; in flakes.nix unecessary??
      3. Could I replace
        this sample in flakes.nix
        specialArgs = { inherit inputs; };
        		modules = [
        		  ./hosts/default/configuration.nix
        
        		  inputs.home-manager.nixosModules.home-manager
        		  {
        			home-manager.useGlobalPkgs = true;
        			home-manager.useUserPackages = true;
        
        			home-manager.users.bs = import ./hosts/default/home.nix;
        
        			home-manager.extraSpecialArgs = { inherit inputs; };
        		  }
        
        with
        this sample in flakes.nix??
        specialArgs = { inherit inputs; };
        extraSpecialArgs = { inherit inputs; };
        		modules = [
        		  ./hosts/default/configuration.nix
        
        		  inputs.home-manager.nixosModules.home-manager
        		  {
        			home-manager.useGlobalPkgs = true;
        			home-manager.useUserPackages = true;
        
        			home-manager.users.bs = import ./hosts/default/home.nix;
        
        			#home-manager.extraSpecialArgs = { inherit inputs; };
        		  }
        
        In my mind I think this change passes inputs of flakes.nix to any module that uses specialArgs (like the configuration.nix module) and extraSpecialArgs (like the home-manager module). Is this correct?

      Thanks for replying btw, it was a good confidence boost:)

      • rycee@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        17 hours ago

        You don’t seem to actually use inputs in your home.nix file so in principle you should be able to remove the

        home-manager.extraSpecialArgs = { inherit inputs; };
        

        line. Doesn’t hurt to keep it, though, if you think you may use inputs in the future.

        The change you propose in 3 would not work the way you expect, the extraSpecialArgs needs to be set for Home Manager, not NixOS. My guess is that the nixosSystem function simply would ignore the extraSpecialArgs parameter.