Skip to content

Commit

Permalink
nix: build nim compiler
Browse files Browse the repository at this point in the history
Using nimbus build system since the codex now uses version of Nim >2.
Tested with nim versions(>2) in nixpkgs but none of them work thus the
removal of USE_SYSTEM_NIM and its logic.
Signed-off-by: markoburcul <[email protected]>
  • Loading branch information
markoburcul committed Jan 21, 2025
1 parent 5917594 commit 01a7cd6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 10 deletions.
2 changes: 1 addition & 1 deletion nix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

A development shell can be started using:
```sh
nix develop
nix develop '.?submodules=1#'
```

## Building
Expand Down
12 changes: 12 additions & 0 deletions nix/checksums.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ pkgs ? import <nixpkgs> { } }:

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=";
}
12 changes: 12 additions & 0 deletions nix/csources.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ pkgs ? import <nixpkgs> { } }:

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=";
}
27 changes: 18 additions & 9 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";

Expand All @@ -49,10 +49,7 @@ in pkgs.gcc11Stdenv.mkDerivation rec {
in
with pkgs; [
cmake
pkg-config
nimble
which
nim-unwrapped-1
lsb-release
circomCompatPkg
fakeGit
Expand All @@ -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 = ''
Expand Down
13 changes: 13 additions & 0 deletions nix/nimble.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ pkgs ? import <nixpkgs> { } }:

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=";
}

0 comments on commit 01a7cd6

Please sign in to comment.