How do I use specific nixpkgs versions in overlays using a flake config?

There is this now very long running issue with pcloud making it impossible to make it run with any nixpkgs version newer than 22.11.

In the linked issue, there are examples of how to apply an overlay to get current versions running while using nixpkgs version 22.11.

The seemingly trivial issue for me is that they are using flake-utils and I’m using a config based on the minimal nix starter config.

I’ve done a few other overlays, but always using the default nixpkgs defined in the flake.

I’d prefer not to switch to flake-utils, as I prefer not to introduce another dependency unless absolutely necessary.

Would be very thankful for any help. I’m sure this is a very basic issue but I’ve been unable to solve it myself.

1 Like

I’m not sure if that’s the best way, but what I do is:

{
  inputs = {
    # ...

    nixpkgs = {
      url = "github:nixos/nixpkgs/nixos-unstable";
    };

    nixpkgs-rust-analyzer = {
      url = "github:nixos/nixpkgs";
    };

    # ...
  };

  outputs =
    { self
    # ...
    , nixpkgs
    , nixpkgs-rust-analyzer
    }:
    {
      darwinConfigurations = {
        mac = darwin.lib.darwinSystem {
          # ...

          modules = [
            # ...

            ({ pkgs, ... }: {
              nixpkgs = {
                overlays = [
                  (self: super: {
                    # ...
                    
                    rust-analyzer = (import nixpkgs-rust-analyzer {
                      system = "aarch64-darwin";
                    }).rust-analyzer;
                  })
                ];
              };
            })
          ];
        };
      };
    };
}

Thank you!

I had solved my problem on my own by referencing how overlays for unstable packages were done in the standard config I referenced but didn’t have the time yet to write it up.

In flake.nix:

{
  inputs = {
    # Nixpkgs
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    hardware.url = "github:nixos/nixos-hardware";

    # for pcloud
    nixpkgs_22_11.url = "github:nixos/nixpkgs/nixos-22.11";
    (...)
  };

  outputs = {
    self,
    nixpkgs,
    nixpkgs_22_11,
    home-manager,
}  @ inputs: let

and then the typical rest as in the standard config.

In the file overlays/default.nix (Could have been put elsewhere, but I was trying to follow the structure provided):

{
  inputs,
  ...
}: {
  old-packages = final: _prev: {
    pkgs_22_11 = import inputs.nixpkgs_22_11 {
      system = final.system;
      config.allowUnfree = true;
    };
  };
}

In the file where I define my packages:

{
  lib,
  config,
  inputs,
  pkgs,
  ...
}: {
  nixpkgs = {
    overlays = [
      (final: prev: {
        pcloud = pkgs.pkgs_22_11.pcloud.overrideAttrs (prev: let
          version = "1.14.0";
          code = "XZpL8AVZAqfCXz5TebJ2gcvAiHi15pYFKPey";
          # Archive link's codes: https://www.pcloud.com/release-notes/linux.html
          src = pkgs.fetchzip {
            url = "https://api.pcloud.com/getpubzip?code=${code}&filename=${prev.pname}-${version}.zip";
            hash = "sha256-uirj/ASOrJyE728q+SB7zq0O9O58XDNzhokvNyca+2c=";
          };

          appimageContents = pkgs.appimageTools.extractType2 {
            name = "${prev.pname}-${version}";
            src = "${src}/pcloud";
          };
        in {
          inherit version;
          src = appimageContents;
        });
      })
    ];
    config = {
      allowUnfree = true;
    };
  };

(my other packages)
};

So a bit different, but same result. No actual reasons why both the nixpkgs and the pcloud overlay couldn’t be in the same file, but that’s how it is for now for other reasons.

Thank you for your answer, it gives me another way of doing things.

1 Like