From 866ba8aa0ec0328f0e7ba2de3c7ade34a29b0d05 Mon Sep 17 00:00:00 2001 From: solidsnakedev Date: Thu, 7 Aug 2025 14:35:18 -0600 Subject: [PATCH 1/5] feat: add Nix flake with Compact compiler toolchain - Downloads compactc, compactc.bin, and zkir per system - Supports x86_64-linux, x86_64-darwin, aarch64-darwin - Version-aware installation with automatic updates - Sets PATH and ZKIR_BIN environment variables - Includes latest Node.js from nixpkgs-unstable --- .envrc | 1 + .gitignore | 6 ++++- flake.lock | 44 ++++++++++++++++++++++++++++++++++ flake.nix | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1bbe080..7c86f00 100644 --- a/.gitignore +++ b/.gitignore @@ -58,4 +58,8 @@ jspm_packages/ *.sln # Compact -managed/ \ No newline at end of file +managed/ + +# nix +.direnv +.nix-bin \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..23fdcc9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,44 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1735563628, + "narHash": "sha256-OnSAY7XDSx7CtDoqNh8jwVwh4xNL/2HaJxGjryLWzX8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b134951a4c9f3c995fd7be05f3243f8ecd65d798", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1754393734, + "narHash": "sha256-fbnmAwTQkuXHKBlcL5Nq1sMAzd3GFqCOQgEQw6Hy0Ak=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a683adc19ff5228af548c6539dbc3440509bfed3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "nixpkgs-unstable": "nixpkgs-unstable" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f8ebc1c --- /dev/null +++ b/flake.nix @@ -0,0 +1,69 @@ +{ + description = "Example Counter – Nix flake that provides the Compact compiler per system"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; + nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + }; + + outputs = inputs: + let + supportedSystems = [ + "x86_64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + forEachSupportedSystem = f: + inputs.nixpkgs.lib.genAttrs supportedSystems ( + system: + f { + pkgs = import inputs.nixpkgs { inherit system; }; + pkgsUnstable = import inputs."nixpkgs-unstable" { inherit system; }; + inherit system; + } + ); + in + { + devShells = forEachSupportedSystem ({ pkgs, pkgsUnstable, system }: + let + # Compact compiler release to use + compactVersion = "0.24.0"; + + # Artifact URLs by host system + urlForSystem = { + "x86_64-linux" = "https://d3fazakqrumx6p.cloudfront.net/artifacts/compiler/compactc_${compactVersion}/compactc_v${compactVersion}_x86_64-unknown-linux-musl.zip"; + "x86_64-darwin" = "https://d3fazakqrumx6p.cloudfront.net/artifacts/compiler/compactc_${compactVersion}/compactc_v${compactVersion}_x86_64-apple-darwin.zip"; + "aarch64-darwin" = "https://d3fazakqrumx6p.cloudfront.net/artifacts/compiler/compactc_${compactVersion}/compactc_v${compactVersion}_aarch64-darwin.zip"; + }; + + # Local bin dir for downloaded tools + binDir = ".nix-bin"; + + installScript = pkgs.writeShellScript "setup-compactc" '' + set -euo pipefail + mkdir -p ${binDir} + + if [ ! -x ${binDir}/compactc ] || [ "$(cat ${binDir}/.compactc-version 2>/dev/null || echo)" != "${compactVersion}" ]; then + tmp="$(mktemp -d)" + trap 'rm -rf "$tmp"' EXIT + curl -fsSL "${urlForSystem.${system}}" -o "$tmp/compactc.zip" + unzip -q "$tmp/compactc.zip" -d "$tmp" + cp "$tmp"/* ${binDir}/ + chmod +x ${binDir}/* + echo "${compactVersion}" > ${binDir}/.compactc-version + fi + ''; + in + { + default = pkgs.mkShell { + packages = [ pkgs.curl pkgs.unzip pkgsUnstable.nodejs pkgs.yarn ]; + shellHook = '' + ${installScript} + export PATH="$PWD/${binDir}:$PATH" + export ZKIR_BIN="$PWD/${binDir}/zkir" + ''; + }; + } + ); + }; +} From 56d9f165b4e6ca2ed47df13230cd716cf7a89086 Mon Sep 17 00:00:00 2001 From: Squirrel Date: Fri, 15 Aug 2025 06:05:18 +0100 Subject: [PATCH 2/5] Update .envrc --- .envrc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.envrc b/.envrc index 8392d15..9229ca9 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,4 @@ -use flake \ No newline at end of file +# Enter a `nix develop` shell if installed +if command -v nix >/dev/null 2>&1; then + use flake +fi \ No newline at end of file From 7f2e453804c7ae731e4a5ab7718a6dee170b26f1 Mon Sep 17 00:00:00 2001 From: solidsnakedev Date: Fri, 15 Aug 2025 11:02:39 -0600 Subject: [PATCH 3/5] feat: migrate to official compact developer tools installation --- flake.nix | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/flake.nix b/flake.nix index f8ebc1c..aa6ae05 100644 --- a/flake.nix +++ b/flake.nix @@ -26,41 +26,32 @@ { devShells = forEachSupportedSystem ({ pkgs, pkgsUnstable, system }: let - # Compact compiler release to use + # Compact toolchain version to use compactVersion = "0.24.0"; - # Artifact URLs by host system - urlForSystem = { - "x86_64-linux" = "https://d3fazakqrumx6p.cloudfront.net/artifacts/compiler/compactc_${compactVersion}/compactc_v${compactVersion}_x86_64-unknown-linux-musl.zip"; - "x86_64-darwin" = "https://d3fazakqrumx6p.cloudfront.net/artifacts/compiler/compactc_${compactVersion}/compactc_v${compactVersion}_x86_64-apple-darwin.zip"; - "aarch64-darwin" = "https://d3fazakqrumx6p.cloudfront.net/artifacts/compiler/compactc_${compactVersion}/compactc_v${compactVersion}_aarch64-darwin.zip"; - }; - - # Local bin dir for downloaded tools - binDir = ".nix-bin"; - - installScript = pkgs.writeShellScript "setup-compactc" '' + installScript = pkgs.writeShellScript "setup-compact" '' set -euo pipefail - mkdir -p ${binDir} - if [ ! -x ${binDir}/compactc ] || [ "$(cat ${binDir}/.compactc-version 2>/dev/null || echo)" != "${compactVersion}" ]; then - tmp="$(mktemp -d)" - trap 'rm -rf "$tmp"' EXIT - curl -fsSL "${urlForSystem.${system}}" -o "$tmp/compactc.zip" - unzip -q "$tmp/compactc.zip" -d "$tmp" - cp "$tmp"/* ${binDir}/ - chmod +x ${binDir}/* - echo "${compactVersion}" > ${binDir}/.compactc-version + # Use project-local compact installation in .nix-bin + COMPACT_DIR="$PWD/.nix-bin" + export COMPACT_INSTALL_DIR="$COMPACT_DIR" + + # Install compact CLI tool if not present + if [ ! -x "$COMPACT_DIR/compact" ]; then + echo "Installing compact developer tools to $COMPACT_DIR..." + curl --proto '=https' --tlsv1.2 -LsSf https://github.com/midnightntwrk/compact/releases/latest/download/compact-installer.sh | COMPACT_NO_MODIFY_PATH=1 sh fi + + # Update to specific toolchain version + "$COMPACT_DIR/compact" update ${compactVersion} ''; in { default = pkgs.mkShell { - packages = [ pkgs.curl pkgs.unzip pkgsUnstable.nodejs pkgs.yarn ]; + packages = [ pkgs.curl pkgsUnstable.nodejs pkgs.yarn ]; shellHook = '' ${installScript} - export PATH="$PWD/${binDir}:$PATH" - export ZKIR_BIN="$PWD/${binDir}/zkir" + export PATH="$PWD/.nix-bin:$PATH" ''; }; } From d011b51923181260270e96d7b4625abba295836f Mon Sep 17 00:00:00 2001 From: solidsnakedev Date: Wed, 29 Oct 2025 18:12:04 -0600 Subject: [PATCH 4/5] fix: improve NixOS compatibility and add unzip dependency --- flake.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index aa6ae05..9881659 100644 --- a/flake.nix +++ b/flake.nix @@ -44,11 +44,16 @@ # Update to specific toolchain version "$COMPACT_DIR/compact" update ${compactVersion} + + # Patch shebang for NixOS (only needed on NixOS) + if [ ! -f "/bin/bash" ]; then + find "$COMPACT_DIR/.compact/versions/${compactVersion}" -name "compactc" -type f -exec sed -i '1s|^#!/bin/bash|#!/usr/bin/env bash|' {} \; 2>/dev/null || true + fi ''; in { default = pkgs.mkShell { - packages = [ pkgs.curl pkgsUnstable.nodejs pkgs.yarn ]; + packages = [ pkgs.curl pkgs.unzip pkgsUnstable.nodejs pkgs.yarn ]; shellHook = '' ${installScript} export PATH="$PWD/.nix-bin:$PATH" @@ -58,3 +63,4 @@ ); }; } + From 04d74692487c94257d036109a3d895fc5c7d704c Mon Sep 17 00:00:00 2001 From: solidsnakedev Date: Wed, 29 Oct 2025 18:15:16 -0600 Subject: [PATCH 5/5] refactor: update title --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 9881659..8095ae5 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Example Counter – Nix flake that provides the Compact compiler per system"; + description = "Nix flake that provides the Compact compiler per system"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";