I’m once again trying to create a flake for a golang project at work, and since it has one dependency that’s in a private repo I’m once again struggling. I can’t believe there’s still no documented solution to this problem. Anyway, in a discussion on Matrix I was told someone else had gotten it to work by
- add the private repos of the dependencies to the
inputs
(marking them withflake = false
), and - modifying the
go.mod
usinggo mod edit --replace github.com/private/dep=${input_dev}
.
So I made a flake.nix
like this
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-24.05";
flake-utils.url = "github:numtide/flake-utils";
priv-dep = {
url = "git+ssh://git@github.com/private/dep.git?ref=v1.0.0";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, priv-dep, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
proj = pkgs.buildGo123Module {
pname = "tool";
version = "1.0.0";
src = ./.;
vendorHash = pkgs.lib.fakeHash;
preBuild = ''
echo 'preBuild - rewriting go.mod'
go mod edit --replace github.com/private/dep=${priv-dep}
'';
};
in {
packages.default = proj;
});
}
This seems to make the golang tools happy. The build phase succeeds, but then it fails with
error: illegal path references in fixed-output derivation '/nix/store/h68mm85avmcai30wkr5kpzak5av2d11b-tool-1.0.0-go-modules.drv'
error: 1 dependencies of derivation '/nix/store/496hnhbx856i6ynlpc7xcy5dzi4jdmr7-tool-1.0.0.drv' failed to build
and I’m at a loss how to solve this. TBH, I’m not even completely sure what the error means.
All help will be appreciated… or maybe I’m no the wrong path completely and and need to rethink this completely.