Mixing unstable, stable & home-manager

I have a problem with mixing unstable, stable & home-manager that I cannot figure out. Any help would really be appreciated.

I am trying to use helix in its newest version (23.10) instead of the previous (23.05). This works for root, but not for non-root:

$ hx --version
helix 23.05
$ sudo -i
# hx --version
helix 23.10 (f6021dd0)

which is what is expected with the follwing configuration (3 files following):

I bring in home-manager and unstable like this:

sudo nix-channel --add https://github.com/nix-community/home-manager/archive/release-23.05.tar.gz home-manager
sudo nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixos-unstable
sudo nix-channel --update

My /etc/nixos/configuration.nix is essentially this:

{ pkgs, ...}:
let
  unstable = import <nixos-unstable> {};
in {
  imports = [
    ./hardware-configuration.nix
    <home-manager/nixos>
  ];
  nix.settings.experimental-features = [ "nix-command" "flakes" ];
  environment.systemPackages = [
    unstable.helix
    pkgs.zsh
  ];
  users.users.jps = {
    # ...
  };
  home-manager = {
    extraSpecialArgs = { inherit unstable; };
    useGlobalPkgs = false;
    useUserPackages = true;
    users.jps = import ./home.nix;
  };
  system.stateVersion = "23.05";

The home.nix is essentially

{ config, pkgs, unstable, ... }:
{
  imports = [
    ./helix.nix
  ];
  home = {
    stateVersion = "23.05";
    sessionVariables = {
      EDITOR = "hx";
    };
    packages = [
      pkgs.helix
      pkgs.zsh
    ];
    # ...
  };
}

and helix.nix is just including a configuration file:

{
  programs.helix.enable = true;
  xdg.configFile."helix/config.toml".source = ../common/helix/config.toml;
}

Now, if I try to use the helix package from unstable (like root does) by changing home.nix to

    packages = [
      unstable.helix
      pkgs.zsh
    ];

then I get a collision:

error: collision between `/nix/store/nayfcdjkl4d1n5w5c0n72np99zvy9x3m-helix-23.10/bin/.hx-wrapped' and `/nix/store/1g9pz0sc47y6v3q7ya6mik0gj37vjiay-helix-23.05/bin/.hx-wrapped'

Why is that?

This setting also adds a version of helix to home.packages: https://github.com/nix-community/home-manager/blob/ecd0a800f716b80a6eac58a7ac34d6d33e6fa5ee/modules/programs/helix.nix#L171

Since home.packages ends up symlinking stuff into a bin directory, you end up with two helix symlinks that both want to end up in the same location and therefore a conflict.

You want to use the programs.helix.package option to set the helix package to use, and not add it to home.packages at all:

# home.nix
{ config, pkgs, ... }:
{
  imports = [
    ./helix.nix
  ];
  home = {
    stateVersion = "23.05";
    sessionVariables = {
      EDITOR = "hx";
    };
    packages = [
      # don't put `pkgs.helix` *or* `unstable.helix` here
      pkgs.zsh
    ];
    # ...
  };
}
# helix.nix
{ unstable, ... }: {
  programs.helix = {
    enable = true;
    package = unstable.helix;
  };
  xdg.configFile."helix/config.toml".source = ../common/helix/config.toml;
}
1 Like

Yes! That worked, thank you so much.

– Cheers
/JP