diff --git a/go/nix/bcacheup/bcacheup.go b/go/nix/bcacheup/bcacheup.go index 3f7777504a..ab9d6f84e7 100644 --- a/go/nix/bcacheup/bcacheup.go +++ b/go/nix/bcacheup/bcacheup.go @@ -16,8 +16,8 @@ import ( "sync" "time" + "github.com/jamespfennell/xz" "github.com/numtide/go-nix/nixbase32" - "github.com/ulikunitz/xz" "gocloud.dev/blob" "golang.org/x/sync/errgroup" "golang.org/x/sync/singleflight" @@ -236,10 +236,7 @@ func (u *uploader) uploadContent(ctx context.Context, ni *narinfo.NarInfo, path fileByteCounter := &byteCounterWriter{} - xzWriter, err := xz.NewWriter(io.MultiWriter(fileHasher, fileByteCounter, dst)) - if err != nil { - return fmt.Errorf("creating xz writer: %v", err) - } + xzWriter := xz.NewWriter(io.MultiWriter(fileHasher, fileByteCounter, dst)) w := io.MultiWriter(narHasher, xzWriter) narSize, err := nar.Pack(w, nar.DirFS(u.storePath), filepath.Base(path)) diff --git a/go/nix/bcacheup/default.nix b/go/nix/bcacheup/default.nix index 54ae48cfb7..008d5f583c 100644 --- a/go/nix/bcacheup/default.nix +++ b/go/nix/bcacheup/default.nix @@ -14,7 +14,7 @@ depot.third_party.buildGo.program { third_party.gopkgs."gocloud.dev".blob.gcsblob third_party.gopkgs."golang.org".x.sync.errgroup third_party.gopkgs."golang.org".x.sync.singleflight - third_party.gopkgs."github.com".ulikunitz.xz + third_party.gopkgs."github.com".jamespfennell.xz go.nix.nar go.nix.nar.narinfo go.nix.nixstore diff --git a/third_party/gopkgs/github.com/jamespfennell/xz/default.nix b/third_party/gopkgs/github.com/jamespfennell/xz/default.nix new file mode 100644 index 0000000000..51d9a1285a --- /dev/null +++ b/third_party/gopkgs/github.com/jamespfennell/xz/default.nix @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: 2022 Luke Granger-Brown +# +# SPDX-License-Identifier: Apache-2.0 + +{ depot, pkgs, ... }: +depot.third_party.buildGo.external { + path = "github.com/jamespfennell/xz"; + src = depot.third_party.nixpkgs.fetchFromGitHub { + owner = "jamespfennell"; + repo = "xz"; + rev = "v0.1.2"; + hash = "sha256:0wdxda81zvzvxvkxazkn48qlw62nhyc4am9vj2yvv9ncas4gp7av"; + }; + cgo = true; + cgodeps = [ pkgs.lzma ]; + cgocflags = [ "-DGOXZ_SKIP_C_COMPILATION" ]; + cgoldflags = [ "-llzma" ]; +} diff --git a/third_party/tvl/nix/buildGo/external/default.nix b/third_party/tvl/nix/buildGo/external/default.nix index c745507430..59a1109db2 100644 --- a/third_party/tvl/nix/buildGo/external/default.nix +++ b/third_party/tvl/nix/buildGo/external/default.nix @@ -50,7 +50,7 @@ let last = l: elemAt l ((length l) - 1); - toPackage = self: src: path: depMap: entry: cgodeps: + toPackage = self: src: path: depMap: entry: cgodeps: cgocflags: cgoldflags: let localDeps = map (d: lib.attrByPath (d ++ [ "gopkg" ]) @@ -79,7 +79,9 @@ let sfiles = map (f: src + ("/" + f)) entry.sfiles; cgofiles = map (f: src + ("/" + f)) entry.cgofiles; inherit cgodeps; - inherit (entry) packageName cgocflags cgoldflags; + cgocflags = entry.cgocflags ++ cgocflags; + cgoldflags = entry.cgoldflags ++ cgoldflags; + inherit (entry) packageName; cfiles = map (f: src + ("/" + f)) entry.cfiles; cxxfiles = map (f: src + ("/" + f)) entry.cxxfiles; }; @@ -91,7 +93,7 @@ let if entry.isCommand then (program binArgs) else (package libArgs); in -{ src, path, deps ? [ ], tags ? [ ], cgo ? false, cgodeps ? [ ] }: +{ src, path, deps ? [ ], tags ? [ ], cgo ? false, cgodeps ? [ ], cgocflags ? [ ], cgoldflags ? [ ] }: let # Build a map of dependencies (from their import paths to their # derivation) so that they can be conditionally imported only in @@ -110,5 +112,5 @@ let analysis = fromJSON (readFile analysisOutput); in lib.fix (self: foldl' lib.recursiveUpdate { } ( - map (entry: mkset entry.locator (toPackage self src path depMap entry cgodeps)) analysis + map (entry: mkset entry.locator (toPackage self src path depMap entry cgodeps cgocflags cgoldflags)) analysis )) diff --git a/third_party/tvl/nix/buildGo/external/main.go b/third_party/tvl/nix/buildGo/external/main.go index 7750acc016..795f0ba0c6 100644 --- a/third_party/tvl/nix/buildGo/external/main.go +++ b/third_party/tvl/nix/buildGo/external/main.go @@ -87,6 +87,13 @@ func findGoDirs(at string) ([]string, error) { return goDirs, nil } +func forceEmpty[T any](m []T) []T { + if m == nil { + return make([]T, 0) + } + return m +} + // analysePackage loads and analyses the imports of a single Go // package, returning the data that is required by the Nix code to // generate a derivation for this package. @@ -153,8 +160,8 @@ func analysePackage(root, source, importpath string, stdlib map[string]bool, tag LocalDeps: local, ForeignDeps: foreign, IsCommand: p.IsCommand(), - CgoCFLAGS: p.CgoCFLAGS, - CgoLDFLAGS: p.CgoLDFLAGS, + CgoCFLAGS: forceEmpty(p.CgoCFLAGS), + CgoLDFLAGS: forceEmpty(p.CgoLDFLAGS), }, nil }