Enabling package in home manager causes it to use an old version

Whenever I enable yazi in home manager with the following:

programs.yazi = {
    enable = true;
};

It causes the version to go to Yazi 0.3.3 (Nixpkgs 2024-09-04) but when I comment that out it picks up the version from my configuration.nix environment.systemPackages (version 25.3.2).

I tried adding the following to configuration.nix but that doesn’t help:

  home-manager.useGlobalPkgs = true;

Also don’t see anything in the example given in the installation instructions that sets the version in home manager:

{pkgs, ...}: let
	yazi-plugins = pkgs.fetchFromGitHub {
		owner = "yazi-rs";
		repo = "plugins";
		rev = "...";
		hash = "sha256-...";
	};
in {
	programs.yazi = {
		enable = true;
		enableZshIntegration = true;
		shellWrapperName = "y";

		settings = {
			manager = {
				show_hidden = true;
			};
			preview = {
				max_width = 1000;
				max_height = 1000;
			};
		};

		plugins = {
			chmod = "${yazi-plugins}/chmod.yazi";
			full-border = "${yazi-plugins}/full-border.yazi";
			toggle-pane = "${yazi-plugins}/toggle-pane.yazi";
			starship = pkgs.fetchFromGitHub {
				owner = "Rolv-Apneseth";
				repo = "starship.yazi";
				rev = "...";
				sha256 = "sha256-...";
			};
		};

		initLua = ''
			require("full-border"):setup()
			require("starship"):setup()
		'';

		keymap = {
			manager.prepend_keymap = [
				{
					on = "T";
					run = "plugin toggle-pane max-preview";
					desc = "Maximize or restore the preview pane";
				}
				{
					on = ["c" "m"];
					run = "plugin chmod";
					desc = "Chmod on selected files";
				}
			];
		};
	};
}

I’m sure it must be something trivial, but I’ve already sunk six hours going down this rabbit hole. Any suggestions would be greatly appreciated.

Maybe you have an old channel on your user profile? Try running nix-channel --list. It is different than sudo nix-channel --list.

nix-channel --list gives me:

home-manager https://github.com/nix-community/home-manager/archive/release-24.11.tar.gz

and sudo nix-channel --list gives:

nixos https://channels.nixos.org/nixos-24.11

That’s good to double check, but all looks right there. Thank you for the suggestion. Ideally the solution would be something along those lines. Like if there was a way to set home-manager to use the same global packages that nixos uses. Honestly, not sure why that isn’t the default. I’d really like to stay away from having to use an overlay, or something along those lines, for every package that I use in home-manager to declare its user config file.

Anyway, thanks again. I’ll grab some coffee and keep digging.

https://search.nixos.org/packages?channel=24.11&from=0&size=50&sort=relevance&type=packages&query=yazi
So, yazi is 0.3.3 on nixos-24.11, but it’s 25.3.2 on nixos-unstable. If you want the later you should add nixos-unstable channel and use programs.yazi.package option of HM to override the package.

I used librephoenix’s technique to use both stable and unstable channels, and added yazi to the unstable package list in nixos.

How do I point to that package in home manager using programs.yazi.package? They don’t provide any examples in the documentation aside from the default being pkgs.yazi. So I tried:

{ pkgs-unstable, ... }: {

  programs.yazi = {
    enable = true;
    package = pkgs-unstable.yazi;
  };

But that made it angry. I’ve never done this before. Do you have any tips?

Skimming the video, that would imply you’re using flakes. Could you share the rest of your configuration, including how you set up your packages? Explaining what you mean by “angry” helps too - without an exact error message or the context that shows what you’ve done we’d need to be fortune tellers to help.

Instead of linking videos you’ll probably get more helpful replies actually showing what you have in general; reading a post is way quicker and more accurate than trying to figure out which parts of a 20+ minute video you followed.

1 Like

Sure thing. Here’s my flake.nix:

{
  description = "Main Hyprnix Flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
    nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
    home-manager.url = "github:nix-community/home-manager/release-24.11";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    nix-flatpak.url = "github:gmodena/nix-flatpak"; # unstable branch. Use github:gmodena/nix-flatpak/?ref=<tag> to pin releases.
    hyprpanel.url = "github:Jas-SinghFSU/HyprPanel";
    hyprswitch.url = "github:h3rmt/hyprswitch/release";
    # wpaperd.url = "github:danyspin97/wpaperd";
    # yazi.url = "github:sxyazi/yazi";
  };

  outputs =
  { nixpkgs, nixpkgs-unstable, home-manager, hyprswitch, nix-flatpak, ... }@inputs:
  let
    system = "x86_64-linux";
    pkgs = nixpkgs.legacyPackages.${system};
    pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
  in {
    nixosConfigurations = {
      hyprnix = nixpkgs.lib.nixosSystem {
        inherit system;
        specialArgs = {
          inherit system;
          inherit inputs;
          inherit pkgs-unstable;
        };
        modules = [
          ./nixos/configuration.nix
          { _module.args = { inherit inputs; }; }
          {nixpkgs.overlays = [inputs.hyprpanel.overlay];}
          nix-flatpak.nixosModules.nix-flatpak
          home-manager.nixosModules.home-manager {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users."guttermonk" = import ./home/home.nix; # CHANGE ME
          }
          ({ pkgs, ... }: {
            environment.systemPackages = [
              hyprswitch.packages.${pkgs.system}.default
              # wpaperd.packages.${pkgs.system}.default
     	      # yazi.packages.${pkgs.system}.default
    	    ];
          })
        ];
      };
    };
    homeConfigurations = {
      guttermonk = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        extraSpecialArgs = {
          inherit nixpkgs-unstable;
        };
        modules = [
          ./home/home.nix
          ({ pkgs, ... }: {home.packages = [
            # wpaperd.packages.${pkgs.system}.default
            # yazi.packages.${pkgs.system}.default
          ];})
        ];
      };
    };
  };
}

And from what I can gather from the error message, it thinks the attribute is missing when I tried setting programs.yazi.package equal to ‘nixpkgs-unstable’ and ‘pkgs-unstable’ which I don’t really get since I have inherit nixpkgs-unstable; as an extraSpecialArgs in the homeConfigurations section of the flake.nix (shown above).

Yeah, so that explains a fair bit. You’ve gotten the standalone and NixOS module home-manager setups confused, and you don’t really understand modules :slight_smile:

I’d start with removing all of homeConfigurations - assuming this is your only system, you’re not using that anyway. If you wanted to, you’d need to use the home-manager binary instead of nixos-rebuild.

Next up, you’d want to actually configure your home-manager. Add to your in-line module (not a function argument, put it on its own set of lines so it’s clearer to you):

{
  home-manager = {
    useGlobalPkgs = true;
    useUserPackages = true;
    # Anything added to this attrset will be available from
    # module args.
    extraSpecialArgs = {
      # Note that you're adding the input here, so you'll need
      # to use `nixpkgs-unstable.legacyPackages.${pkgs.system}.yazi
      # instead of `pkgs-unstable.yazi`
      inherit nixpkgs-unstable;
    };

    users."guttermonk" = import ./home/home.nix; # CHANGE ME
  };
}

The options for this module are defined here, by the way: Appendix B. NixOS Configuration Options

Furthermore, this almost certainly means you’ve previously installed yazi with nix-env, as you weren’t using unstable for anything else. I’d urge you to remove all packages you have installed with nix-env, alongside any channels you have on your system. You’re using flakes, not channels.


Finally, if I may be so bold as to give some NixOS config structure advice; instead of packing the modules list in your flake.nix full of gunk, add those modules as part of your config - especially any in-line modules.

By that I mean, replace all of this:

… with just ./nixos/configuration.nix, and then in nixos/configuration.nix you would do this:

{ inputs, ... }: {
  imports = [
    # This part I could be convinced comes down to preference,
    # but if you have more than one system writing these for
    # each system gets old fast, especially if you add more in
    # the future.
    inputs.nix-flatpak.nixosModules.nix-flatpak
    inputs.home-manager.nixosModules.home-manager
  ];

  environment.systemPackages = [
    inputs.hyprswitch.packages.${pkgs.system}.default
    # inputs.wpaperd.packages.${pkgs.system}.default
    # inputs.yazi.packages.${pkgs.system}.default
  ];

  nixpkgs.overlays = [
    inputs.hyprpanel.overlay
  ];

  # This has always been superfluous, you add `inputs` to
  # `specialArgs` already.
  # _module.args = { inherit inputs; };

  home-manager = {
    useGlobalPkgs = true;
    useUserPackages = true;
    extraSpecialArgs = {
      # Note that you're adding *all* inputs here, so now you need
      # `inputs.nixpkgs-unstable`. I would recommend this, but
      # you could use `inherit (inputs) nixpkgs-unstable` if you
      # want to be more specific.
      inherit inputs;
    };

    users."guttermonk" = import ./home/home.nix; # CHANGE ME
  };

  # ... Any other config already in here
}

I hope breaking apart that list makes it a bit clearer what “modules” are, and helps you keep your config a bit more organized.

After that, you could refactor your nixosSystem call to just this:

nixpkgs.lib.nixosSystem {
  inherit system;
  specialArgs = {
    inherit inputs;

    # inherit system;   - You could just use `pkgs.system`
    # inherit pkgs-unstable;   - You could just use `inputs.nixpkgs-unstable.legacyPackages.${system}`
  };
  modules = [
    ./nixos/configuration.nix
  ];
}
2 Likes

That worked brilliantly. Thank you so much! This is going to take me some time to digest and refactor, but I’ve already learned a lot. Cheers!