From 2fd9cda82af26b6ae548548d3ec5e03a72fcd0af Mon Sep 17 00:00:00 2001 From: "guillem.cordoba" Date: Thu, 7 Mar 2024 20:23:26 +0100 Subject: [PATCH] WIP --- .github/workflows/test-nix.yml | 67 +++++++++++++++++++++++++++++++--- flake.nix | 13 ++++++- nix/deterministic-zome.nix | 51 ++++++++++++++------------ nix/fixture/Cargo.toml | 1 + nix/fixture/flake.lock | 14 +++---- nix/zome.nix | 13 +++++-- 6 files changed, 119 insertions(+), 40 deletions(-) diff --git a/.github/workflows/test-nix.yml b/.github/workflows/test-nix.yml index 9b0f240..2c4a7b6 100644 --- a/.github/workflows/test-nix.yml +++ b/.github/workflows/test-nix.yml @@ -8,11 +8,8 @@ on: branches: [ main, develop ] jobs: - testbuild: - strategy: - matrix: - os: [ ubuntu-latest, macos-latest ] - runs-on: ${{ matrix.os }} + build-and-cache: + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -32,6 +29,8 @@ jobs: run: brew install coreutils - name: Build zomes + env: + CACHIX_AUTH_TOKEN: "${{ secrets.CACHIX_TOKEN_HOLOCHAIN_OPEN_DEV }}" run: | cd ./nix/fixture nix flake update @@ -40,3 +39,61 @@ jobs: nix build -L .#my_zome sha256sum result + +jobs: + linux-build-and-cache: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install nix + uses: cachix/install-nix-action@v18 + with: + install_url: https://releases.nixos.org/nix/nix-2.12.0/install + extra_nix_config: | + experimental-features = flakes nix-command + + - uses: cachix/cachix-action@v10 + with: + name: holochain-ci + + - name: Build zomes + env: + CACHIX_AUTH_TOKEN: "${{ secrets.CACHIX_TOKEN_HOLOCHAIN_OPEN_DEV }}" + run: | + cd ./nix/fixture + yes | nix flake update + nix build -L .#my_zome.meta.debug + nix build -L .#my_zome + cachix watch-store holochain-open-dev + sha256sum result + + macos-just-get-from-cache: + needs: build-and-cache + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + + - name: Install nix + uses: cachix/install-nix-action@v18 + with: + install_url: https://releases.nixos.org/nix/nix-2.12.0/install + extra_nix_config: | + experimental-features = flakes nix-command + + - uses: cachix/cachix-action@v10 + with: + name: holochain-ci + + - name: Install coreutils for macOS + if: matrix.os == 'macos-latest' + run: brew install coreutils + + - name: Build zomes + run: | + cd ./nix/fixture + yes | nix flake update + nix build -L .#my_zome.meta.debug + nix build -L .#my_zome + sha256sum result + diff --git a/flake.nix b/flake.nix index c990121..24c5e9e 100644 --- a/flake.nix +++ b/flake.nix @@ -19,6 +19,15 @@ hcUtils.url = "github:holochain-open-dev/common"; }; + nixConfig = { + extra-substituters = [ + "https://holochain-open-dev.cachix.org" + ]; + extra-trusted-public-keys = [ + "holochain-open-dev.cachix.org-1:3Tr+9in6uo44Ga7qiuRIfOTFXog+2+YbyhwI/Z6Cp4U=" + ]; + }; + outputs = inputs @ { ... }: inputs.holochain.inputs.flake-parts.lib.mkFlake { @@ -33,9 +42,9 @@ filterDnas = filterByHolochainPackageType "dna"; filterHapps = filterByHolochainPackageType "happ"; - rustZome = { crateCargoToml, holochain, workspacePath, excludedCrates ? [] }: + rustZome = { crateCargoToml, workspacePath, excludedCrates ? [] }: let - system = holochain.legacyPackages.cowsay.system; + system = "x86_64-linux"; pkgs = import inputs.nixpkgs { inherit system; overlays = [ (import inputs.rust-overlay) ]; diff --git a/nix/deterministic-zome.nix b/nix/deterministic-zome.nix index 7821953..04e8839 100644 --- a/nix/deterministic-zome.nix +++ b/nix/deterministic-zome.nix @@ -1,17 +1,22 @@ { + pkgs, runCommandNoCC, - dockerTools, - docker, workspacePath, - dbus, + dockerTools, crateCargoToml, - buildEnv, - git, - systemd, meta }: let + + hello = dockerTools.pullImage { + imageName = "hello-world"; + imageDigest = "sha256:e2fc4e5012d16e7fe466f5291c476431beaa1f9b90a5c2125b493ed28e2aba57"; + sha256 = "mQYzwbTpkslXAOAi4LX05kNcoPqVHfhzM8yZ9bQ7VgA="; + # finalImageTag = "nixos-23.11"; + # finalImageName = "nix"; + }; + nixFromDockerHub = dockerTools.pullImage { imageName = "nixpkgs/nix-flakes"; imageDigest = "sha256:ae2d8172d75347b040b29b726faf680f35c9beffe3f90d6a93b74fa3d5227774"; @@ -24,32 +29,32 @@ let tag = "latest"; fromImage = nixFromDockerHub; - copyToRoot = buildEnv { + copyToRoot = pkgs.buildEnv { name = "cargo-workspace"; pathsToLink = [ workspacePath "/bin" ]; - paths = [ workspacePath git ]; + paths = [ workspacePath pkgs.git ]; }; # runAsRoot = '' - # #!/bin/bash - # echo ${workspacePath} - # mkdir -p /build/source - # cp -R ${workspacePath}/* /build/source - # cd /build/source - # git init . - # git add . - # ls -la - # nix --help - # nix build .#my_zome.meta.debug + #!/bin/bash # ''; - config.Cmd = [ "/bin/nix --help"]; + # config = { + # Cmd = [ "/bin/bash"]; + # Volumes = { + # "/etc/localtime" = "/etc/localtime"; + # }; + # }; }; in runCommandNoCC "container" { - buildInputs = [dbus]; + src = image; + buildInputs = with pkgs; [ + docker + skopeo + ]; } '' - ${systemd}/bin/systemctl --user start docker - ${docker}/bin/docker load --input ${image} - ${docker}/bin/docker run -t -i build-deterministic-zome + echo ${image} + docker load --input ${image} + docker run build-deterministic-zome '' diff --git a/nix/fixture/Cargo.toml b/nix/fixture/Cargo.toml index a1a0259..968730a 100644 --- a/nix/fixture/Cargo.toml +++ b/nix/fixture/Cargo.toml @@ -13,4 +13,5 @@ serde = "1" [profile.release] opt-level = "z" trim-paths = true +codegen-units = 1 # remap-debuginfo = true diff --git a/nix/fixture/flake.lock b/nix/fixture/flake.lock index c5f4bec..311d500 100644 --- a/nix/fixture/flake.lock +++ b/nix/fixture/flake.lock @@ -717,7 +717,7 @@ }, "locked": { "lastModified": 0, - "narHash": "sha256-BW2CkwgB4tSFlNxbWG0mTjVKkmm3xWHozohgyA+/Nz8=", + "narHash": "sha256-WXZBLFHhN58QcK1zogs8LA+LmQeCSz3Uo1XsTvwLMio=", "path": "../..", "type": "path" }, @@ -1063,11 +1063,11 @@ ] }, "locked": { - "lastModified": 1709810020, - "narHash": "sha256-fSi18Ew1FxI6pnLW7njvJUe7eb6AYhv/2I4CXO4dJ5c=", + "lastModified": 1709815034, + "narHash": "sha256-38D5vqw30r6eYGfPUtjD5YqnkZDMLTlsn3NGmzWOUaQ=", "owner": "holochain", "repo": "holochain", - "rev": "8f7e419a7ef487a4167f1009a59497eecc6142f3", + "rev": "adb0030cf2de28895437026c49e2b5c6ff876895", "type": "github" }, "original": { @@ -2077,11 +2077,11 @@ }, "locked": { "dir": "versions/weekly", - "lastModified": 1709810020, - "narHash": "sha256-fSi18Ew1FxI6pnLW7njvJUe7eb6AYhv/2I4CXO4dJ5c=", + "lastModified": 1709815034, + "narHash": "sha256-38D5vqw30r6eYGfPUtjD5YqnkZDMLTlsn3NGmzWOUaQ=", "owner": "holochain", "repo": "holochain", - "rev": "8f7e419a7ef487a4167f1009a59497eecc6142f3", + "rev": "adb0030cf2de28895437026c49e2b5c6ff876895", "type": "github" }, "original": { diff --git a/nix/zome.nix b/nix/zome.nix index 1ecfdf7..7447071 100644 --- a/nix/zome.nix +++ b/nix/zome.nix @@ -2,6 +2,7 @@ runCommandLocal, runCommandNoCC, binaryen, + callPackage, craneLib, workspacePath, crateCargoToml, @@ -19,8 +20,6 @@ let doCheck = false; src = craneLib.cleanCargoSource (craneLib.path workspacePath); CARGO_BUILD_TARGET = "wasm32-unknown-unknown"; - # CARGO_BUILD_RUSTFLAGS = ""; - # RUSTC_WRAPPER = rustcWrapper; }; wasmDeps = craneLib.buildDepsOnly (commonArgs // { @@ -44,11 +43,19 @@ let cp ${wasm}/lib/${crate}.wasm $out ''; in + # callPackage ./deterministic-zome.nix { + # inherit workspacePath crateCargoToml; + # meta = { + # inherit debug; + # holochainPackageType = "zome"; + # }; + # } runCommandNoCC crate { meta = { inherit debug; holochainPackageType = "zome"; }; + buildInputs = [ binaryen ]; } '' - cp ${debug} $out + wasm-opt --strip-debug -Oz -o $out ${debug} ''