Installing an overlay

Hi y’all.

I am struggling with overlays. My system uses flake.nix+home-manager, and I am really getting confused how to set up an overlay.

Basially, I want to install the latest version of zotero, for which I used this guy’s guide: Valentin Pratz - NixOS: Adding Zotero Beta as an Overlay

The relevant structure of my nix-config setup is as follows:

├── nixos-config
│   
│   ├── flake.nix
│   ├── home
│   │   ├── default.nix
│   ├── overlays
│   │   ├── default.nix

Basically, I pasted the code from the zotero guide in ‘‘overlays/default.nix’’, and added the line

  outputs = { nixpkgs, home-manager,... }@inputs: {
    nixosConfigurations = {
      NixOS = nixpkgs.lib.nixosSystem {
        specialArgs = { inherit inputs; };
        system = "x86_64-linux";
	      modules = [
                 (import ./overlays)
        ]
    };

However, I am really lost, should I add the zotero package in the home manager, what tells nixos rebuild to install zotero, etc…

I am not really explaining my problem super well, since I do not think I understood how overlays work (I understood they are used to change packages, but besides that…).

Any help will be appreciated :wink:

Maybe FYI, here is the content of the overlays/default.nix

{ config, pkgs, lib, ... }:

{
  nixpkgs.overlays = [
 (final: prev: { 
  zotero = prev.zotero.overrideAttrs (old: with prev.zotero; rec {
    version = "0cab24fb8";

    libPath = prev.zotero.libPath + ":" + prev.lib.makeLibraryPath [
      prev.alsa-lib
      prev.xorg.libXtst
    ];
    src = pkgs.fetchurl {
      url = "https://download.zotero.org/client/beta/7.0.0-beta.48%2B${version}/Zotero-7.0.0-beta.48%2B${version}_linux-x86_64.tar.bz2";
      hash = "sha256-IbTCQr32dknmy8aqQe4u6ymlQ+2VNSqHcFZDbV26Wbo=";
    };
    meta.knownVulnerabilities = [ ];
    postPatch = "";

    installPhase = ''
      runHook preInstall

      mkdir -p "$prefix/usr/lib/zotero-bin-${version}"
      cp -r * "$prefix/usr/lib/zotero-bin-${version}"
      mkdir -p "$out/bin"
      ln -s "$prefix/usr/lib/zotero-bin-${version}/zotero" "$out/bin/"

      # install desktop file and icons.
      mkdir -p $out/share/applications
      cp ${desktopItem}/share/applications/* $out/share/applications/
      for size in 16 32 48 256; do
        install -Dm444 chrome/icons/default/default$size.png \
          $out/share/icons/hicolor/''${size}x''${size}/apps/zotero.png
      done

      for executable in \
        zotero-bin plugin-container \
        updater minidump-analyzer
      do
        if [ -e "$out/usr/lib/zotero-bin-${version}/$executable" ]; then
          patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
            "$out/usr/lib/zotero-bin-${version}/$executable"
        fi
      done
      find . -executable -type f -exec \
        patchelf --set-rpath "$libPath" \
          "$out/usr/lib/zotero-bin-${version}/{}" \;

      runHook postInstall
    '';
  });
  })
  ];
}

The main idea of overlays is that it allows adding or changing attributes(packages) in pkgs. In this case when something in your config would pull in pkgs.zotero – the overridden version will be installed.

To have this version installed – you can add environment.systemPackages = [ pkgs.zotero ]; somewhere in your configuration.

Okay, I thought so, but when I add zotero via my home manger in home/default.nix via

{ pkgs, ...} : {
  home.packages = with pkgs; [
    zotero
  ];
}

I get the nixpkgs version of zotero installed. Maybe I should somehow let home-manger (and not my flake) ‘know’, that I want it to use the overlay??

After adding it I just do nix rebuild --switch from the flake directory…

Are you using home-manager as a module or running it standalone? Looks like module, since not seeing the home-manager part of the flake, but just to make sure.

I cut out the home manager part of the flake. Here is the entire flake:

{
  description = "flake for NixOS";
  inputs = { 
    nixpkgs.url = "github:NixOS/nixpkgs/release-23.11"; 
    home-manager.url = "github:nix-community/home-manager/release-23.11";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { nixpkgs, home-manager,  ... }@inputs: {
    nixosConfigurations = {
      NixOS = nixpkgs.lib.nixosSystem {
        specialArgs = { inherit inputs; };
        system = "x86_64-linux";
	      modules = [
 	        (imports ./overlays)

	        # Home manager
	        home-manager.nixosModules.home-manager
	        {
	          home-manager.useGlobalPkgs = true;
	          home-manager.useUserPackages = true;
	          home-manager.users.test_user = import ./home;
	        }
	      ];
      };
    };
  };
}

I was thinking, maybe I have to add the overlays to the NIX_PATH as written in the wiki (Overlays - NixOS Wiki).

On the system level
If you want your overlays to be accessible by nix tools and also in the system-wide configuration, add nixpkgs-overlays to your NIX_PATH:
NIX_PATH="$NIX_PATH:nixpkgs-overlays=/etc/nixos/overlays"

because in /etc/nixos/overlays, I indeed see the added zotero overlay.

Okay, I got nowhere…

Maybe an answer doing the overlay from scratch with what is put where will be the only way to help out at this point… :smiley: