Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nixhash #120

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/derivation/drv_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"encoding/hex"
"sort"

"github.com/nix-community/go-nix/pkg/hash"
"github.com/nix-community/go-nix/pkg/nixbase32"
"github.com/nix-community/go-nix/pkg/nixhash"
"github.com/nix-community/go-nix/pkg/nixpath"
)

Expand Down Expand Up @@ -80,5 +80,5 @@ func (d *Derivation) DrvPath() (string, error) {

atermDigest = h.Sum(nil)

return nixpath.Absolute(nixbase32.EncodeToString(hash.CompressHash(atermDigest, 20)) + "-" + name + ".drv"), nil
return nixpath.Absolute(nixbase32.EncodeToString(nixhash.CompressHash(atermDigest, 20)) + "-" + name + ".drv"), nil
}
4 changes: 2 additions & 2 deletions pkg/derivation/hashes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"
chash "hash"

"github.com/nix-community/go-nix/pkg/hash"
"github.com/nix-community/go-nix/pkg/nixbase32"
"github.com/nix-community/go-nix/pkg/nixhash"
"github.com/nix-community/go-nix/pkg/nixpath"
)

Expand Down Expand Up @@ -117,7 +117,7 @@ func (d *Derivation) CalculateOutputPaths(inputDrvReplacements map[string]string
)
}

calculatedPath := nixpath.Absolute(nixbase32.EncodeToString(hash.CompressHash(storeHash, 20)) +
calculatedPath := nixpath.Absolute(nixbase32.EncodeToString(nixhash.CompressHash(storeHash, 20)) +
"-" + outputPathName)

outputPaths[outputName] = calculatedPath
Expand Down
102 changes: 0 additions & 102 deletions pkg/hash/hash.go

This file was deleted.

120 changes: 0 additions & 120 deletions pkg/hash/hash_test.go

This file was deleted.

78 changes: 63 additions & 15 deletions pkg/nar/narinfo/narinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strings"
"testing"

"github.com/nix-community/go-nix/pkg/hash"
"github.com/nix-community/go-nix/pkg/nar/narinfo"
"github.com/nix-community/go-nix/pkg/nixhash"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -38,13 +38,24 @@ Deriver: 10dx1q4ivjb115y3h90mipaaz533nr0d-net-tools-1.60_p20170221182432.drv
Sig: cache.nixos.org-1:sn5s/RrqEI+YG6/PjwdbPjcAC7rcta7sJU4mFOawGvJBLsWkyLtBrT2EuFt/LJjWkTZ+ZWOI9NTtjo/woMdvAg==
Sig: hydra.other.net-1:JXQ3Z/PXf0EZSFkFioa4FbyYpbbTbHlFBtZf4VqU0tuMTWzhMD7p9Q7acJjLn3jofOtilAAwRILKIfVuyrbjAA==
`
_NarHash = &hash.Hash{
HashType: "sha256",
Digest: []uint8{
0xc6, 0xe1, 0x55, 0xb3, 0x45, 0x6e, 0x30, 0xb7, 0x61, 0x22, 0x63, 0xec, 0x09, 0x50, 0x70, 0x81,
0x1c, 0xaf, 0x8a, 0xbf, 0xd5, 0x9f, 0xaa, 0x72, 0xab, 0x82, 0xa5, 0x92, 0xef, 0xde, 0xb2, 0x53,
},
}

strNarinfoSampleCachix = `
StorePath: /nix/store/8nb4qdm1n2mpfcfr3hdaxw54fjdn4hqz-treefmt-docs-4b33ba3
URL: nar/b136fa7b36b966d63a93f983ee03070e44bffe9ba9005cda59835e2a0f0f64b9.nar.zst
Compression: zstd
FileHash: sha256:b136fa7b36b966d63a93f983ee03070e44bffe9ba9005cda59835e2a0f0f64b9
FileSize: 873969
NarHash: sha256:1d3pp407iawzv79w453x5ff5fs0cscwzxm7572q85nijc56faxr8
NarSize: 1794360
References:
Deriver: 7nzyn0l9402ya02g6sac073c3733k0p7-treefmt-docs-4b33ba3.drv
Sig: numtide.cachix.org-1:YYcsiDnC0WR2utXGy1G6PqjDPH7TsvMrpaK4QJV1MHLks4N5XPA+Na0yzfOqBxqn9BB8NsTAqSu2B08SiIQmDA==
`

_NarHash = nixhash.MustNewHashWithEncoding(nixhash.SHA256, []uint8{
0xc6, 0xe1, 0x55, 0xb3, 0x45, 0x6e, 0x30, 0xb7, 0x61, 0x22, 0x63, 0xec, 0x09, 0x50, 0x70, 0x81,
0x1c, 0xaf, 0x8a, 0xbf, 0xd5, 0x9f, 0xaa, 0x72, 0xab, 0x82, 0xa5, 0x92, 0xef, 0xde, 0xb2, 0x53,
}, nixhash.NixBase32, true)

_Signatures = []*narinfo.Signature{
{
Expand All @@ -71,13 +82,10 @@ Sig: hydra.other.net-1:JXQ3Z/PXf0EZSFkFioa4FbyYpbbTbHlFBtZf4VqU0tuMTWzhMD7p9Q7ac
StorePath: "/nix/store/00bgd045z0d4icpbc2yyz4gx48ak44la-net-tools-1.60_p20170221182432",
URL: "nar/1094wph9z4nwlgvsd53abfz8i117ykiv5dwnq9nnhz846s7xqd7d.nar.xz",
Compression: "xz",
FileHash: &hash.Hash{
HashType: "sha256",
Digest: []byte{
0xed, 0x34, 0xdc, 0x8f, 0x36, 0x04, 0x7d, 0x68, 0x6d, 0xc2, 0x96, 0xb7, 0xb2, 0xe3, 0xf4, 0x27,
0x84, 0x88, 0xbe, 0x5b, 0x6a, 0x94, 0xa6, 0xf7, 0xa3, 0xdc, 0x92, 0x9f, 0xe0, 0xe5, 0x24, 0x81,
},
},
FileHash: nixhash.MustNewHashWithEncoding(nixhash.SHA256, []byte{
0xed, 0x34, 0xdc, 0x8f, 0x36, 0x04, 0x7d, 0x68, 0x6d, 0xc2, 0x96, 0xb7, 0xb2, 0xe3, 0xf4, 0x27,
0x84, 0x88, 0xbe, 0x5b, 0x6a, 0x94, 0xa6, 0xf7, 0xa3, 0xdc, 0x92, 0x9f, 0xe0, 0xe5, 0x24, 0x81,
}, nixhash.NixBase32, true),
FileSize: 114980,
NarHash: _NarHash,
NarSize: 464152,
Expand All @@ -96,6 +104,34 @@ Sig: hydra.other.net-1:JXQ3Z/PXf0EZSFkFioa4FbyYpbbTbHlFBtZf4VqU0tuMTWzhMD7p9Q7ac
Deriver: "10dx1q4ivjb115y3h90mipaaz533nr0d-net-tools-1.60_p20170221182432.drv",
Signatures: _Signatures,
}

narinfoSampleCachix = &narinfo.NarInfo{
StorePath: "/nix/store/8nb4qdm1n2mpfcfr3hdaxw54fjdn4hqz-treefmt-docs-4b33ba3",
URL: "nar/b136fa7b36b966d63a93f983ee03070e44bffe9ba9005cda59835e2a0f0f64b9.nar.zst",
Compression: "zstd",
NarHash: nixhash.MustNewHashWithEncoding(nixhash.SHA256, []byte{
0x28, 0x77, 0xe5, 0x4c, 0x61, 0x32, 0xda, 0x82, 0xb0, 0x38, 0xe5, 0xd4, 0xfe, 0x39, 0xd3, 0x0c,
0x68, 0x57, 0x9c, 0x2b, 0x7d, 0x14, 0xc2, 0xd3, 0xd9, 0x9f, 0xab, 0x78, 0x00, 0xb9, 0x77, 0xb4,
}, nixhash.NixBase32, true),
NarSize: 1794360,
FileHash: nixhash.MustNewHashWithEncoding(nixhash.SHA256, []byte{
0xb1, 0x36, 0xfa, 0x7b, 0x36, 0xb9, 0x66, 0xd6, 0x3a, 0x93, 0xf9, 0x83, 0xee, 0x03, 0x07, 0x0e,
0x44, 0xbf, 0xfe, 0x9b, 0xa9, 0x00, 0x5c, 0xda, 0x59, 0x83, 0x5e, 0x2a, 0x0f, 0x0f, 0x64, 0xb9,
}, nixhash.Base16, true),
FileSize: 873969,
Deriver: "7nzyn0l9402ya02g6sac073c3733k0p7-treefmt-docs-4b33ba3.drv",
Signatures: []*narinfo.Signature{
{
KeyName: "numtide.cachix.org-1",
Digest: []byte{
0x61, 0x87, 0x2c, 0x88, 0x39, 0xc2, 0xd1, 0x64, 0x76, 0xba, 0xd5, 0xc6, 0xcb, 0x51, 0xba, 0x3e,
0xa8, 0xc3, 0x3c, 0x7e, 0xd3, 0xb2, 0xf3, 0x2b, 0xa5, 0xa2, 0xb8, 0x40, 0x95, 0x75, 0x30, 0x72,
0xe4, 0xb3, 0x83, 0x79, 0x5c, 0xf0, 0x3e, 0x35, 0xad, 0x32, 0xcd, 0xf3, 0xaa, 0x07, 0x1a, 0xa7,
0xf4, 0x10, 0x7c, 0x36, 0xc4, 0xc0, 0xa9, 0x2b, 0xb6, 0x07, 0x4f, 0x12, 0x88, 0x84, 0x26, 0x0c,
},
},
},
}
)

func TestNarInfo(t *testing.T) {
Expand All @@ -122,6 +158,18 @@ func TestNarInfoWithoutFileFields(t *testing.T) {
assert.Equal(t, strNarinfoSampleWithoutFileFields, "\n"+ni.String())
}

func TestNarInfoCachix(t *testing.T) {
ni, err := narinfo.Parse(strings.NewReader(strNarinfoSampleCachix))
assert.NoError(t, err)

// Test the parsing happy path
assert.Equal(t, narinfoSampleCachix, ni)
assert.NoError(t, ni.Check())

// Test to string
assert.Equal(t, strNarinfoSampleCachix, "\n"+ni.String())
}

func TestBigNarinfo(t *testing.T) {
f, err := os.Open("../../../test/testdata/big.narinfo")
if err != nil {
Expand Down
Loading