Install a package from a specific commit

Hello everyone:

I want to install Anki version 2.1.64 on my system via home-manager (since when I was on Arch Linux only, the version that had decent font rendering was that, in previous versions and current 2.1.65 the sources in Wayland are broken), then try using the following code to install the version I want:

{ config, pkgs, ... }:

{
  # ...

    home.packages = with pkgs; [

     (anki-bin.overrideDerivation (oldAttrs: {
       version = "2.1.64";
       sources = {
         linux = fetchurl {
          url = "https://github.com/ankitects/anki/releases/download/${version}/anki-${version}-linux-qt6.tar.zst";
          sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
        };
      };
    }))
    # Other packages.

  ];

  # ...

 }

But after running home-manager switch, I get the following error:

error: cannot coerce a set to a string

       at /home/anderson/.config/home-manager/home.nix:17:7:

           16|       version = "2.1.64";
           17|       sources = {
             |       ^
           18|         linux = fetchurl {
(use '--show-trace' to show detailed location information)

So please can someone help me to install this version of Anki?

URLs:
Git Release
Nixpkgs Sources

Post-Data: I don’t speak English, all this text was translated using some translator on the internet, I apologize for any inaccuracies there may be; I’m also a complete newbie to Nix…

That package does not seem very easy to override, most of the code is inside a let ... in.
Instead of wasting your time with bad ways to override it, here is my pragmatic advice: just copy that file into your configuration, modify it and import it like this:

{
  home.packages = with pkgs; [
    (callPackage ./your-modified-anki-bin.nix {})
  ];
}

Side-note: You most likely never want to use overrideDerivation: nixpkgs manual: overrideDerivation.

2 Likes

A somewhat curious question, how do you calculate the hash?, because I downloaded the file and used the sha256sum command and pasted the hash, but when I use your solution, Nix complains saying that they do not match (I still put the one that appeared in the message error and it worked).

Post-Data: Thanks for your help, your answer worked perfectly. I had no idea about the existence of the callPackage function.

Most of the time that’s what I do too, except I set the hash to an empty string to guarantee that nix will not pick the incorrect file from the cache, If you change the url, but not the hash, that can happen.

fetchurl {
  url = "https://github.com/ankitects/anki/releases/download/${version}/anki-${version}-linux-qt6.tar.zst";
  sha256 = "";
};

This annoyance with having to manually update hashes is one of the reasons I use flakes even though they’re experimental.

1 Like

Oh I see. Thank you very much for your help!

1 Like