Installing mozilla overlays with home-manager

Hi,

I’d like to install mozilla overlays using home-manager. Note that I’d like the overlay to be available both when home-manager runs and afterward, because I’d like to use the nixpkgs.latest.rustChannels packages in my projects. Having the overlays when home-manager runs is easy:

# home.nix
{ config, pkgs, ... }:

let
  mozilla-overlays = import (builtins.fetchTarball {
      url = https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz;
  });
in {
  nixpkgs.overlays = [ mozilla-overlays ];
  nixpkgs.config.allowUnfree = true;
  home.packages = with pkgs; [
    latest.firefox-nightly-bin
  ];
}

But this does not install the overlays permanently. To do so, my idea was to have a derivation that would copy the overlays in the store, and use home-manager to write ~/.config/nixpkgs/config.nix:

let
  mozilla-overlays = pkgs.stdenv.mkDerivation rec {
    name = "mozilla-overlays";
    src = fetchTarball {
      url = https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz;
    };
    installPhase = "mkdir -p $out ; cp -r * $out";
  };
in {
  programs.home-manager.enable = true;
  home.stateVersion = "19.09";
  nixpkgs.config.allowUnfree = true;

  # Make the overlays available when home-manager runs
  nixpkgs.overlays = [ mozilla-overlays ];

  # Make the overlays available permanently
  xdg.configFile."nixpkgs/config.nix".text = "${mozilla-overlays}";

  home.packages = with pkgs; [
    latest.firefox-nightly-bin
  ];
}

However, that doesn’t work:

$ home-manager build
error: infinite recursion encountered, at /nix/store/v8n46qk2mx9izhpnvk43ygiy3d2gr5cj-nixos-20.03pre209690.c438ce12a85/nixos/lib/attrsets.nix:344:7
(use '--show-trace' to show detailed location information)
error: infinite recursion encountered, at /nix/store/v8n46qk2mx9izhpnvk43ygiy3d2gr5cj-nixos-20.03pre209690.c438ce12a85/nixos/lib/attrsets.nix:344:7
(use '--show-trace' to show detailed location information)
/home/corentin/.nix-profile/bin/home-manager: line 115: /tmp/home-manager-build.MZGv2mHbnS/news-info.sh: No such file or directory

I’m wondering if what I’m trying to achieve makes sense, or if it is an anti-pattern. If that makes sense, how could I make this work?

Perhaps something like

xdg.configFile."nixpkgs/overlays/mozilla-overlays".source = mozilla-overlays;

will work?

Oh, and I think

mozilla-overlays = fetchTarball {
  url = https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz;
};

should be sufficient, no need for mkDerivation.

1 Like

@rycee thank you that works to make the overlay permanent:

let
  mozilla-overlays = fetchTarball {
      url = https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz;
  };
in {
  programs.home-manager.enable = true;
  home.stateVersion = "19.09";
  nixpkgs.config.allowUnfree = true;
  xdg.configFile."nixpkgs/config.nix".source = mozilla-overlays;
}

However, I also want to install firefox nightly, so I want to also have these two lines:

  nixpkgs.overlays = [ mozilla-overlays ];
  home.packages = with pkgs; [
    latest.firefox-nightly-bin
  ];

But now I get:

error: The option value `nixpkgs.overlays.[definition 1-entry 1]' in `/home/corentin/.config/nixpkgs/home.nix' is not of type `nixpkgs overlay'.

AH! I think this works:

let
  mozilla-overlays = fetchTarball {
      url = https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz;
  };
in {
  programs.home-manager.enable = true;
  home.stateVersion = "19.09";
  nixpkgs.config.allowUnfree = true;
  xdg.configFile."nixpkgs/config.nix".source = mozilla-overlays;
  nixpkgs.overlays = [ (import "${mozilla-overlays}") ];
  home.packages = with pkgs; [
    latest.firefox-nightly-bin
  ];
}

Yes, nixpkgs.overlays expects a list of overlay expressions, not file paths. So this final version looks fine to me.