Skip to content

Commit

Permalink
add formatter and pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
hall committed Jan 15, 2023
1 parent 1ce81d1 commit 15d0a31
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 16 deletions.
12 changes: 8 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ nix develop # or use direnv or do the setup yourself, whatever
Build the project with

```sh
make -j
nix build # or `make -j`
```

The compiled firmware will be at `./out/firmware.bin`.
The compiled firmware will be at `./result/*.bin`.

## language

Expand All @@ -40,13 +40,17 @@ make -j LANGUAGE=fr

Flash both earbuds:

for i in 0 1; do bestool write-image --port /dev/ttyACM$i result/*.bin; done
```sh
nix run '.#flash' [./path/to/firmware.bin]
```

## logs

View logs over the serial port with

minicom -D /dev/ttyACM0 -b 2000000
```sh
nix run '.#logs' <left|right>
```

## release

Expand Down
107 changes: 107 additions & 0 deletions flake.lock

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

58 changes: 46 additions & 12 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
inputs = {
utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11";
pre-commit.url = "github:cachix/pre-commit-hooks.nix";
};

outputs = inputs@{ self, ... }:
Expand All @@ -14,18 +15,33 @@
(system:
let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
{
formatter = pkgs.treefmt;
apps = {
flash = inputs.utils.lib.mkApp {
drv = pkgs.writeShellScriptBin "tts" ''
# should correctly identify the pinebuds
id=/dev/serial/by-id/usb-wch.cn_USB_Dual_Serial_0123456789-if
for i in 00 02; do
path=/dev/serial/by-id/usb-wch.cn_USB_Dual_Serial_0123456789-if
for id in 02 00; do
# use the given file or a default
[ $# -eq 1 ] && bin=$1 || bin=result/little-buddy-*-''${LANGUAGE:-en}.bin
${self.packages.${system}.bestool}/bin/bestool write-image --port $id$i $bin
${self.packages.${system}.bestool}/bin/bestool write-image --port $path$id $bin
done
'';
};
logs = inputs.utils.lib.mkApp {
drv = pkgs.writeShellScriptBin "tts" ''
if [ $1 == "left" ]; then
id=02
elif [ $1 == "right" ]; then
id=00
else
echo error: must pass either \"left\" or \"right\" as an argument
exit 1
fi
path=/dev/serial/by-id/usb-wch.cn_USB_Dual_Serial_0123456789-if
${pkgs.minicom}/bin/minicom -D $path$id -b 2000000
'';
};
tts = inputs.utils.lib.mkApp {
drv = pkgs.writeShellScriptBin "tts" ''
LANGUAGE=$1
Expand Down Expand Up @@ -60,22 +76,14 @@
udev
];
};

default = pkgs.stdenv.mkDerivation rec {
name = "little-buddy";
src = ./.;
nativeBuildInputs = with pkgs; [
# https://github.com/NixOS/nixpkgs/issues/51907
gcc-arm-embedded-9

bc
hostname

# serial
minicom
self.packages.${system}.bestool

# audio
ffmpeg
xxd
];
Expand All @@ -91,5 +99,31 @@
'';
};
};
});
checks = {
pre-commit = inputs.pre-commit.lib."${system}".run {
src = ./.;
hooks = {
treefmt = {
name = "treefmt";
enable = true;
types = [ "file" ];
pass_filenames = true;
entry = "${pkgs.treefmt}/bin/treefmt";
};
};
};
};
devShell = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit) shellHook;
inputsFrom = [ self.packages.${system}.default ];
buildInputs = with pkgs; [
# formatters
treefmt
nixpkgs-fmt
nodePackages.prettier
clang
];
};
}
);
}
25 changes: 25 additions & 0 deletions treefmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[formatter.nix]
command = "nixpkgs-fmt"
includes = ["*.nix"]

[formatter.prettier]
command = "prettier"
options = ["--write"]
includes = [
"*.css",
"*.html",
"*.js",
"*.json",
"*.jsx",
"*.md",
"*.mdx",
"*.scss",
"*.ts",
"*.yaml",
]

# TODO: breaks compilation
# [formatter.clang]
# command = "clang-format"
# options = [ "-i" ]
# includes = [ "*.c", "*.cpp", "*.cc", "*.h", "*.hpp", "*.S" ]

0 comments on commit 15d0a31

Please sign in to comment.