diff --git a/.gitignore b/.gitignore index ce7c9f30..0e1f27db 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ nimcache/ +# Executables when using nix will be stored in result/ directory +result/ + # Executables shall be put in an ignored build/ directory build/ diff --git a/nix/README.md b/nix/README.md index d1886794..fa34ffe2 100644 --- a/nix/README.md +++ b/nix/README.md @@ -4,7 +4,7 @@ A development shell can be started using: ```sh -nix develop +nix develop '.?submodules=1#' ``` ## Building diff --git a/nix/checksums.nix b/nix/checksums.nix new file mode 100644 index 00000000..d79345d2 --- /dev/null +++ b/nix/checksums.nix @@ -0,0 +1,12 @@ +{ pkgs ? import { } }: + +let + tools = pkgs.callPackage ./tools.nix {}; + sourceFile = ../vendor/nimbus-build-system/vendor/Nim/koch.nim; +in pkgs.fetchFromGitHub { + owner = "nim-lang"; + repo = "checksums"; + rev = tools.findKeyValue "^ +ChecksumsStableCommit = \"([a-f0-9]+)\"$" sourceFile; + # WARNING: Requires manual updates when Nim compiler version changes. + hash = "sha256-Bm5iJoT2kAvcTexiLMFBa9oU5gf7d4rWjo3OiN7obWQ="; +} diff --git a/nix/csources.nix b/nix/csources.nix new file mode 100644 index 00000000..33cd9d0f --- /dev/null +++ b/nix/csources.nix @@ -0,0 +1,12 @@ +{ pkgs ? import { } }: + +let + tools = pkgs.callPackage ./tools.nix {}; + sourceFile = ../vendor/nimbus-build-system/vendor/Nim/config/build_config.txt; +in pkgs.fetchFromGitHub { + owner = "nim-lang"; + repo = "csources_v2"; + rev = tools.findKeyValue "^nim_csourcesHash=([a-f0-9]+)$" sourceFile; + # WARNING: Requires manual updates when Nim compiler version changes. + hash = "sha256-UCLtoxOcGYjBdvHx7A47x6FjLMi6VZqpSs65MN7fpBs="; +} diff --git a/nix/default.nix b/nix/default.nix index b4030095..691e2af3 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -3,15 +3,15 @@ src ? ../., targets ? ["all"], # Options: 0,1,2 - verbosity ? 0, - # Use system Nim compiler instead of building it with nimbus-build-system - useSystemNim ? true, + verbosity ? 1, commit ? builtins.substring 0 7 (src.rev or "dirty"), # These are the only platforms tested in CI and considered stable. stableSystems ? [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ], + # Perform 2-stage bootstrap instead of 3-stage to save time. + quickAndDirty ? true, circomCompatPkg ? ( builtins.getFlake "github:codex-storage/circom-compat-ffi" ).packages.${builtins.currentSystem}.default @@ -26,7 +26,7 @@ let revision = lib.substring 0 8 (src.rev or "dirty"); tools = callPackage ./tools.nix {}; -in pkgs.gcc11Stdenv.mkDerivation rec { +in pkgs.gcc13Stdenv.mkDerivation rec { pname = "codex"; @@ -49,10 +49,7 @@ in pkgs.gcc11Stdenv.mkDerivation rec { in with pkgs; [ cmake - pkg-config - nimble which - nim-unwrapped-1 lsb-release circomCompatPkg fakeGit @@ -66,11 +63,23 @@ in pkgs.gcc11Stdenv.mkDerivation rec { makeFlags = targets ++ [ "V=${toString verbosity}" - "USE_SYSTEM_NIM=${if useSystemNim then "1" else "0"}" + "QUICK_AND_DIRTY_COMPILER=${if quickAndDirty then "1" else "0"}" + "QUICK_AND_DIRTY_NIMBLE=${if quickAndDirty then "1" else "0"}" ]; configurePhase = '' - patchShebangs . > /dev/null + patchShebangs . vendor/nimbus-build-system > /dev/null + make nimbus-build-system-paths + ''; + + preBuild = '' + pushd vendor/nimbus-build-system/vendor/Nim + mkdir dist + cp -r ${callPackage ./nimble.nix {}} dist/nimble + cp -r ${callPackage ./checksums.nix {}} dist/checksums + cp -r ${callPackage ./csources.nix {}} csources_v2 + chmod 777 -R dist/nimble csources_v2 + popd ''; installPhase = '' diff --git a/nix/nimble.nix b/nix/nimble.nix new file mode 100644 index 00000000..39c5e0ff --- /dev/null +++ b/nix/nimble.nix @@ -0,0 +1,13 @@ +{ pkgs ? import { } }: + +let + tools = pkgs.callPackage ./tools.nix {}; + sourceFile = ../vendor/nimbus-build-system/vendor/Nim/koch.nim; +in pkgs.fetchFromGitHub { + owner = "nim-lang"; + repo = "nimble"; + fetchSubmodules = true; + rev = tools.findKeyValue "^ +NimbleStableCommit = \"([a-f0-9]+)\".+" sourceFile; + # WARNING: Requires manual updates when Nim compiler version changes. + hash = "sha256-Rz48sGUKZEAp+UySla+MlsOfsERekuGKw69Tm11fDz8="; +}