-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nix: make derivation and update shell #1003
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,33 +3,36 @@ | |||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
inputs = { | ||||||||||||||||||||||||||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; | ||||||||||||||||||||||||||||||
circom-compat.url = "github:codex-storage/circom-compat-ffi"; | ||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
outputs = { self, nixpkgs }: | ||||||||||||||||||||||||||||||
outputs = { self, nixpkgs, circom-compat}: | ||||||||||||||||||||||||||||||
let | ||||||||||||||||||||||||||||||
supportedSystems = [ | ||||||||||||||||||||||||||||||
stableSystems = [ | ||||||||||||||||||||||||||||||
"x86_64-linux" "aarch64-linux" | ||||||||||||||||||||||||||||||
"x86_64-darwin" "aarch64-darwin" | ||||||||||||||||||||||||||||||
]; | ||||||||||||||||||||||||||||||
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); | ||||||||||||||||||||||||||||||
pkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); | ||||||||||||||||||||||||||||||
forEach = nixpkgs.lib.genAttrs; | ||||||||||||||||||||||||||||||
forAllSystems = forEach stableSystems; | ||||||||||||||||||||||||||||||
pkgsFor = forEach stableSystems ( | ||||||||||||||||||||||||||||||
system: import nixpkgs { inherit system; } | ||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||
Comment on lines
+15
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why this change happened. |
||||||||||||||||||||||||||||||
in rec { | ||||||||||||||||||||||||||||||
devShells = forAllSystems (system: let | ||||||||||||||||||||||||||||||
pkgs = pkgsFor.${system}; | ||||||||||||||||||||||||||||||
inherit (pkgs) lib stdenv mkShell; | ||||||||||||||||||||||||||||||
in { | ||||||||||||||||||||||||||||||
default = mkShell.override { stdenv = pkgs.gcc11Stdenv; } { | ||||||||||||||||||||||||||||||
buildInputs = with pkgs; [ | ||||||||||||||||||||||||||||||
# General | ||||||||||||||||||||||||||||||
git pkg-config openssl lsb-release | ||||||||||||||||||||||||||||||
# Build | ||||||||||||||||||||||||||||||
rustc cargo nimble gcc11 cmake nim-unwrapped-1 | ||||||||||||||||||||||||||||||
# Libraries | ||||||||||||||||||||||||||||||
gmp llvmPackages.openmp | ||||||||||||||||||||||||||||||
# Tests | ||||||||||||||||||||||||||||||
nodejs_18 | ||||||||||||||||||||||||||||||
]; | ||||||||||||||||||||||||||||||
packages = forAllSystems (system: let | ||||||||||||||||||||||||||||||
circomCompatPkg = circom-compat.packages.${system}.default; | ||||||||||||||||||||||||||||||
buildTarget = pkgsFor.${system}.callPackage ./nix/default.nix { | ||||||||||||||||||||||||||||||
inherit stableSystems; | ||||||||||||||||||||||||||||||
inherit circomCompatPkg; | ||||||||||||||||||||||||||||||
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
src = self; | ||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
build = targets: buildTarget.override { inherit targets; }; | ||||||||||||||||||||||||||||||
in rec { | ||||||||||||||||||||||||||||||
codex = build ["all"]; | ||||||||||||||||||||||||||||||
default = codex; | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
devShells = forAllSystems (system: { | ||||||||||||||||||||||||||||||
default = pkgsFor.${system}.callPackage ./nix/shell.nix { }; | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
Comment on lines
+34
to
36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could just use the package itself to get necessary tools, and add others using
Suggested change
Are we even using this |
||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Usage | ||
|
||
## Shell | ||
|
||
A development shell can be started using: | ||
```sh | ||
nix develop | ||
``` | ||
|
||
## Building | ||
|
||
To build a Codex you can use: | ||
```sh | ||
nix build '.?submodules=1#codex' | ||
``` | ||
The `?submodules=1` part should eventually not be necessary. | ||
For more details see: | ||
https://github.com/NixOS/nix/issues/4423 | ||
|
||
It can be also done without even cloning the repo: | ||
```sh | ||
nix build 'github:codex-storage/nim-codex?submodules=1' | ||
``` | ||
|
||
## Running | ||
|
||
```sh | ||
nix run 'github:codex-storage/nim-codex?submodules=1' | ||
``` |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,86 @@ | ||||||||||
{ | ||||||||||
pkgs ? import <nixpkgs> { }, | ||||||||||
src ? ../., | ||||||||||
targets ? ["all"], | ||||||||||
# Options: 0,1,2 | ||||||||||
verbosity ? 0, | ||||||||||
# Use system Nim compiler instead of building it with nimbus-build-system | ||||||||||
useSystemNim ? true, | ||||||||||
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" | ||||||||||
], | ||||||||||
circomCompatPkg | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could add a default fallback here too:
Suggested change
|
||||||||||
}: | ||||||||||
|
||||||||||
let | ||||||||||
inherit (pkgs) stdenv lib writeScriptBin callPackage; | ||||||||||
|
||||||||||
revision = lib.substring 0 8 (src.rev or "dirty"); | ||||||||||
in pkgs.stdenv.mkDerivation rec { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we be enforcing GCC11?
Suggested change
|
||||||||||
|
||||||||||
pname = "codex"; | ||||||||||
|
||||||||||
version = "${callPackage ./version.nix {}}-${revision}"; | ||||||||||
|
||||||||||
inherit src; | ||||||||||
|
||||||||||
# Dependencies that should only exist in the build environment. | ||||||||||
nativeBuildInputs = let | ||||||||||
# Fix for Nim compiler calling 'git rev-parse' and 'lsb_release'. | ||||||||||
fakeGit = writeScriptBin "git" "echo ${version}"; | ||||||||||
fakeLsbRelease = writeScriptBin "lsb_release" "echo nix"; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you using this instead of |
||||||||||
# Fix for the nim-circom-compat-ffi package that is built with cargo. | ||||||||||
fakeCargo = writeScriptBin "cargo" "echo ${version}"; | ||||||||||
in | ||||||||||
with pkgs; [ | ||||||||||
gcc11 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be done using |
||||||||||
cmake | ||||||||||
curl | ||||||||||
bash | ||||||||||
Comment on lines
+41
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bash is a part of |
||||||||||
pkg-config | ||||||||||
openssl | ||||||||||
gmp | ||||||||||
Comment on lines
+44
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't we already adding this in |
||||||||||
nimble | ||||||||||
which | ||||||||||
nim-unwrapped-1 | ||||||||||
circomCompatPkg | ||||||||||
fakeGit | ||||||||||
fakeCargo | ||||||||||
fakeLsbRelease | ||||||||||
]; | ||||||||||
|
||||||||||
# Disable CPU optmizations that make binary not portable. | ||||||||||
NIMFLAGS = "-d:disableMarchNative -d:git_revision_override=${revision}"; | ||||||||||
# Avoid Nim cache permission errors. | ||||||||||
XDG_CACHE_HOME = "/tmp"; | ||||||||||
|
||||||||||
makeFlags = targets ++ [ | ||||||||||
"V=${toString verbosity}" | ||||||||||
"USE_SYSTEM_NIM=${if useSystemNim then "1" else "0"}" | ||||||||||
]; | ||||||||||
|
||||||||||
# Dependencies that should exist in the runtime environment. | ||||||||||
buildInputs = with pkgs; [ | ||||||||||
openssl | ||||||||||
gmp | ||||||||||
]; | ||||||||||
|
||||||||||
configurePhase = '' | ||||||||||
patchShebangs . > /dev/null | ||||||||||
''; | ||||||||||
|
||||||||||
installPhase = '' | ||||||||||
mkdir -p $out/bin | ||||||||||
cp build/codex $out/bin/ | ||||||||||
''; | ||||||||||
|
||||||||||
meta = with pkgs.lib; { | ||||||||||
description = "Codex storage system"; | ||||||||||
homepage = "https://github.com/codex-storage/nim-codex"; | ||||||||||
license = licenses.mit; | ||||||||||
platforms = stableSystems; | ||||||||||
}; | ||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ pkgs ? import <nixpkgs> {}}: | ||
|
||
pkgs.mkShell.override { stdenv = pkgs.gcc11Stdenv; } { | ||
|
||
buildInputs = with pkgs; [ | ||
# General | ||
git pkg-config openssl lsb-release | ||
# Build | ||
rustc cargo nimble gcc11 cmake nim-unwrapped-1 | ||
# Libraries | ||
gmp llvmPackages.openmp | ||
# Tests | ||
nodejs_18 | ||
]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ pkgs ? import <nixpkgs> { } }: | ||
|
||
let | ||
|
||
inherit (pkgs.lib) fileContents last splitString flatten remove; | ||
inherit (builtins) map match; | ||
in { | ||
findKeyValue = regex: sourceFile: | ||
let | ||
linesFrom = file: splitString "\n" (fileContents file); | ||
matching = regex: lines: map (line: match regex line) lines; | ||
extractMatch = matches: last (flatten (remove null matches)); | ||
in | ||
extractMatch (matching regex (linesFrom sourceFile)); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,9 @@ | ||||||||||||||||||||||||
{ pkgs ? import <nixpkgs> { } }: | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let | ||||||||||||||||||||||||
tools = pkgs.callPackage ./tools.nix {}; | ||||||||||||||||||||||||
source = ../codex.nimble; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
version = tools.findKeyValue "version = \"([0-9]+\.[0-9]+\.[0-9]+)\"" source; | ||||||||||||||||||||||||
in | ||||||||||||||||||||||||
"${version}" | ||||||||||||||||||||||||
Comment on lines
+3
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
Honestly, this is so short you could just put this directly in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't reference it by relative path? Might be possible: