How to get the proper hashes from a github repo and commit?

Hey everyone, I finished packaging this app and I’m working on the update script.. I got everything work but I don’t know how to get the proper hashes nixos requires. I know I have to use nix eval but, I don’t know how. I already tried using a tool like nix-update and it doesn’t work with this package.

This is my update script currently.

#!/usr/bin/env nix-shell
#! nix-shell -i python -p python3Packages.githubkit

from githubkit import GitHub, UnauthAuthStrategy
from githubkit.versions.latest.models import (
    Commit,
    ContentSubmodule,
    Tag,
)

with GitHub(UnauthAuthStrategy()) as github:
    edopro: Tag = github.rest.repos.list_tags("edo9300", "edopro").parsed_data[0]

    ocgcore: ContentSubmodule = github.rest.repos.get_content(
        "edo9300", "edopro", "ocgcore"
    ).parsed_data

    irrlicht: Commit = github.rest.repos.list_commits(
        "edo9300", "irrlicht1-8-4"
    ).parsed_data[0]

with open("./pkgs/by-name/ed/edopro/deps.nix", "w") as file:

    contents = f"""
    # This is automatically generated by the update script.
    # DO NOT MANUALLY EDIT.
    {{
      edopro-version = "{edopro.name}";
      edopro-rev = "{edopro.commit.sha}";
      edopro-hash = "sha256-2E1cjG0FONu/fbr67/3qRCKQ1W/wPznClEWsMa1FAzo=";
      ocgcore-rev = "{ocgcore.sha}";
      ocgcore-hash = "sha256-s3DOHrZilRUy6fbXObNiLRinxpdHY99vDOmS/ZfOI78=";
      irrlicht-rev = "{irrlicht.sha}";
      irrlicht-hash = "sha256-Q2tNiYE/enZPqA5YhUe+Tkvmqtmmz2E0OqTRUDnt+UA=";
    }}
    """

    file.write(contents)

I think fetchFromGitHub fetches github.com/${owner}/${repo}/archive/${rev}.tar.gz, so you would probably need to use nix-prefetch-url with this url

I’m going to get that to work, but how do I trigger my update script? I know theres a command to run update scripts but I forget.

So after testing with this command It seems that I get a different hash than what I expected with

nix-prefetch-url --type sha256 --unpack github.com/edo9300/edopro/archive/c713e23491a1e55c9d8e91257e5f2b5873696b9b.tar.gz

It returns 1cdqvmmkc4j6by6xp5g39xnqzwq05jdbid1nzwzpcwh5kc832gcs

Which is not equal to the hash I have that is 2E1cj

I was testing this even more and it seems to be reproducible neither command gives me the correct hash

error: hash mismatch in fixed-output derivation '/nix/store/42n7y7hga9f861qbhxffjzkxm20j4ric-source.drv':
         specified: sha256-Q2tNiYE/enZPqA5YhUe+Tkvmqtmmz2E0OqTRUDnt+UA=
            got:    sha256-ZByRMe/0/HVE2yDRPuFE+GhiI6swgkU/tTTY8GvQz5g=
error: 1 dependencies of derivation '/nix/store/jbmfjfsprx41djafczkpnbizi2i916cv-irrlicht-edopro-1.9-custom.drv' failed to build
error: 1 dependencies of derivation '/nix/store/r883qrfgfslckyjxxz1xbr205q0ap8z1-edopro-40.1.4.drv' failed to build
error: 1 dependencies of derivation '/nix/store/0xxvqmdzrij0v9w8p1h03gnb7fj6i8sn-edopro-application-40.1.4.drv' failed to build

nixpkgs on  3dopolololo [!] via ❄  impure (shell) took 14s 
❯ nix-prefetch-url github.com/edo9300/irrlicht1-8-4/archive/eb657b02c64cb8bcf8dd1e4d12bfef2972c2fcd2.tar.gz --type sha256 
path is '/nix/store/ccmjbn012vpycfp165caz89xgyb7qz08-eb657b02c64cb8bcf8dd1e4d12bfef2972c2fcd2.tar.gz'
1qcfcvxv4dpjn689adgv0gw9k7b4p3f7cgm5svla7hlsbpn66nmz

nixpkgs on  3dopolololo [!] via ❄  impure (shell) took 2s 
❯ nix-prefetch-url github.com/edo9300/irrlicht1-8-4/archive/eb657b02c64cb8bcf8dd1e4d12bfef2972c2fcd2.tar.gz --type sha256 --unpack
path is '/nix/store/yp51ddr6sg6g4r9zwqqhk6v576r0bb58-eb657b02c64cb8bcf8dd1e4d12bfef2972c2fcd2.tar.gz'
166gs1mz1n1lnlzlb0ihmcin4s7q8khkxl90vd27bz7lxwqr2734

You want to use nix-prefetch-github

The top hash is an SRI hash, the bottom ones aren’t

After adding nix.settings.experimental-features = “nix-command flakes”; to your /etc/nixos/configuration.nix, you can use nix hash convert

See nix hash convert –-help.

In this case it would be nix hash convert --hash-algo sha256 --to sri 166gs1mz1n1lnlzlb0ihmcin4s7q8khkxl90vd27bz7lxwqr2734

Make sure you use the output hash from nix-prefetch-url https://github.com/edo9300/irrlicht1-8-4/archive/eb657b02c64cb8bcf8dd1e4d12bfef2972c2fcd2.tar.gz --type sha256 --unpack

Hope this helps anyone coming across this!