I have a flake called “Custom nixpkgs flake” that creates an overlay of nixpkgs and adds a package named hello-nix
to nixpkgs. I have another flake called “local flake” that tries to consume that overlay, and use hello-nix
in a devShell
. For some reason this isn’t working, and instead is just throwing a sha hash mismatch when there shouldn’t be one.
The “Custom nixpkgs flake” looks like this:
{
description = "Custom nixpkgs flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs =
{ self, nixpkgs, ... }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
};
in
{
overlays.default = final: prev: {
hello-nix = pkgs.callPackage ./pkgs/by-name/hello-nix/package.nix { };
};
packages.${system} = {
hello-nix = pkgs.callPackage ./pkgs/by-name/hello-nix/package.nix { };
};
};
}
I have this file in a github repository at github:megaloblasto/custom-nixpkgs
. In that same reporepository, in the location ./pkgs/hello-nix/
there is a package.nix
file that looks like this:
{ lib
, stdenv
, fetchFromGitHub
, coreutils
, gcc
}:
stdenv.mkDerivation {
pname = "hello-nix";
version = "0.1";
src = fetchFromGitHub {
owner = "megaloblasto";
repo = "hello-nix";
rev = "master"; # You can specify a commit hash or a tag here if needed
sha256 = "sha256-VP+R+GcvLOd+Hu1n0/zNoMCSVTnZXm44N+KJKQuQlfw=";
};
buildInputs = [ coreutils gcc ];
# Build Phases
configurePhase = ''
declare -xp
'';
buildPhase = ''
gcc "$src/hello.c" -o ./hello
'';
installPhase = ''
mkdir -p "$out/bin"
cp ./hello "$out/bin/"
'';
}
This points to another github repo at github:megaloblasto/hello-nix/
which has the following hello.c
file:
#include <stdio.h>
int main(int argc, char const *argv[])
{
printf("Hello from megaloblasto \n");
return 0;
}
Finally, I have another local flake.nix
file that looks like this:
{
description = "local flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
custom-nixpkgs.url = "github:megaloblasto/custom-nixpkgs";
};
outputs = { self, nixpkgs, custom-nixpkgs, ... }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
overlays = [ custom-nixpkgs.overlays.default ];
};
in
{
devShells.${system}.default = pkgs.mkShell {
name = "default";
packages = [
pkgs.hello-nix
];
};
};
}
When I run nix develop
using this local flake, I get the error:
error: hash mismatch in fixed-output derivation '/nix/store/f6dbmpb4w7m8yyn9yfyd013zx6dcblja-source.drv':
specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
got: sha256-VP+R+GcvLOd+Hu1n0/zNoMCSVTnZXm44N+KJKQuQlfw=
But, as you can see, I did change the sha hash to the appropriate value. Furthermore, if I run nix build .#hello-nix
in the “Custom nixpkgs flake”, hello-nix builds flawlessly.
What am I doing wrong here? Why can’t I consume this overlay, and why is it giving me a sha hash mismatch?