diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..9229ca9 --- /dev/null +++ b/.envrc @@ -0,0 +1,4 @@ +# 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 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..8095ae5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,66 @@ +{ + description = "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 toolchain version to use + compactVersion = "0.24.0"; + + installScript = pkgs.writeShellScript "setup-compact" '' + set -euo pipefail + + # 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} + + # 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 pkgs.unzip pkgsUnstable.nodejs pkgs.yarn ]; + shellHook = '' + ${installScript} + export PATH="$PWD/.nix-bin:$PATH" + ''; + }; + } + ); + }; +} +