Hi,

I am using the following flake.nix in a gitlab runner to build gatewares for the Kasli.

{
  inputs = {
    artiq.url = "github:m-labs/artiq/release-8";
    nixpkgs.follows = "artiq/nixpkgs";
  };

  outputs =
    { self
    , nixpkgs
    , artiq
    }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs { inherit system; };

      artiqpkgs = artiq.packages.${system};

      configs = ./configs;
      projects = builtins.attrNames (pkgs.lib.filterAttrs (name: type: type == "directory") (builtins.readDir configs));
      gatewares = builtins.listToAttrs
        (builtins.map
          (name: {
            inherit name;
            value = artiq.makeArtiqBoardPackage rec {
              target = "kasli";
              variant = name;
              buildCommand = "python -m artiq.gateware.targets.${target} ${configs}/${name}/main.json";
            };
          })
          projects);
    in
    rec
    {
      packages.${system} = gatewares // {
        default = pkgs.symlinkJoin {
          name = "all";
          paths = builtins.attrValues gatewares;
        };
      };
    };
}

but unfortunately nix build . fails with

error: NAR hash mismatch in input 'git+https://github.com/m-labs/misoc.git?ref=refs/heads/master&rev=fea9de558c730bc394a5936094ae95bb9d6fa726&submodules=1', expected 'sha256-q+USDcaKHABwW56Jzq8u94iGPWlyLXMyVt0j/Gyg+IE=' but got 'sha256-WmX0ru9wPv3iMX9y03bY3vxjZcn2IAgUuQZ7bhRetX0='

I found some related posts on discours.nixos.org and the github repo of nix but haven't found a solution working for me.

Has anyone got such an error before? How did you solve it?

Best wishes,
Bodo

    Hi bodokaiser,

    Can you try to add the M-Labs binary cache to your Nix config?

    You can perhaps use this in your flake:

      nixConfig = {
        extra-trusted-public-keys = "nixbld.m-labs.hk-1:5aSRVA5b320xbNvu30tqxVPXpld73bhtOeH6uAjRyHc=";
        extra-substituters = "https://nixbld.m-labs.hk";
      };

    Or add it manually in the substituters and trusted-public-keys setting in /etc/nix/nix.conf.

    It should work without, though.

    Trying back and forth many different combinations, including, using different urls for artiq, and clearing nix's cache, store and configs in-between, I found it only to work when I add

    extra-trusted-public-keys = nixbld.m-labs.hk-1:5aSRVA5b320xbNvu30tqxVPXpld73bhtOeH6uAjRyHc=
    extra-substituters = https://nixbld.m-labs.hk

    to /etc/nix/nix.conf.

    Even with accept-flake-config = true in /etc/nix/nix.conf, nixConfig inside flake.nix is ignored on my system.

    I am using Almalinux 9 (successor of CentOS, used by our IT department) with v0.19 of the determinate nix installer (I had quite some issues with the vanilla nix installer for multi-user).

    To reproduce the NAR hash mismatch, I need to completely reinstall nix (just deleting the user's cache is not enough). Then without the extra-* parameters in the nix.conf, it fails again. When using nix with the -vvvv flag, I find a couple of warnings, which might be the issue of why I cannot build it without m-labs' binary cache:

    checking substituter 'https://cache.nixos.org' for path '/nix/store/zsqdizhqglanihnzrnidljcznvdnbbh0-source'
    entered goal loop
    substitution of '/nix/store/zsqdizhqglanihnzrnidljcznvdnbbh0-source': init
    substitution of '/nix/store/zsqdizhqglanihnzrnidljcznvdnbbh0-source': trying next substituter
    substitution of '/nix/store/zsqdizhqglanihnzrnidljcznvdnbbh0-source': trying next substituter
    path '/nix/store/zsqdizhqglanihnzrnidljcznvdnbbh0-source' is required, but there is no substituter that can build it
    substitution of '/nix/store/zsqdizhqglanihnzrnidljcznvdnbbh0-source': done
    substitution of '/nix/store/zsqdizhqglanihnzrnidljcznvdnbbh0-source': goal destroyed
    substitution of input 'git+https://github.com/m-labs/misoc.git?ref=refs/heads/master&rev=fea9de558c730bc394a5936094ae95bb9d6fa726&submodules=1' failed: error: path '/nix/store/zsqdizhqglanihnzrnidljcznvdnbbh0-source' does not exist and cannot be created
    locking path '/scratch-local/gitlab-runner/cache/nix/gitv3/0rsc3jc6f6j7icbxp6zlx02pmb6c4lihjhz2x4jj76vhrywa2l5p'
    lock acquired on '/scratch-local/gitlab-runner/cache/nix/gitv3/0rsc3jc6f6j7icbxp6zlx02pmb6c4lihjhz2x4jj76vhrywa2l5p.lock'
    fetching Git repository 'https://github.com/m-labs/misoc.git'...
    warning: could not update mtime for file '/scratch-local/gitlab-runner/cache/nix/gitv3/0rsc3jc6f6j7icbxp6zlx02pmb6c4lihjhz2x4jj76vhrywa2l5p/refs/heads/master': No such file or directory
    lock released on '/scratch-local/gitlab-runner/cache/nix/gitv3/0rsc3jc6f6j7icbxp6zlx02pmb6c4lihjhz2x4jj76vhrywa2l5p.lock'
    did not find cache entry for '{"_what":"gitLastModified","rev":"fea9de558c730bc394a5936094ae95bb9d6fa726"}'
    did not find cache entry for '{"_what":"gitRevCount","rev":"fea9de558c730bc394a5936094ae95bb9d6fa726"}'
    getting Git revision count of 'https://github.com/m-labs/misoc.git'...
    using revision fea9de558c730bc394a5936094ae95bb9d6fa726 of repo 'https://github.com/m-labs/misoc.git'
    Git submodule /misoc/cores/lm32/verilog/submodule: https://github.com/m-labs/lm32.git  84b3e3ca0ad9535acaef201c1482342871358b08 -> https://github.com/m-labs/lm32.git
    resolved HEAD ref 'refs/heads/master' for repo 'https://github.com/m-labs/lm32.git'
    locking path '/scratch-local/gitlab-runner/cache/nix/gitv3/0svzd3jrh8qj3fp5y213nri82a4jxn3jpacnygvy6gijri6rb6g1'
    lock acquired on '/scratch-local/gitlab-runner/cache/nix/gitv3/0svzd3jrh8qj3fp5y213nri82a4jxn3jpacnygvy6gijri6rb6g1.lock'
    fetching Git repository 'https://github.com/m-labs/lm32.git'...
    warning: could not update mtime for file '/scratch-local/gitlab-runner/cache/nix/gitv3/0svzd3jrh8qj3fp5y213nri82a4jxn3jpacnygvy6gijri6rb6g1/refs/heads/master': No such file or directory
    lock released on '/scratch-local/gitlab-runner/cache/nix/gitv3/0svzd3jrh8qj3fp5y213nri82a4jxn3jpacnygvy6gijri6rb6g1.lock'
    did not find cache entry for '{"_what":"gitLastModified","rev":"84b3e3ca0ad9535acaef201c1482342871358b08"}'
    did not find cache entry for '{"_what":"gitRevCount","rev":"84b3e3ca0ad9535acaef201c1482342871358b08"}'
    getting Git revision count of 'https://github.com/m-labs/lm32.git'...
    using revision 84b3e3ca0ad9535acaef201c1482342871358b08 of repo 'https://github.com/m-labs/lm32.git'
    Git submodule /misoc/cores/mor1kx/verilog: https://github.com/m-labs/mor1kx.git  b9e1cd6ee49940eec246605938a5d905d7e999d3 -> https://github.com/m-labs/mor1kx.git
    resolved HEAD ref 'refs/heads/master' for repo 'https://github.com/m-labs/mor1kx.git'
    locking path '/scratch-local/gitlab-runner/cache/nix/gitv3/1y9nczl9xxd5aq58bl59lnjylcgx7mx5f3zfczfgf64mpn08ssnk'
    lock acquired on '/scratch-local/gitlab-runner/cache/nix/gitv3/1y9nczl9xxd5aq58bl59lnjylcgx7mx5f3zfczfgf64mpn08ssnk.lock'
    fetching Git repository 'https://github.com/m-labs/mor1kx.git'...
    warning: could not update mtime for file '/scratch-local/gitlab-runner/cache/nix/gitv3/1y9nczl9xxd5aq58bl59lnjylcgx7mx5f3zfczfgf64mpn08ssnk/refs/heads/master': No such file or directory
    lock released on '/scratch-local/gitlab-runner/cache/nix/gitv3/1y9nczl9xxd5aq58bl59lnjylcgx7mx5f3zfczfgf64mpn08ssnk.lock'
    did not find cache entry for '{"_what":"gitLastModified","rev":"b9e1cd6ee49940eec246605938a5d905d7e999d3"}'
    did not find cache entry for '{"_what":"gitRevCount","rev":"b9e1cd6ee49940eec246605938a5d905d7e999d3"}'
    getting Git revision count of 'https://github.com/m-labs/mor1kx.git'...
    using revision b9e1cd6ee49940eec246605938a5d905d7e999d3 of repo 'https://github.com/m-labs/mor1kx.git'
    Git submodule /misoc/cores/vexriscv/verilog: https://github.com/m-labs/VexRiscv-verilog.git  2e4f43d72404a986c9d7251d9d543cf7aef077bc -> https://github.com/m-labs/VexRiscv-verilog.git
    resolved HEAD ref 'refs/heads/master' for repo 'https://github.com/m-labs/VexRiscv-verilog.git'
    locking path '/scratch-local/gitlab-runner/cache/nix/gitv3/06fsdx4afhvaqkn57m8fj0767wh5bmfg9hwjp7i4733hcgkwkcf0'
    lock acquired on '/scratch-local/gitlab-runner/cache/nix/gitv3/06fsdx4afhvaqkn57m8fj0767wh5bmfg9hwjp7i4733hcgkwkcf0.lock'
    fetching Git repository 'https://github.com/m-labs/VexRiscv-verilog.git'...
    warning: could not update mtime for file '/scratch-local/gitlab-runner/cache/nix/gitv3/06fsdx4afhvaqkn57m8fj0767wh5bmfg9hwjp7i4733hcgkwkcf0/refs/heads/master': No such file or directory
    lock released on '/scratch-local/gitlab-runner/cache/nix/gitv3/06fsdx4afhvaqkn57m8fj0767wh5bmfg9hwjp7i4733hcgkwkcf0.lock'
    did not find cache entry for '{"_what":"gitLastModified","rev":"2e4f43d72404a986c9d7251d9d543cf7aef077bc"}'
    did not find cache entry for '{"_what":"gitRevCount","rev":"2e4f43d72404a986c9d7251d9d543cf7aef077bc"}'
    getting Git revision count of 'https://github.com/m-labs/VexRiscv-verilog.git'...
    using revision 2e4f43d72404a986c9d7251d9d543cf7aef077bc of repo 'https://github.com/m-labs/VexRiscv-verilog.git'
    Git submodule /misoc/software/compiler_rt: https://github.com/llvm-mirror/compiler-rt.git  7f1c97c76620a6ee795792e6120d98a7edf81e65 -> https://github.com/llvm-mirror/compiler-rt.git
    resolved HEAD ref 'refs/heads/master' for repo 'https://github.com/llvm-mirror/compiler-rt.git'
    locking path '/scratch-local/gitlab-runner/cache/nix/gitv3/0padfbwz9xbpg55gdfiqvk5k5sp3n5kifr47h3jmqa5y10n170pd'
    lock acquired on '/scratch-local/gitlab-runner/cache/nix/gitv3/0padfbwz9xbpg55gdfiqvk5k5sp3n5kifr47h3jmqa5y10n170pd.lock'
    fetching Git repository 'https://github.com/llvm-mirror/compiler-rt.git'...
    warning: could not update mtime for file '/scratch-local/gitlab-runner/cache/nix/gitv3/0padfbwz9xbpg55gdfiqvk5k5sp3n5kifr47h3jmqa5y10n170pd/refs/heads/master': No such file or directory
    lock released on '/scratch-local/gitlab-runner/cache/nix/gitv3/0padfbwz9xbpg55gdfiqvk5k5sp3n5kifr47h3jmqa5y10n170pd.lock'
    did not find cache entry for '{"_what":"gitLastModified","rev":"7f1c97c76620a6ee795792e6120d98a7edf81e65"}'
    did not find cache entry for '{"_what":"gitRevCount","rev":"7f1c97c76620a6ee795792e6120d98a7edf81e65"}'
    getting Git revision count of 'https://github.com/llvm-mirror/compiler-rt.git'...
    using revision 7f1c97c76620a6ee795792e6120d98a7edf81e65 of repo 'https://github.com/llvm-mirror/compiler-rt.git'
    did not find cache entry for '{"_what":"fetchToStore","fingerprint":"fea9de558c730bc394a5936094ae95bb9d6fa726;s","method":"nar","name":"source","path":"/","store":"/nix/store"}'
    copying '«git+https://github.com/m-labs/misoc.git?ref=refs/heads/master&rev=fea9de558c730bc394a5936094ae95bb9d6fa726&submodules=1»/' to the store...

    So maybe git+https://github.com/m-labs/misoc.git is our troublemaker dependency? Maybe also this nix issue on GitHub is related?

    Also, I haven't had any problems with the single-user nix install on WSL2, which I use for development.

    6 days later

    I also tried a fresh installation of nix multi-user to reproduce the issue, but it builds fine. I'm using nix version 2.23.3.

      @fsagbuya I will soon do a reinstall on a fresh AlmaLinux install. Is there anything I should try or log to get more insights into this issue?

      fsagbuya Did you use the flake.nix I posted or your own? On the fresh install, I also don't have problems but I also don't use any of the dependencies like misoc or migen, which seem to cause the problem

        bodokaiser The issue here is not related to the flake.nix file. I've previously encountered a similar problem here using nix 2.22.0, as the ARTIQ flake also uses misoc.

        As previously mentioned, the issue appears to stem from Nix's handling of git, especially with submodules. The problem seems to have been addressed by this commit and is resolved in nix 2.23+.

        This might explain why I couldn't reproduce the issue, even with a fresh installation of Linux and Nix. Perhaps you could try updating to a newer version of Nix and check if the issue persists.