Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Enter a `nix develop` shell if installed
if command -v nix >/dev/null 2>&1; then
use flake
fi
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ jspm_packages/
*.sln

# Compact
managed/
managed/

# nix
.direnv
.nix-bin
44 changes: 44 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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"
'';
};
}
);
};
}