From 20fb2f919456921a8df561bd417a3f8338a3cd28 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Fri, 18 Oct 2024 11:17:52 +0200 Subject: [PATCH 1/6] Add tarball for FPGA --- lagarto-ox.nix | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/lagarto-ox.nix b/lagarto-ox.nix index 571cc1c..d3c3d25 100644 --- a/lagarto-ox.nix +++ b/lagarto-ox.nix @@ -546,6 +546,91 @@ EOF ''; + # A tarball with all the parts to boot NixOS in a FPGA + fpga-tarball = let + build = config.system.build; + in prev.stdenv.mkDerivation rec { + name = "nixos-riscv"; + src = ./fpga; + + COMMIT = if self ? rev then self.rev + else throw ("Refusing to build tarball from a dirty Git tree!"); + + TOPLEVEL = build.toplevel; + OPENSBI = final.opensbi; + KERNEL = build.kernel; + INITRD = build.initialRamdisk; + ROOTFS = build.sdImage; + UBOOT_ENV = final.uboot-env; + BITSTREAM = final.bitstream; + BOOTROM = final.bootrom; + bitName = builtins.baseNameOf BITSTREAM; + + unpackPhase = '' + mkdir -p src/nixos-riscv + ln -s $src fpga + fpga/upload.sh src/nixos-riscv + chmod +w -R src + sourceRoot=src + ''; + + buildPhase = '' + cat > nixos-riscv/README.txt < + + These files allow you to boot NixOS on Lagarto Ox. They correspond to + this commit: + + https://pm.bsc.es/gitlab/rarias/nixos-riscv/-/commit/${COMMIT} + + Here are the pieces used by this system: + + COMMIT = ${COMMIT} + TOPLEVEL = ${TOPLEVEL} + OPENSBI = ${OPENSBI} + KERNEL = ${KERNEL} + INITRD = ${INITRD} + ROOTFS = ${ROOTFS} + UBOOT_ENV = ${UBOOT_ENV} + BITSTREAM = ${BITSTREAM} + BOOTROM = ${BOOTROM} + + Copy these files into a MEEP FPGA node, then allocate a FPGA node and + run from this directory (don't forget the dot at the end): + + $ ./run-node.sh . + + That would flash the bitstream and NixOS and boot the whole system + until the login, and exit after some inactivity period. You should see + this message near the end: + + __________________ + < Welcome to NixOS > + ------------------ + ^__^ + (oo)_______ + (__) )/ + ||----w | + || || + + If you can read this message then then you have + successfully booted NixOS into the login shell. + + EOF + ''; + + installPhase = '' + mkdir -p $out + tar czvf $out/${COMMIT}.tar.gz nixos-riscv + ''; + + nativeBuildInputs = with final.buildPackages; [ rsync ]; + }; + opensbi = prev.opensbi.overrideAttrs (old: rec { #version = "1.4"; version = "1.5"; -- 2.45.2 From 97d477d2850e696930d66041069306a210bb9b16 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Mon, 21 Oct 2024 08:53:54 +0200 Subject: [PATCH 2/6] Add tarball to CI and make steps manual --- .gitlab-ci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3cdbd5d..c6e9563 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,23 @@ build:lagarto-ox: stage: build + when: manual tags: - nix script: - nix develop -L .#lagarto-ox --command fpga/run-remotely.sh fpgalogin1:ci + +build:lagarto-ox-tarball: + stage: build + when: manual + tags: + - nix + script: + - nix build -L .#nixosConfigurations.lagarto-ox.pkgs.fpga-tarball + - cd result + - out=/ceph/home/gitlab-runner/public_html/nixos-riscv/ + - fn=$(ls | head -1) + - cp $fn $out/$fn + - rm -f $out/latest.tar.gz + - ln -s $out/$fn $out/latest.tar.gz + - cd .. + - rm result -- 2.45.2 From 53ab72fa202852e8f64ffdf39b31231a60028176 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Mon, 21 Oct 2024 09:17:10 +0200 Subject: [PATCH 3/6] Switch to ZST for tarball It is faster then Gzip and available in MEEP FPGA cluster. --- .gitlab-ci.yml | 4 ++-- lagarto-ox.nix | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c6e9563..e254767 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,7 +17,7 @@ build:lagarto-ox-tarball: - out=/ceph/home/gitlab-runner/public_html/nixos-riscv/ - fn=$(ls | head -1) - cp $fn $out/$fn - - rm -f $out/latest.tar.gz - - ln -s $out/$fn $out/latest.tar.gz + - rm -f $out/latest.tar.zst + - ln -s $out/$fn $out/latest.tar.zst - cd .. - rm result diff --git a/lagarto-ox.nix b/lagarto-ox.nix index d3c3d25..a34ac6a 100644 --- a/lagarto-ox.nix +++ b/lagarto-ox.nix @@ -625,10 +625,10 @@ installPhase = '' mkdir -p $out - tar czvf $out/${COMMIT}.tar.gz nixos-riscv + tar -I zstd -cvf $out/${COMMIT}.tar.zst nixos-riscv ''; - nativeBuildInputs = with final.buildPackages; [ rsync ]; + nativeBuildInputs = with final.buildPackages; [ rsync zstd ]; }; opensbi = prev.opensbi.overrideAttrs (old: rec { -- 2.45.2 From 6cb22575b364df071853735733b956d522de6fc9 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Mon, 21 Oct 2024 09:21:49 +0200 Subject: [PATCH 4/6] Print URL for tarball --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e254767..33db893 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,3 +21,6 @@ build:lagarto-ox-tarball: - ln -s $out/$fn $out/latest.tar.zst - cd .. - rm result + - | + echo "Pinned: https://jungle.bsc.es/~gitlab-runner/nixos-riscv/$fn" + echo "Latest: https://jungle.bsc.es/~gitlab-runner/nixos-riscv/latest.tar.zst" -- 2.45.2 From 81bd11999a612118101ae5db4c1ff1fd19876ad7 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Mon, 21 Oct 2024 09:38:59 +0200 Subject: [PATCH 5/6] Use --zstd flag in tar --- lagarto-ox.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lagarto-ox.nix b/lagarto-ox.nix index a34ac6a..c5aa356 100644 --- a/lagarto-ox.nix +++ b/lagarto-ox.nix @@ -625,7 +625,7 @@ installPhase = '' mkdir -p $out - tar -I zstd -cvf $out/${COMMIT}.tar.zst nixos-riscv + tar --zstd -cvf $out/${COMMIT}.tar.zst nixos-riscv ''; nativeBuildInputs = with final.buildPackages; [ rsync zstd ]; -- 2.45.2 From 5da53c69b8b33d2323a363ac269859a89d816579 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Tue, 22 Oct 2024 13:57:46 +0200 Subject: [PATCH 6/6] Add tarball script for CI Allows the same script to be executed by GitLab and Gitea runners. --- .gitea/workflows/ci.yaml | 9 +++++++++ .gitlab-ci.yml | 12 +----------- ci/make-tarball.sh | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 .gitea/workflows/ci.yaml create mode 100755 ci/make-tarball.sh diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml new file mode 100644 index 0000000..8e2dd4e --- /dev/null +++ b/.gitea/workflows/ci.yaml @@ -0,0 +1,9 @@ +name: CI +on: push + +jobs: + build:lagarto-ox-tarball: + runs-on: native + steps: + - uses: https://gitea.com/ScMi1/checkout@v1.4 + - run: ci/make-tarball.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 33db893..d344286 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,14 +13,4 @@ build:lagarto-ox-tarball: - nix script: - nix build -L .#nixosConfigurations.lagarto-ox.pkgs.fpga-tarball - - cd result - - out=/ceph/home/gitlab-runner/public_html/nixos-riscv/ - - fn=$(ls | head -1) - - cp $fn $out/$fn - - rm -f $out/latest.tar.zst - - ln -s $out/$fn $out/latest.tar.zst - - cd .. - - rm result - - | - echo "Pinned: https://jungle.bsc.es/~gitlab-runner/nixos-riscv/$fn" - echo "Latest: https://jungle.bsc.es/~gitlab-runner/nixos-riscv/latest.tar.zst" + - ci/make-tarball.sh result && rm result diff --git a/ci/make-tarball.sh b/ci/make-tarball.sh new file mode 100755 index 0000000..01b2e75 --- /dev/null +++ b/ci/make-tarball.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +nix build -L '.#nixosConfigurations.lagarto-ox.pkgs.fpga-tarball' + +cd result +out=/ceph/home/gitlab-runner/public_html/nixos-riscv/ +fn=$(ls | head -1) +cp "$fn" "$out/$fn" +rm -f "$out/latest.tar.zst" +ln -s "$out/$fn" "$out/latest.tar.zst" +rm result + +echo "Pinned: https://jungle.bsc.es/~gitlab-runner/nixos-riscv/$fn" +echo "Latest: https://jungle.bsc.es/~gitlab-runner/nixos-riscv/latest.tar.zst" -- 2.45.2