diff --git a/go/nix/nar/default.nix b/go/nix/nar/default.nix index 5ac90af272..d6625ccd68 100644 --- a/go/nix/nar/default.nix +++ b/go/nix/nar/default.nix @@ -2,13 +2,7 @@ # # SPDX-License-Identifier: Apache-2.0 -{ depot, ... }: -depot.third_party.buildGo.package { - name = "nar"; - srcs = [ - ./narinfo.go - ]; - deps = with depot; [ - third_party.gopkgs."github.com".numtide.go-nix.nixbase32 - ]; +args: +{ + narinfo = import ./narinfo args; } diff --git a/go/nix/nar/narinfo/default.nix b/go/nix/nar/narinfo/default.nix new file mode 100644 index 0000000000..9be17bf0f7 --- /dev/null +++ b/go/nix/nar/narinfo/default.nix @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2020 Luke Granger-Brown +# +# SPDX-License-Identifier: Apache-2.0 + +{ depot, ... }: +depot.third_party.buildGo.package { + name = "narinfo"; + srcs = [ + ./narinfo.go + ]; + deps = with depot; [ + third_party.gopkgs."github.com".numtide.go-nix.nixbase32 + ]; +} diff --git a/go/nix/nar/narinfo.go b/go/nix/nar/narinfo/narinfo.go similarity index 96% rename from go/nix/nar/narinfo.go rename to go/nix/nar/narinfo/narinfo.go index ebac51edbb..9a90a0f65c 100644 --- a/go/nix/nar/narinfo.go +++ b/go/nix/nar/narinfo/narinfo.go @@ -2,8 +2,8 @@ // // SPDX-License-Identifier: Apache-2.0 -// Package nar implements a simple NAR read/writer. -package nar +// Package narinfo implements a simple narinfo read/writer. +package narinfo import ( "bufio" @@ -207,6 +207,7 @@ type NarInfo struct { Deriver string System string Sig map[string][]byte + CA string } func (ni NarInfo) WriteTo(w io.Writer) error { @@ -273,6 +274,11 @@ func (ni NarInfo) WriteTo(w io.Writer) error { } } } + if ni.CA != "" { + if _, err := fmt.Fprintf(w, "CA: %s\n", ni.CA); err != nil { + return err + } + } return nil } @@ -335,6 +341,9 @@ func ParseNarInfo(r io.Reader) (*NarInfo, error) { } case "References": ni.References = strings.Split(value, " ") + if len(ni.References) == 1 && ni.References[0] == "" { + ni.References = nil + } case "Deriver": if value != "unknown-deriver" { ni.Deriver = value @@ -355,7 +364,7 @@ func ParseNarInfo(r io.Reader) (*NarInfo, error) { } ni.Sig[bits[0]] = rawVal case "CA": - return nil, fmt.Errorf("content-addressed NARs not supported yet") + ni.CA = value } } if err := s.Err(); err != nil { diff --git a/go/nix/nar/narinfo_test.go b/go/nix/nar/narinfo/narinfo_test.go similarity index 99% rename from go/nix/nar/narinfo_test.go rename to go/nix/nar/narinfo/narinfo_test.go index f54d8b40df..0a55f7fd4a 100644 --- a/go/nix/nar/narinfo_test.go +++ b/go/nix/nar/narinfo/narinfo_test.go @@ -1,4 +1,4 @@ -package nar +package narinfo import ( "strings"