Adding an overlay on something else than nixpkgs

Hi there,

I’m trying to add an overlay to install a version of a package that is not already merged into nixpkgs unstable (this pull request). This is the first time I’m attempting this and being new to this I might be doing something stupid. I have a NixOs installation with Flake and Home-Manager.

flake.nix

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
    unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager/release-23.05";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixos-hardware.url = "github:NixOS/nixos-hardware/master";
    devenv.url = "github:cachix/devenv/latest";
    impermanence.url = "github:nix-community/impermanence/master";
  };
  outputs = { self, nixpkgs, unstable, home-manager, nixos-hardware, devenv, impermanence }:
  let
    system = "x86_64-linux";
  in {
    nixosConfigurations.mymachine = nixpkgs.lib.nixosSystem {
      inherit system;
      specialArgs = {
        unstablePkgs = unstable.legacyPackages.${system};
      };
      modules = [
        nixos-hardware.nixosModules.lenovo-thinkpad-t480
        impermanence.nixosModules.impermanence
        ./hosts/mymachine/nixos/configuration.nix
        home-manager.nixosModules.home-manager
        {
          home-manager = {
            useGlobalPkgs = true;
            useUserPackages = true;
            users.martin = import ./hosts/mymachine/home/home.nix;
            extraSpecialArgs = {
	      unfreePkgs = import unstable {
	        config.allowUnfree = true;
		inherit system; 
                overlays = [
                  (final: prev: {
                    anytype = prev.anytype.overrideAttrs (
		      _: {
		        version = "0.36.0";
			name = "Anytype-0.36.0";
                        src = prev.fetchurl {
                          url = "https://github.com/anyproto/anytype-ts/releases/download/v0.36.0/AnyType-0.36.0.AppImage";
                          name = "Anytype-0.36.0.AppImage";
                          sha256 = "sha256-Efoqy/izULDgd2Dc3ktVZNj9/U0vCtENm0NLr5VKQpQ=";
                        };
		      });
		  })
                ];
	      };
	     devenvPkgs = devenv.packages.${system};
	    };
          };
        }
      ];
    };
  };
}

Extract of home.nix

{ pkgs, agenixPkgs, devenvPkgs, unfreePkgs, ...}:
{
  home.packages = [
    unfreePkgs.anytype
  ];
}

Problem is that I don’t get the correct version of Anytype but the one already in the unstable repository although I do see the download of the newer version happening in the trace.

What am I doing wrong/not understanding ?

I do have a second question regarding this which is: is there a way to do this overlaying inside home-manager instead of the flake.nix file ? I’ve see that home-manager has a nixpkgs.overlays option but in my case it’s the unfreePkgs that I would like to overlay.

Thanks in advance !

Or you can temporarily use this NUR

Thanks for the pointer, maybe I’ll try that as well in the end. But for the sake of understanding better what is happening I would have liked to build the Anytype package using the updated definition and use this one instead. I don’t like my current solution anyway, what I’d like is to be able to point to your pull request and build only Anytype from it and have this as an overlay on the unstable that I will swap out once it is merged.

For question one.

flake.nix

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
    unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager/release-23.05";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixos-hardware.url = "github:NixOS/nixos-hardware/master";
    devenv.url = "github:cachix/devenv/latest";
    impermanence.url = "github:nix-community/impermanence/master";
    nixpkgs-anytype.url = github:NixOS/nixpkgs/377f148f94fbe46120cf169cf0799256e4227163;
  };
  outputs = { self, nixpkgs, unstable, home-manager, nixos-hardware, devenv, impermanence, nixpkgs-anytype }:
  let
    system = "x86_64-linux";
    overlay-anytype = final: prev: {
      anytype =  (import nixpkgs-anytype {
          system = prev.system;
          config.allowUnfree = true;
      }).anytype;
    };
  in {
    nixosConfigurations.mymachine = nixpkgs.lib.nixosSystem {
      inherit system;
      specialArgs = {
        unstablePkgs = unstable.legacyPackages.${system};
      };
      modules = [
        ({ config, pkgs, ... }: { nixpkgs.overlays = [ overlay-anytype ]; })
        nixos-hardware.nixosModules.lenovo-thinkpad-t480
        impermanence.nixosModules.impermanence
        ./hosts/mymachine/nixos/configuration.nix
        home-manager.nixosModules.home-manager
        {
          home-manager = {
            useGlobalPkgs = true;
            useUserPackages = true;
            users.martin = import ./hosts/mymachine/home/home.nix;
            extraSpecialArgs = {
	    
	     devenvPkgs = devenv.packages.${system};
	    };
          };
        }
      ];
    };
  };
}

and home.nix

{ pkgs, agenixPkgs, devenvPkgs, unfreePkgs, ...}:
{
  home.packages = [
    pkgs.anytype
  ];
}

For question 2:

in home.nix.

{ pkgs, agenixPkgs, devenvPkgs, unfreePkgs, ...}:

let 
  pkgsAnytype = import (pkgs.fetchFromGitHub { 
    owner = "NixOS";
    repo = "nixpkgs";
    rev = "377f148f94fbe46120cf169cf0799256e4227163";
    hash = "sha256-Ljkz6WSEGw5x3J9awZGNkOFdtdFl1GRk/mCq9Z0daX0=";
    # url = github:NixOS/nixpkgs/377f148f94fbe46120cf169cf0799256e4227163;
  }) {
    system = "x86_64-linux";
    config.allowUnfree = true;
  };
in 
{
  home.packages = [
    pkgsAnytype.anytype
  ];
}

Wow, thank you very much that’s very nice of you. I’m going to try that but I think I understand what you are doing.

Out of curiosity, do you have any hint as to why my first overlay was not working the way I thought it would? Because I saw the download happening so I was not doing everything wrong I guess, but in the end I did not have the correct version installed like if my overlay was not included in what ends up in unfreePkgs in the home.nix.

I guess it’s because anytype uses appimageTools. wrapType2 instead of’ stdenv. mkDerivation

Oh I see. So it should have work in principle.

Thank you very much.

anytype: 0.35.25-beta -> 0.36.0 by running-grass · Pull Request #269098 · NixOS/nixpkgs · GitHub is merged