From ee9f082d5c5e5b2f307865d936f55df362ac0a14 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 7 May 2025 08:25:50 +0200 Subject: [PATCH 1/3] fix(nix): Only attempt to include EtherCAT support on x86_64 platforms Signed-off-by: Steffen Vogel --- packaging/nix/villas.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packaging/nix/villas.nix b/packaging/nix/villas.nix index 134918258..10e5f263e 100644 --- a/packaging/nix/villas.nix +++ b/packaging/nix/villas.nix @@ -19,7 +19,7 @@ # Node-types withNodeAmqp ? withAllNodes, withNodeComedi ? withAllNodes, - withNodeEthercat ? withAllNodes, + withNodeEthercat ? (withAllNodes && system == "x86_64-linux"), withNodeIec60870 ? withAllNodes, withNodeIec61850 ? withAllNodes, withNodeInfiniband ? withAllNodes, @@ -42,6 +42,7 @@ jq, lib, makeWrapper, + system, pkg-config, stdenv, # Optional dependencies From b9f1166267fb28602641d501e204b0f5cc7fa924 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 7 May 2025 08:26:25 +0200 Subject: [PATCH 2/3] feat(nix): Add simple access to cross-compiled packages Signed-off-by: Steffen Vogel --- flake.nix | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/flake.nix b/flake.nix index ba75bed90..99993a9ee 100644 --- a/flake.nix +++ b/flake.nix @@ -71,6 +71,27 @@ config.ENTRYPOINT = "/bin/villas"; }; + # Cross-compiled packages + + villas-node-x86_64-linux = if pkgs.system == "x86_64-linux" then pkgs.villas-node else pkgs.pkgsCross.x86_64-linux.villas-node; + villas-node-aarch64-linux = if pkgs.system == "aarch64-linux" then pkgs.villas-node else pkgs.pkgsCross.aarch64-multiplatform.villas-node; + + dockerImage-x86_64-linux = pkgs.dockerTools.buildLayeredImage { + name = "villas-node"; + tag = "latest-nix-x86_64-linux"; + contents = [ villas-node-x86_64-linux ]; + config.ENTRYPOINT = "/bin/villas"; + }; + + dockerImage-aarch64-linux = pkgs.dockerTools.buildLayeredImage { + name = "villas-node"; + tag = "latest-nix-aarch64-linux"; + contents = [ villas-node-aarch64-linux ]; + config.ENTRYPOINT = "/bin/villas"; + }; + + # Third-party dependencies + opendssc = pkgs.callPackage (nixDir + "/opendssc.nix") { }; }; in From 7ad0c30ad5c820ca76374116d4e7fb21c7986534 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 7 May 2025 08:30:44 +0200 Subject: [PATCH 3/3] feat(nix): Add cache and start cross-building VILLASnode for aarch64-linux Signed-off-by: Steffen Vogel --- .gitlab-ci.yml | 48 ++++++++++++++++++------------------------------ flake.nix | 9 +++++++++ 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3b6a28b10..65108dbd3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -89,53 +89,41 @@ build:source: build:nix: stage: build - image: nixos/nix + image: docker.nix-community.org/nixpkgs/cachix-flakes needs: [] + variables: + CACHIX_CACHE_NAME: villas + + parallel: + matrix: + - SYSTEM: [x86_64-linux, aarch64-linux] artifacts: when: on_success access: all expire_in: "1 year" paths: - - artifacts/villas + - artifacts/* before_script: - - | # Create artifacts directory - mkdir artifacts - - - | # Configure Nix - echo "experimental-features = flakes nix-command" >> /etc/nix/nix.conf - - # - | # Configure Attic - # nix shell nixpgks#attic-client + - cachix use "$CACHIX_CACHE_NAME" - # attic login nulll https://cache.0l.de ${ATTIC_TOKEN} - # attic use "nulll:villas" + - | # Create directories + mkdir -p artifacts /var/tmp/ - script: - - nix build --print-build-logs . - - - | # Build ARX bundle - nix bundle --out-link villas . - cp -L villas artifacts/villas - - - | # Build Docker image + - | # Login at Docker registry nix run nixpkgs#skopeo -- login \ --username ${CI_REGISTRY_USER} \ --password ${CI_REGISTRY_PASSWORD} \ ${CI_REGISTRY} - nix build '.#dockerImage' - - nix run nixpkgs#skopeo -- copy --insecure-policy \ - "docker-archive:./result" \ - "docker://${DOCKER_IMAGE}:${DOCKER_TAG}-nix" - - # after_script: - # - | # Push whole store to cache - # nix shell nixpgks#attic-client + script: + - cachix watch-exec $CACHIX_CACHE_NAME -- nix build --print-build-logs ".#villas-node-${SYSTEM}" + - cachix watch-exec $CACHIX_CACHE_NAME -- nix bundle --print-build-logs --out-link bundle ".#villas-node-${SYSTEM}" + - cachix watch-exec $CACHIX_CACHE_NAME -- nix build --print-build-logs --out-link docker ".#dockerImage-${SYSTEM}" - # attic push /nix/store/* + - cp -L bundle artifacts/villas-${SYSTEM} + - nix run nixpkgs#skopeo -- --tmpdir=${TMPDIR} --insecure-policy copy "docker-archive:./docker" "docker://${DOCKER_IMAGE}:${DOCKER_TAG}-nix-${SYSTEM}" # Stage: test diff --git a/flake.nix b/flake.nix index 99993a9ee..330032da9 100644 --- a/flake.nix +++ b/flake.nix @@ -3,6 +3,15 @@ { description = "VILLASnode is a client/server application to connect simulation equipment and software."; + nixConfig = { + extra-substituters = [ + "https://villas.cachix.org" + ]; + extra-trusted-public-keys = [ + "villas.cachix.org-1:vCWp9IzwxFT6ovZivQAvn5ZuLST01bpAGXWwlGTZ9fA=" + ]; + }; + inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; };