Skip to content

Instantly share code, notes, and snippets.

@vamega
Created June 6, 2022 20:53
Show Gist options
  • Save vamega/1065557052877f313726f977c2f36139 to your computer and use it in GitHub Desktop.
Save vamega/1065557052877f313726f977c2f36139 to your computer and use it in GitHub Desktop.
Caddy build failure with Nixpkgs 22.05
{ vendorSha256, lib, buildGo117Module, fetchFromGitHub, nixosTests
, plugins ? [ ] }:
let
version = "2.5.1";
dist = fetchFromGitHub {
owner = "caddyserver";
repo = "dist";
rev = "v${version}";
sha256 = "sha256:1h91sb2fzfyzaaw4z2ga8pgcwfx4hp9x1s9ca940vf31kk1lydza";
};
imports = lib.flip lib.concatMapStrings plugins (pkg: " _ \"${pkg}\"\n");
main = ''
package main
import (
caddycmd "github.com/caddyserver/caddy/v2/cmd"
_ "github.com/caddyserver/caddy/v2/modules/standard"
${imports}
)
func main() {
caddycmd.Main()
}
'';
in buildGo117Module {
pname = "caddy";
inherit version;
proxyVendor = true;
subPackages = [ "cmd/caddy" ];
src = fetchFromGitHub {
owner = "caddyserver";
repo = "caddy";
rev = "v${version}";
sha256 = "sha256:1nlphjg5wh5drpwkm4cczrkxdzbv72ll7hp5x7z6ww8pzz3q10b3";
};
inherit vendorSha256;
overrideModAttrs = (_: {
name = "caddy-webserver-go-modules-3";
sourceRoot = "source/cmd/caddy";
modRoot = "cmd/caddy";
postConfigure = ''
go mod init caddy
go mod tidy
'';
preBuild = ''
echo '${main}' > main.go
cat main.go
pwd
'';
postBuild = "cd ../..";
postInstall = "cp go.sum go.mod $out/ && ls $out/";
});
postPatch = ''
echo '${main}' > cmd/caddy/main.go
cat cmd/caddy/main.go
'';
postBuild = ''
cp vendor/go.sum ./
cp vendor/go.mod ./
'';
preInstall = ''
ls -la
pwd
echo ${dist}
ls -la ${dist}
'';
postInstall = ''
install -Dm644 ${dist}/init/caddy.service ${dist}/init/caddy-api.service -t $out/lib/systemd/system
substituteInPlace $out/lib/systemd/system/caddy.service --replace "/usr/bin/caddy" "$out/bin/caddy"
substituteInPlace $out/lib/systemd/system/caddy-api.service --replace "/usr/bin/caddy" "$out/bin/caddy"
'';
passthru.tests = { inherit (nixosTests) caddy; };
meta = with lib; {
homepage = "https://caddyserver.com";
description = "Fast, cross-platform HTTP/2 web server with automatic HTTPS";
license = licenses.asl20;
maintainers = with maintainers; [ Br1ght0ne techknowlogick ];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment