Skip to content

Patch binaries and add CI #3

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

Merged
merged 17 commits into from
Mar 26, 2022
Merged
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
15 changes: 15 additions & 0 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Build flake example"
on:
pull_request:
push:
jobs:
nix:
name: Build flake example on ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/[email protected]
- uses: cachix/install-nix-action@v15
- run: cd examples/flake && nix build --show-trace
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# DFINITY
.dfx/


# Nix
result
result-*
44 changes: 35 additions & 9 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,49 @@ let
"dfx-${version}.tar.gz"
];
};
nativeBuildInputs = [
self.makeWrapper
] ++ self.lib.optional self.stdenv.isLinux [
self.glibc.bin
self.patchelf
self.which
];
# Use `find $(dfx cache show) -type f -executable -print` on macOS to
# help discover what to symlink.
installPhase = ''
export HOME=$TMP

${self.lib.optionalString self.stdenv.isLinux ''
local LD_LINUX_SO=$(ldd $(which iconv)|grep ld-linux-x86|cut -d' ' -f3)
local IS_STATIC=$(ldd ./dfx | grep 'not a dynamic executable')
local USE_LIB64=$(ldd ./dfx | grep '/lib64/ld-linux-x86-64.so.2')
chmod +rw ./dfx
test -n "$IS_STATIC" || test -z "$USE_LIB64" || patchelf --set-interpreter "$LD_LINUX_SO" ./dfx
''}

./dfx cache install

mkdir -p $out/cache
cp --preserve=mode,timestamps -R $(./dfx cache show)/. $out/cache
local CACHE_DIR="$out/.cache/dfinity/versions/${version}"
mkdir -p "$CACHE_DIR"
cp --preserve=mode,timestamps -R $(./dfx cache show)/. $CACHE_DIR

mkdir -p $out/bin
ln -s $out/cache/dfx $out/bin/dfx
ln -s $out/cache/ic-ref $out/bin/ic-ref
ln -s $out/cache/ic-starter $out/bin/ic-starter
ln -s $out/cache/mo-doc $out/bin/mo-doc
ln -s $out/cache/mo-ide $out/bin/mo-ide
ln -s $out/cache/moc $out/bin/moc
ln -s $out/cache/replica $out/bin/replica

for binary in dfx ic-ref ic-starter icx-proxy mo-doc mo-ide moc replica; do
${self.lib.optionalString self.stdenv.isLinux ''
local BINARY="$CACHE_DIR/$binary"
test -f "$BINARY" || continue
local IS_STATIC=$(ldd "$BINARY" | grep 'not a dynamic executable')
local USE_LIB64=$(ldd "$BINARY" | grep '/lib64/ld-linux-x86-64.so.2')
chmod +rw "$BINARY"
test -n "$IS_STATIC" || test -z "$USE_LIB64" || patchelf --set-interpreter "$LD_LINUX_SO" "$BINARY"
''}
ln -s $CACHE_DIR/$binary $out/bin/$binary
done

wrapProgram $CACHE_DIR/dfx --set DFX_CONFIG_ROOT $out
rm $out/bin/dfx
ln -s $CACHE_DIR/dfx $out/bin/dfx
'';
system = resolvedSystem;
inherit version;
Expand Down
10 changes: 10 additions & 0 deletions examples/flake/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": 1,
"dfx": "0.8.4",
"networks": {
"local": {
"bind": "127.0.0.1:8000",
"type": "ephemeral"
}
}
}
14 changes: 5 additions & 9 deletions examples/flake/flake.lock

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

15 changes: 14 additions & 1 deletion examples/flake/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
nixpkgs.url = "github:nixos/nixpkgs/21.11";
flake-utils.url = "github:numtide/flake-utils";
dfinity-sdk = {
url = "github:paulyoung/nixpkgs-dfinity-sdk";
# url = "github:paulyoung/nixpkgs-dfinity-sdk";
url = "../../";
flake = false;
};
};
Expand All @@ -24,6 +25,18 @@
})."0.8.4";
in
{
# `nix build`
defaultPackage = pkgs.runCommand "example" {
buildInputs = [
dfinitySdk
];
} ''
cp ${./dfx.json} dfx.json
dfx start --background
dfx stop
touch $out
'';

# `nix develop`
devShell = pkgs.mkShell {
buildInputs = [
Expand Down