From 6c7ada6fd369153bdc8365335b2d16bce292238e Mon Sep 17 00:00:00 2001 From: Miles Breslin Date: Sat, 18 Apr 2026 13:43:26 -0700 Subject: [PATCH 1/4] Makefile: Allow overriding BUILD_DATE and GIT_HASH When building with nix directly, git is not present in the repository and the git hash must be passed manually to track it. Passing these values manually enables more deterministic builds. --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 411013d1..f3cfc86d 100644 --- a/Makefile +++ b/Makefile @@ -26,13 +26,16 @@ else MINIFY_CMD="cat" endif +BUILD_DATE=`date --rfc-3339=seconds` +GIT_HASH=`git rev-parse --short HEAD` + package_README-gen.md: package_README.md version cp $< $@ echo "" >> $@ echo "### Build Info" >> $@ echo "- Version: ${VERSION}" >> $@ - echo "- Build Date: `date --rfc-3339=seconds`" >> $@ - echo "- Git Commit: #`git rev-parse --short HEAD`" >> $@ + echo "- Build Date: ${BUILD_DATE}" >> $@ + echo "- Git Commit: #${GIT_HASH}" >> $@ ui.qml: ui.qml.in package_name version cat $< | \ From 4366ec618f0e0cb47a1c21f3667cd24374fe2932 Mon Sep 17 00:00:00 2001 From: Miles Breslin Date: Sat, 18 Apr 2026 13:47:16 -0700 Subject: [PATCH 2/4] Add support for building with nix flakes Nix is already supported by VESC Tool directly. Add similar support directly for Refloat. --- .gitignore | 2 + flake.lock | 187 ++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 45 ++++++++++++ nix/overlay.nix | 5 ++ nix/refloat.nix | 34 +++++++++ 5 files changed, 273 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/overlay.nix create mode 100644 nix/refloat.nix diff --git a/.gitignore b/.gitignore index 3700402a..e728785b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ ui.qml *.obj *.so *.vescpkg + +/result diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..c68855ab --- /dev/null +++ b/flake.lock @@ -0,0 +1,187 @@ +{ + "nodes": { + "bldcSrc": { + "flake": false, + "locked": { + "lastModified": 1733324381, + "narHash": "sha256-ui9N8QSog1G5zyK7yRrD0Xl+Y2CZhvvhBkaJuQZ2qZw=", + "owner": "vedderb", + "repo": "bldc", + "rev": "a0d40e2c5a42c810888d8c379307e6b0a118a125", + "type": "github" + }, + "original": { + "owner": "vedderb", + "ref": "release_6_05", + "repo": "bldc", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1778003029, + "narHash": "sha256-q/nkKLDtHIyLjZpKhWk3cSK5IYsFqtMd6UtXF3ddjgA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "0c88e1f2bdb93d5999019e99cb0e61e1fe2af4c5", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-25.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgsOld": { + "locked": { + "lastModified": 1748037224, + "narHash": "sha256-92vihpZr6dwEMV6g98M5kHZIttrWahb9iRPBm1atcPk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "f09dede81861f3a83f7f06641ead34f02f37597f", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1735554305, + "narHash": "sha256-zExSA1i/b+1NMRhGGLtNfFGXgLtgo+dcuzHzaWA6w3Q=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "0e82ab234249d8eee3e8c91437802b32c74bb3fd", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "vesc-tool": "vesc-tool" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1744961264, + "narHash": "sha256-aRmUh0AMwcbdjJHnytg1e5h5ECcaWtIFQa6d9gI85AI=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "8d404a69efe76146368885110f29a2ca3700bee6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + }, + "vesc-tool": { + "inputs": { + "bldcSrc": "bldcSrc", + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgsOld": "nixpkgsOld", + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1761839474, + "narHash": "sha256-1T3r7D6gQw+IuYHA+YANLd4/MfSKZ+Yqf21O1j0eLj8=", + "owner": "vedderb", + "repo": "vesc_tool", + "rev": "87689d9f69c2ffd5325224151a1f5124c93dd645", + "type": "github" + }, + "original": { + "owner": "vedderb", + "ref": "release_6_06", + "repo": "vesc_tool", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..80d30b29 --- /dev/null +++ b/flake.nix @@ -0,0 +1,45 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11"; + flake-utils.url = "github:numtide/flake-utils"; + vesc-tool.url = "github:vedderb/vesc_tool/release_6_06"; + vesc-tool.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { + self, + flake-utils, + nixpkgs, + vesc-tool, + } @ inputs: + flake-utils.lib.eachSystem ["x86_64-linux"] ( + system: let + pkgs = import nixpkgs { + inherit system; + overlays = [ + (final: prev: { + vesc-tool = vesc-tool.packages.${system}.vesc-tool; + }) + (import ./nix/overlay.nix) + (final: prev: { + refloat = prev.refloat.overrideDerivation (old: { + version = prev.lib.strings.removeSuffix "\n" (builtins.readFile ./version); + src = self; + + makeFlags = [ + "GIT_HASH=${builtins.substring 0 8 (self.rev or self.dirtyRev)}" + "BUILD_DATE=${self.lastModifiedDate}" + ]; + }); + }) + ]; + }; + in { + packages = + pkgs + // { + default = pkgs.refloat; + }; + } + ); +} diff --git a/nix/overlay.nix b/nix/overlay.nix new file mode 100644 index 00000000..8bdc7caa --- /dev/null +++ b/nix/overlay.nix @@ -0,0 +1,5 @@ +final: prev: { + refloat = final.callPackage ./refloat.nix { + gcc-arm-embedded = final.gcc-arm-embedded-13; + }; +} diff --git a/nix/refloat.nix b/nix/refloat.nix new file mode 100644 index 00000000..6bdf966d --- /dev/null +++ b/nix/refloat.nix @@ -0,0 +1,34 @@ +{ + lib, + stdenv, + gcc-arm-embedded, + vesc-tool, + python3, +}: +stdenv.mkDerivation { + pname = "refloat"; + version = "0.0.0-dev"; + + src = ../.; + + postPatch = '' + # Python shebang is failing for some reason. Replace it with full shebang + sed -i '1s,.*,#!${lib.getExe python3},' rjsmin.py + echo "$version" > ./version + ''; + + doFixup = false; + + nativeBuildInputs = [ + gcc-arm-embedded + vesc-tool + python3 + ]; + + installPhase = '' + mkdir $out + cp src/package_lib.elf $out/refloat.elf + cp refloat.vescpkg $out + cat src/conf/confparser.h | sed -n 's/^#define .\+_SIGNATURE\W\+\([0-9]*\)/\1/p' > $out/config_signature.txt + ''; +} From 8743ab28749549f6c06273a61f0a34f5afd298cb Mon Sep 17 00:00:00 2001 From: Miles Breslin Date: Sat, 18 Apr 2026 14:26:43 -0700 Subject: [PATCH 3/4] CI/CD: Use nix to build By using Nix in CI, we reference flake.lock. This file pins the version of all inputs to this build. Previously, the version of nixpkgs and vesc_tool were technically not reproducible because they reference branches which may change. The flake.lock converts those references to commit SHAs, which are tracked by git. This commit comes with the cost that maintainers of this repository must commit a flake.lock update when updating versions. Changing version strings without doing this is not valid. However, this commit comes with a benefit that CI is binary reproducible locally. --- .github/actions/build/action.yml | 5 +---- .github/workflows/create_release.yml | 8 +++----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 8bad1d93..a1cb712f 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -13,10 +13,7 @@ runs: with: name: refloat authToken: '${{ inputs.cache-auth-token }}' - - uses: rrbutani/use-nix-shell-action@v1 - with: - flakes: nixpkgs/nixos-24.11#gcc-arm-embedded-13, nixpkgs#gnumake, github:lukash/vesc_tool-flake/release_6_06 - name: Build shell: bash - run: make -j + run: nix build .#refloat diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 99f2fae8..5d6ef272 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -51,13 +51,11 @@ jobs: with: cache-auth-token: '${{ secrets.CACHIX_AUTH_TOKEN }}' - - name: Extract Config Signature - run: cat src/conf/confparser.h | sed -n 's/^#define .\+_SIGNATURE\W\+\([0-9]*\)/\1/p' > config_signature.txt - - name: Rename Package File run: | - mv refloat.vescpkg refloat-${{env.VERSION}}.vescpkg - mv src/package_lib.elf refloat-${{env.VERSION}}.elf + cp result/refloat.vescpkg refloat-${{env.VERSION}}.vescpkg + cp result/refloat.elf refloat-${{env.VERSION}}.elf + cp result/config_signature.txt config_signature.txt - name: Install Changelog Generation Dependencies run: sudo apt-get install python3-git From 6eed3687d22fcc6665fb77f6297cd2f585818a6f Mon Sep 17 00:00:00 2001 From: Miles Breslin Date: Sat, 18 Apr 2026 14:39:45 -0700 Subject: [PATCH 4/4] CI/CD: Use flake.lock for linters Previously, linters were using nixpkgs directly, which is a branch that is moving. By using inputs from the local lock-file, we ensure that we only take in changes to linter versions when a Refloat commit updates them. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fcdbf73d..2aa781e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,7 @@ jobs: - uses: rrbutani/use-nix-shell-action@v1 with: flakes: nixpkgs#llvmPackages_18.clang-tools, nixpkgs#pre-commit + extraNixOptions: --inputs-from . - name: Run clang-format id: clang-format