Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Mar 7, 2024
1 parent 5a16efd commit 2fd9cda
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 40 deletions.
67 changes: 62 additions & 5 deletions .github/workflows/test-nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
13 changes: 11 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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) ];
Expand Down
51 changes: 28 additions & 23 deletions nix/deterministic-zome.nix
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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
''
1 change: 1 addition & 0 deletions nix/fixture/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ serde = "1"
[profile.release]
opt-level = "z"
trim-paths = true
codegen-units = 1
# remap-debuginfo = true
14 changes: 7 additions & 7 deletions nix/fixture/flake.lock

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

13 changes: 10 additions & 3 deletions nix/zome.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
runCommandLocal,
runCommandNoCC,
binaryen,
callPackage,
craneLib,
workspacePath,
crateCargoToml,
Expand All @@ -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 // {
Expand All @@ -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}
''

0 comments on commit 2fd9cda

Please sign in to comment.