Skip to content

burmudar/nix-cloudflare-caddy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Nix Cloudflare Caddy build

How to update and build

  1. Update the rev attribute in caddySrc to the version you want ie. v2.7.6
  2. Replace sha256 value with an empty string ie. sha256 = "";
  3. Do nix build which should tell you that it found an empty sha and assuming a value of ``. It will also list the sha value you should be using:
nix build
warning: Git tree '/home/william/code/nix-cloudflare-caddy' is dirty
warning: found empty hash, assuming 'sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='
error: hash mismatch in fixed-output derivation '/nix/store/gaw0d9km9rn3x1xsq7l38297m85j0mdf-cloudflare-caddy-v2.7.6-go-modules.drv':
         specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
            got:    sha256-dnKAwOrQkICkUVsyWJO+o2N4HcImLaL+fPyq8hUd5/8=
error: 1 dependencies of derivation '/nix/store/rmrwby0qal7i10z10di2fzlr7cfwmh3k-cloudflare-caddy-v2.7.6.drv' failed to build
  1. Replace sha256 with the sha value reported by nix-build
  2. With the sha256 value updated, run nix build again. The build might fail to apply the patch.
nix build
warning: Git tree '/home/user/code/nix-cloudflare-caddy' is dirty
error: builder for '/nix/store/b5gd2lmydb6j6y90rvnrspzzfn2jdj5v-cloudflare-caddy-v2.7.6.drv' failed with exit code 1;
       last 10 log lines:
       > applying patch /nix/store/ygf32kr7sy9zgp206flw60ca33im65ga-0001-cloudflare.patch
       > patching file cmd/caddy/main.go
       > patching file go.mod
       > Hunk #1 FAILED at 7.
       > Hunk #2 FAILED at 55.
       > 2 out of 2 hunks FAILED -- saving rejects to file go.mod.rej
       > patching file go.sum
       > Hunk #1 FAILED at 93.
       > Hunk #2 succeeded at 344 (offset -92 lines).
       > 1 out of 2 hunks FAILED -- saving rejects to file go.sum.rej
       For full logs, run 'nix log /nix/store/b5gd2lmydb6j6y90rvnrspzzfn2jdj5v-cloudflare-caddy-v2.7.6.drv'.
  1. If nix build failed to apply due to the patch then refer to How to update the patch` to resolve this.
  2. If nix build successfully applies the patch but complains about inconsistent vendoring we need to replace the vendorHash value with an empty string "", so that the build regenerates the internal vendor directory and ultimately a new vendor hash. As in step 3, when vendorHash is an empty string, the vendorHash that should be used will be printed.
  3. With the vendorHash updated, nix build should now succeed.

How to update the patch

  1. git clone github.com:caddyserver/caddy --branch v2.7.6 --single-branch where v2.7.6 is the tag or version we're interested in
  2. Edit ./cmd/caddy/main.go so that it looks like
package main

import (
	caddycmd "github.com/caddyserver/caddy/v2/cmd"

	// plug in Caddy modules here
	_ "github.com/caddy-dns/cloudflare"
	_ "github.com/caddyserver/caddy/v2/modules/standard"
)

func main() {
	caddycmd.Main()
}
  1. cd cmd/caddy

Important

The following steps have to be executed in cmd/caddy.

  1. go get github.com/caddy-dns/cloudflare
  2. Check that we can build it with go build .
  3. Generate the patch with git -P diff > 0001-cloudflare.patch
  4. Move the patch to the root of this repo. Since we're currently in the caddy repo at cmd/caddy to move to the root of THIS repo we have to execute mv 0001-cloudflare.patch ../../../0001-cloudflare.patch

About

nix flake to build caddy with cloudflare dns

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages