diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..75e9c06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..6f6bfa6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1769461804, + "narHash": "sha256-msG8SU5WsBUfVVa/9RPLaymvi5bI8edTavbIq3vRlhI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bfc1b8a4574108ceef22f02bafcf6611380c100d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ede0955 --- /dev/null +++ b/flake.nix @@ -0,0 +1,95 @@ +{ + description = "Logos Blockchain Circuits (GitHub Releases)"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = + { nixpkgs, ... }: + let + lib = nixpkgs.lib; + + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + "x86_64-windows" + ]; + + forAll = lib.genAttrs systems; + + circuitsVersion = "0.3.2"; # TODO: Parametrize or make package per version available + versions = import ./versions.nix; + circuitsHashes = versions.${circuitsVersion}; + + githubBase = "https://github.com/logos-blockchain/logos-blockchain-circuits/releases/download"; + + mkCircuits = + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + os = + if pkgs.stdenv.isLinux then + "linux" + else if pkgs.stdenv.isDarwin then + "macos" + else if pkgs.stdenv.isWindows then + "windows" + else + throw "Unsupported OS"; + + arch = + if pkgs.stdenv.isx86_64 then + "x86_64" + else if pkgs.stdenv.isAarch64 then + "aarch64" + else + throw "Unsupported architecture."; + + sha256 = + if circuitsHashes ? ${system} then + circuitsHashes.${system} + else + throw "logos-blockchain-circuits ${circuitsVersion} does not support ${system}."; + in + pkgs.stdenv.mkDerivation { + pname = "logos-blockchain-circuits"; + version = circuitsVersion; + phases = [ "installPhase" ]; + + src = pkgs.fetchurl { + url = + "${githubBase}/v${circuitsVersion}" + + "/logos-blockchain-circuits-v${circuitsVersion}-${os}-${arch}.tar.gz"; + inherit sha256; + }; + + installPhase = '' + mkdir -p $out + tar -xzf $src -C $out --strip-components=1 + ''; + + meta = { + platforms = [ system ]; + }; + + passthru = { + version = circuitsVersion; + }; + }; + in + { + packages = forAll ( + system: + let + circuits = mkCircuits system; + in + { + inherit circuits; + default = circuits; + } + ); + }; +} diff --git a/scripts/gh-hash-to-nix.sh b/scripts/gh-hash-to-nix.sh new file mode 100755 index 0000000..162cab0 --- /dev/null +++ b/scripts/gh-hash-to-nix.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [ $# -ne 1 ]; then + echo "usage: $0 " + exit 1 +fi + +input="$1" + +# If already SRI, print as-is +if [[ "$input" =~ ^sha256- ]]; then + echo "$input" + exit 0 +fi + +# Strip optional sha256: prefix +hex="${input#sha256:}" + +# Convert hex → SRI +nix hash convert --hash-algo sha256 "$hex" diff --git a/versions.nix b/versions.nix new file mode 100644 index 0000000..32ce77a --- /dev/null +++ b/versions.nix @@ -0,0 +1,13 @@ +{ + "0.3.2" = { + x86_64-linux = "sha256-80+GrB3kBhwLHvNemme5Vig6tPDRRZC7xHps0DNonzM="; + aarch64-darwin = "sha256-FbLgrHaa8djFEaA69WpZMB3uozkLT/abQiCWKrkzcsk="; + x86_64-windows = "sha256-VOBUXlXNHTY0l91G+B1vybDfES0Y0HXhUytJIfFEiBA="; + }; + "0.4.1" = { + x86_64-linux = "sha256-Oi3xhqm5Sd4PaCSHWMvsJm2YPtSlm11BBG99xG30tiM="; + aarch64-linux = "sha256-8lsgqflHXPP6mnxILpUCNhetpVeDNOXiQlWKoZLHa7I="; + aarch64-darwin = "sha256-E+yMjJPMy08jbiHLlDmDvlKnGJ4UiIRKB9GGZ0JGBB8="; + x86_64-windows = "sha256-8qceJxNt+OGF5cRNwNG146Op5xcqbShQEtmVJ6iDvmQ="; + }; +}