From 6db1fe885f354e3ca951dccd5dd68588758a7da4 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Mon, 30 Nov 2020 22:53:27 +0100 Subject: [PATCH] fix(fetch.py): when fetch is run, first update unstable channel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This way we won’t forget to do it for months at a time. You’d hope that stuff like this would be possible without jumping through hoops, but this is nix after all. Flakes our salvation or something. --- fetch.py | 29 +++++++++++++++++++++++++++++ nixpkgs.json | 6 ++++++ nixpkgs.nix | 12 ++++++------ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 nixpkgs.json diff --git a/fetch.py b/fetch.py index c977251..3fdef9c 100755 --- a/fetch.py +++ b/fetch.py @@ -11,6 +11,29 @@ def curl_latest_release(): url = "https://api.github.com/repos/dhall-lang/dhall-haskell/releases/latest" return json.loads(sub.check_output(["curl", url])) +# fetch the latest nixos unstable version +def curl_latest_nixos_unstable(): + url = "https://nixos.org/channels/nixos-unstable/git-revision" + return sub.check_output(["curl", "--location", url]).strip().decode() + +def update_nixpkgs(lockfile_path, new_hash): + # --unpack produces the hash required by `builtins.fetchTarball` + github_archive = "https://github.com/NixOS/nixpkgs/archive/{}.tar.gz".format(new_hash) + hash = sub.check_output([ + "nix-prefetch-url", '--unpack', github_archive + ]).strip().decode() + date = sub.check_output([ + "date", "--iso-8601=minutes" + ]).strip().decode() + with open(lockfile_path, 'w') as f: + json.dump({ + "comment": "autogenerated by fetch.py", + "url": github_archive, + "sha256": hash, + "date": date + }, f, indent=2) + + # call nix-prefetch-url on each asset to get their hashes def prefetch_binaries(release): res = [] @@ -39,11 +62,17 @@ def postprocess(fetched): if __name__ == "__main__": + print("updating nixpkgs to latest unstable", file=sys.stderr) + nixos_hash = curl_latest_nixos_unstable() + update_nixpkgs("./nixpkgs.json", nixos_hash) + release = curl_latest_release() version = release['tag_name'] + print("updating to release {}".format(version), file=sys.stderr) fetched = prefetch_binaries(release) res = postprocess(fetched) + print("writing ./release.json", file=sys.stderr) with open("./release.json", mode='w') as f: json.dump(res, f, indent=2) diff --git a/nixpkgs.json b/nixpkgs.json new file mode 100644 index 0000000..f1f1fa5 --- /dev/null +++ b/nixpkgs.json @@ -0,0 +1,6 @@ +{ + "comment": "autogenerated by fetch.py", + "url": "https://github.com/NixOS/nixpkgs/archive/24eb3f87fc610f18de7076aee7c5a84ac5591e3e.tar.gz", + "sha256": "1ca14hhbinnz1ylbqnhwinjdbm6nn859j4gmyamg2kr7jl6611s0", + "date": "2020-11-30T23:28+01:00" +} \ No newline at end of file diff --git a/nixpkgs.nix b/nixpkgs.nix index 219a3cf..8a9556a 100644 --- a/nixpkgs.nix +++ b/nixpkgs.nix @@ -1,6 +1,6 @@ -import ( - builtins.fetchTarball { - url = "https://github.com/nixos/nixpkgs/archive/a7bf8161fa834a602278c15fcbdd955656b3aed8.tar.gz"; - sha256 = "0lzd35niw0j8qy4mhglvqwv5qwyvdb9mhv8hpmn73ym57r92i4p1"; - } -) +import (fetchTarball { + inherit (builtins.fromJSON (builtins.readFile ./nixpkgs.json)) + url + sha256 + ; +})