Flake with home manager

Hi!

I am trying to use flake with home-manager and am having some problems.
This is my flake:

{
  description = "jeansib's flake";

  inputs = {
    nixpkgs-unstable = {
      url = "github:nixos/nixpkgs/nixos-unstable";
    };
    nixpkgs-24-11 = {
      url = "github:nixos/nixpkgs/nixos-24.11";
    };
    nix-flatpak = {
      url = "github:gmodena/nix-flatpak/";
    };
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, nixpkgs-unstable, nixpkgs-24-11, nix-flatpak, home-manager, ... }@inputs:
    let
      system = "x86_64-linux";
    in
    {
      defaultPackage.x86_64-linux = home-manager.defaultPackage.x86_64-linux;

      homeConfigurations = {
        "jeansib" = home-manager.lib.homeManagerConfiguration {
          modules = [ ./home.nix ];
          extraSpecialArgs = {
            pkgs-unstable = import nixpkgs-unstable {
              inherit system;
            };
            pkgs-24-11 = import nixpkgs-24-11 {
              inherit system;
            };
            inherit inputs;
          };
          pkgs = import nixpkgs;
        };
        modules = [
          nix-flatpak.nixosModules.nix-flatpak
          ./home.nix
        ];
      };
    };
}

When I run flake update and home-manager switch I get the following error:

[jeansib@dell-3:~/.config/home-manager]$ nix flake update 

[jeansib@dell-3:~/.config/home-manager]$ home-manager switch 
error:
       … while selecting an attribute
         at /nix/store/alm3nymx19kvkc8my31niws5d81b9pri-source/flake.nix:41:65:
           40|         hm = (import ./modules/lib/stdlib-extended.nix nixpkgs.lib).hm;
           41|         homeManagerConfiguration = { modules ? [ ], pkgs, lib ? pkgs.lib
             |                                                                 ^
           42|           , extraSpecialArgs ? { }, check ? true

       error: expected a set but found a function: «lambda @ /nix/store/v0g0bxsd5gw6k0jz2855f8h7l1218925-source/pkgs/top-level/impure.nix:14:1»

[jeansib@dell-3:~/.config/home-manager]$ 

What am I doing wrong?

Also, THESE are lines 40, 41 and 42:

        };
        modules = [
          nix-flatpak.nixosModules.nix-flatpak

Why it shows wrong?

I could be wrong but maybe he doesn’t like the second modules list outside of the home-manager.lib.homeManagerConfiguration block.

Also this line: pkgs = import nixpkgs;
Where do you set your nixpkgs input?

Oh, I didn’t see that module line. I tried many things and I forgot to delete it, but it doesn’t make any difference.

I don’t exactly know why I need that line pkgs = import nixpkgs;, I added it to satisfy nix’ complain, this is the output of “home-manager switch” without that line.

[jeansib@dell-3:~/.config/home-manager]$ home-manager switch --verbose --show-trace
error:
       … from call site
         at /nix/store/srcwbp6pcscp4d5551djisbfiy6vlm5n-source/flake.nix:28:29:
           27|       homeConfigurations = {
           28|         "jeansib" = home-manager.lib.homeManagerConfiguration {
             |                             ^
           29|           extraSpecialArgs = {

       error: function 'homeManagerConfiguration' called without required argument 'pkgs'
       at /nix/store/alm3nymx19kvkc8my31niws5d81b9pri-source/flake.nix:41:36:
           40|         hm = (import ./modules/lib/stdlib-extended.nix nixpkgs.lib).hm;
           41|         homeManagerConfiguration = { modules ? [ ], pkgs, lib ? pkgs.lib
             |                                    ^
           42|           , extraSpecialArgs ? { }, check ? true

[jeansib@dell-3:~/.config/home-manager]$ 

I want to have two options in installing software: I want to be able to install some packages from unstable branch, and some from stable. How do I implement it to my home.nix file?

You need a pkgs attrset in the home manager configuration. Therefore, you need to move the stable (your default package set, if by default you want stable packages) from extraSpecialArgs to where pkgs previously have been, but also correctly set it to the result of a function:

pkgs = import nixpkgs-24-11 { inherit system; };
# Or like this:
pkgs = nixpkgs-24-11.legacyPackages.${system};

Then you use pkgs.firefox to install the stable Firefox version and pkgs-unstable.firefox to install the unstable version.

Also the inputs.nixpkgs here should be inputs.nixpkgs-unstable.

And remove nixpkgs, from this line:

Allowing this type of error is one of flakes’ biggest design mistakes IMO.

FYI this would be incorrect since they’re using the master branch of HM. They must therefore use unstable nixpkgs by default.

TIL. I did realise this. And since I am using unstable everything, there was never any problem on my side. Thank you for clarification.

Okay, thank you very much for your answer, that worked!