diff options
| author | Fuwn <[email protected]> | 2024-12-02 20:23:53 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-12-02 20:23:53 -0800 |
| commit | af8d47f92af62917ea2f8fe800782374225d36bc (patch) | |
| tree | eeb481a9fb2ad8756812b827f0f10294afa65226 | |
| parent | 6fd049f7a0636a406d9a7405825046c1928fa8ab (diff) | |
| download | yae-af8d47f92af62917ea2f8fe800782374225d36bc.tar.xz yae-af8d47f92af62917ea2f8fe800782374225d36bc.zip | |
feat(yae): track sri hash field for sources
| -rw-r--r-- | flake.nix | 2 | ||||
| -rw-r--r-- | internal/yae/source.go | 10 | ||||
| -rw-r--r-- | internal/yae/utilities.go | 10 | ||||
| -rw-r--r-- | yae.schema.json | 3 |
4 files changed, 22 insertions, 3 deletions
@@ -54,7 +54,7 @@ inherit meta; pname = name; - version = "2024.11.25"; + version = "2024.12.02"; src = pkgs.lib.cleanSource ./.; vendorHash = "sha256-XQEB2vgiztbtLnc7BR4WTouPI+2NDQXXFUNidqmvbac="; buildInputs = [ pkgs.musl ]; diff --git a/internal/yae/source.go b/internal/yae/source.go index 735e4d4..20d16dc 100644 --- a/internal/yae/source.go +++ b/internal/yae/source.go @@ -11,6 +11,7 @@ import ( type Source struct { URL string `json:"url"` SHA256 string `json:"sha256"` + Hash string `json:"hash"` Unpack bool `json:"unpack"` Type string `json:"type"` Version string `json:"version,omitempty"` @@ -78,10 +79,17 @@ func (source *Source) Update(sources *Environment, name string, force bool, forc return updated, err } - if sha256 != source.SHA256 { + sriHash, err := FetchSRIHash(sha256) + + if err != nil { + return updated, err + } + + if sha256 != source.SHA256 || sriHash != source.Hash || force || source.Force { log.Infof("rehashed %s: %s -> %s", name, source.SHA256, sha256) source.SHA256 = sha256 + source.Hash = sriHash updated = true } diff --git a/internal/yae/utilities.go b/internal/yae/utilities.go index ef9d334..73042fd 100644 --- a/internal/yae/utilities.go +++ b/internal/yae/utilities.go @@ -25,6 +25,16 @@ func FetchSHA256(url string, unpack bool) (string, error) { return strings.Trim(lines[len(lines)-2], "\n"), nil } +func FetchSRIHash(sha256 string) (string, error) { + output, err := command("nix", false, "hash", "convert", "--hash-algo", "sha256", "--from", "nix32", sha256) + + if err != nil { + return "", err + } + + return strings.Trim(output, "\n"), nil +} + func command(name string, show bool, args ...string) (string, error) { executable, err := exec.LookPath(name) out := []byte{} diff --git a/yae.schema.json b/yae.schema.json index 04a0e75..d0c1e22 100644 --- a/yae.schema.json +++ b/yae.schema.json @@ -4,11 +4,12 @@ "properties": { "$schema": { "type": "string" } }, "additionalProperties": { "type": "object", - "required": ["url", "sha256", "unpack", "type"], + "required": ["url", "sha256", "hash", "unpack", "type"], "additionalProperties": false, "properties": { "url": { "type": "string" }, "sha256": { "type": "string" }, + "hash": { "type": "string" }, "unpack": { "type": "boolean" }, "type": { "type": "string" }, "version": { "type": "string" }, |