Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ ui.qml
*.obj
*.so
*.vescpkg

/result
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 $< | \
Expand Down
187 changes: 187 additions & 0 deletions flake.lock

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

45 changes: 45 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
);
}
5 changes: 5 additions & 0 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
final: prev: {
refloat = final.callPackage ./refloat.nix {
gcc-arm-embedded = final.gcc-arm-embedded-13;
};
}
34 changes: 34 additions & 0 deletions nix/refloat.nix
Original file line number Diff line number Diff line change
@@ -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
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ugly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. I tried getting it to work with /usr/bin/env, but it wasn't working when I tried it. I can take another look and see if there's a better way around this.

echo "$version" > ./version
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should ideally be one source of truth for version and you're duplicating it here. And version is set to 0.0.0-dev above. Not sure what this is supposed to be doing but given version is set to 0.0.0-dev above, not sure it even does what it's supposed to.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This delegates the single source of truth into nix, which defaults to reading the version file. If the nix package states a version, that will be embedded into the binary.

I designed nix/refloat.nix to be generic, and not dependent on the nix flake. 0.0.0-dev is used as a placeholder in the generic build implementation. It is then overridden in the flake.nix by reading the version file. This keeps nix/refloat.nix generic, while maintaining expected behavior for development using the nix flake.

I think echo "$version" > ./version should stay, but if we want to change the placeholder version or shift where that logic is, no problem.

'';

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
'';
}