From da5d731b5037bfe67945825dd592a74f77fbe8a0 Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Fri, 11 Oct 2024 15:59:29 -0500 Subject: [PATCH] Use git-hooks.nix, treefmt-nix, and nix-direnv --- .editorconfig | 19 + .envrc | 5 + .github/workflows/build-pico.yaml | 2 +- .github/workflows/check-image-metadata.yaml | 38 -- .github/workflows/clippy-attiny85.yaml | 2 - .github/workflows/flake-lock-updater.yaml | 1 + .github/workflows/format-just.yaml | 28 - .github/workflows/link-checker.yaml | 39 ++ .github/workflows/rustfmt.yaml | 24 - ...adata.yaml => test-update-nix-direnv.yaml} | 18 +- .github/workflows/treefmt.yaml | 21 + ...autoupdate.yaml => update-nix-direnv.yaml} | 19 +- .gitignore | 9 + .justfile | 48 +- .pre-commit-config.yaml | 76 --- .vscode/extensions.json | 13 +- .vscode/settings.json | 123 ++-- .yamlfmt.yaml | 3 + .yamllint.yaml | 2 + README.adoc | 2 +- boards/attiny85/Cargo.toml | 2 +- boards/attiny85/README.adoc | 8 +- boards/attiny85/default.nix | 12 +- boards/pico/.cargo/config.toml | 15 +- boards/pico/Embed.toml | 2 +- boards/pico/README.adoc | 8 +- boards/pico/default.nix | 40 +- boards/qt-py-ch32v203/.cargo/config.toml | 4 +- boards/qt-py-ch32v203/Cargo.toml | 16 +- boards/qt-py-ch32v203/README.adoc | 8 +- boards/qt-py-ch32v203/default.nix | 80 +-- check-image-metadata-tests.nu | 246 ------- check-image-metadata.nu | 77 --- flake.lock | 139 +++- flake.nix | 629 +++++++++++++----- lychee.toml | 10 + update-nix-direnv-tests.nu | 29 + update-nix-direnv.nu | 59 ++ 38 files changed, 984 insertions(+), 892 deletions(-) create mode 100644 .editorconfig create mode 100644 .envrc delete mode 100644 .github/workflows/check-image-metadata.yaml delete mode 100644 .github/workflows/format-just.yaml create mode 100644 .github/workflows/link-checker.yaml delete mode 100644 .github/workflows/rustfmt.yaml rename .github/workflows/{test-check-image-metadata.yaml => test-update-nix-direnv.yaml} (50%) create mode 100644 .github/workflows/treefmt.yaml rename .github/workflows/{pre-commit-autoupdate.yaml => update-nix-direnv.yaml} (51%) delete mode 100644 .pre-commit-config.yaml create mode 100644 .yamlfmt.yaml delete mode 100755 check-image-metadata-tests.nu delete mode 100755 check-image-metadata.nu create mode 100644 lychee.toml create mode 100755 update-nix-direnv-tests.nu create mode 100755 update-nix-direnv.nu diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0a256d7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_size = 2 +indent_style = space +max_line_length = 120 +trim_trailing_whitespace = true + +[*.adoc] +indent_size = unset + +[*.{adoc,envrc,nix,nu}] +max_line_length = off + +[{justfile,.justfile,*.just,*.rs}] +indent_size = 4 diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..720e019 --- /dev/null +++ b/.envrc @@ -0,0 +1,5 @@ +if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM=" +fi + +use flake diff --git a/.github/workflows/build-pico.yaml b/.github/workflows/build-pico.yaml index 890b5f9..59c07db 100644 --- a/.github/workflows/build-pico.yaml +++ b/.github/workflows/build-pico.yaml @@ -1,4 +1,4 @@ -name: Build Rasbperry Pi Pico +name: Build Raspberry Pi Pico "on": pull_request: diff --git a/.github/workflows/check-image-metadata.yaml b/.github/workflows/check-image-metadata.yaml deleted file mode 100644 index 5a30d65..0000000 --- a/.github/workflows/check-image-metadata.yaml +++ /dev/null @@ -1,38 +0,0 @@ -name: Check image metadata -"on": - pull_request: - branches: ["main"] - paths: - - .github/workflows/check-image-metadata.yaml - - flake.lock - - check-image-metadata.nu - - '**.gif' - - '**.jpg' - - '**.jpeg' - - '**.png' - - '**.webp' - push: - branches: ["main"] - paths: - - .github/workflows/check-image-metadata.yaml - - flake.lock - - check-image-metadata.nu - - '**.gif' - - '**.jpg' - - '**.jpeg' - - '**.png' - - '**.webp' - -jobs: - check-image-metadata: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: DeterminateSystems/nix-installer-action@v14 - - uses: DeterminateSystems/magic-nix-cache-action@v8 - - name: Get changed files - id: changed-files - uses: tj-actions/changed-files@v45 - - name: Check image metadata - run: | - nix develop --command nu check-image-metadata.nu ${{ steps.changed-files.outputs.all_changed_files }} diff --git a/.github/workflows/clippy-attiny85.yaml b/.github/workflows/clippy-attiny85.yaml index c726a06..08cd69d 100644 --- a/.github/workflows/clippy-attiny85.yaml +++ b/.github/workflows/clippy-attiny85.yaml @@ -24,5 +24,3 @@ jobs: - uses: actions/checkout@v4 - uses: DeterminateSystems/nix-installer-action@v14 - uses: DeterminateSystems/magic-nix-cache-action@v8 - # - name: Lint Rust code with Clippy - # run: nix develop --command 'cd boards/attiny85; cargo clippy' diff --git a/.github/workflows/flake-lock-updater.yaml b/.github/workflows/flake-lock-updater.yaml index 694b9e8..4235abe 100644 --- a/.github/workflows/flake-lock-updater.yaml +++ b/.github/workflows/flake-lock-updater.yaml @@ -22,5 +22,6 @@ jobs: pr-labels: | automated dependencies + pr-reviewers: ${{ github.repository_owner }} pr-title: "chore: update flake.lock" token: ${{ secrets.GH_TOKEN_FOR_UPDATES }} diff --git a/.github/workflows/format-just.yaml b/.github/workflows/format-just.yaml deleted file mode 100644 index 936026f..0000000 --- a/.github/workflows/format-just.yaml +++ /dev/null @@ -1,28 +0,0 @@ -name: Format justfiles -"on": - pull_request: - branches: ["main"] - paths: - - .github/workflows/format-just.yaml - - flake.lock - - '**/.justfile' - - '**/justfile' - - '**/*.just' - push: - branches: ["main"] - paths: - - .github/workflows/format-just.yaml - - flake.lock - - '**/.justfile' - - '**/justfile' - - '**/*.just' - -jobs: - format-just: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: DeterminateSystems/nix-installer-action@v14 - - uses: DeterminateSystems/magic-nix-cache-action@v8 - - name: Format justfile - run: nix develop --command just --check --fmt --unstable diff --git a/.github/workflows/link-checker.yaml b/.github/workflows/link-checker.yaml new file mode 100644 index 0000000..897a6ea --- /dev/null +++ b/.github/workflows/link-checker.yaml @@ -0,0 +1,39 @@ +name: Check URLs with Lychee + +"on": + pull_request: + branches: [main] + paths: + - .github/workflows/link-checker.yaml + - flake.lock + - '**.adoc' + push: + branches: [main] + paths: + - .github/workflows/link-checker.yaml + - flake.lock + - '**.adoc' + schedule: + # Run once a month on the 14th. + - cron: "0 0 14 * *" + workflow_dispatch: + +jobs: + link-checker: + runs-on: ubuntu-latest + steps: + - name: Restore lychee cache + uses: actions/cache@v4 + with: + path: .lycheecache + key: cache-lychee-${{ github.sha }} + restore-keys: cache-lychee- + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@v14 + - uses: DeterminateSystems/magic-nix-cache-action@v8 + - name: Convert the Asciidoc files to html + run: nix develop --command asciidoctor ./**/*.adoc + - name: Run lychee on the generated site + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: nix develop --command lychee --cache --no-progress --verbose ./**/*.html diff --git a/.github/workflows/rustfmt.yaml b/.github/workflows/rustfmt.yaml deleted file mode 100644 index f08401f..0000000 --- a/.github/workflows/rustfmt.yaml +++ /dev/null @@ -1,24 +0,0 @@ -name: Format Rust code -"on": - pull_request: - branches: ["main"] - paths: - - .github/workflows/rustfmt.yaml - - flake.lock - - '**.rs' - push: - branches: ["main"] - paths: - - .github/workflows/rustfmt.yaml - - flake.lock - - '**.rs' - -jobs: - rustfmt: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: DeterminateSystems/nix-installer-action@v14 - - uses: DeterminateSystems/magic-nix-cache-action@v8 - - name: Check Rust formatting - run: nix develop --command nu --commands 'rustfmt --check **/*.rs' diff --git a/.github/workflows/test-check-image-metadata.yaml b/.github/workflows/test-update-nix-direnv.yaml similarity index 50% rename from .github/workflows/test-check-image-metadata.yaml rename to .github/workflows/test-update-nix-direnv.yaml index f0fcae7..1465960 100644 --- a/.github/workflows/test-check-image-metadata.yaml +++ b/.github/workflows/test-update-nix-direnv.yaml @@ -1,27 +1,27 @@ -name: Test check-image-metadata.nu +name: Test update-nix-direnv.nu "on": pull_request: branches: ["main"] paths: - - .github/workflows/test-check-image-metadata.yaml + - .github/workflows/test-update-nix-direnv.yaml - flake.lock - - check-image-metadata.nu - - check-image-metadata-tests.nu + - update-nix-direnv.nu + - update-nix-direnv-tests.nu push: branches: ["main"] paths: - - .github/workflows/test-check-image-metadata.yaml + - .github/workflows/test-update-nix-direnv.yaml - flake.lock - - check-image-metadata.nu - - check-image-metadata-tests.nu + - update-nix-direnv.nu + - update-nix-direnv-tests.nu workflow_dispatch: jobs: - test-check-image-metadata: + test-update-nix-direnv: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: DeterminateSystems/nix-installer-action@v14 - uses: DeterminateSystems/magic-nix-cache-action@v8 - name: Run the Nushell tests - run: nix develop --command nu check-image-metadata-tests.nu + run: nix develop --command nu update-nix-direnv-tests.nu diff --git a/.github/workflows/treefmt.yaml b/.github/workflows/treefmt.yaml new file mode 100644 index 0000000..688a2cc --- /dev/null +++ b/.github/workflows/treefmt.yaml @@ -0,0 +1,21 @@ +name: Check files with treefmt +"on": + pull_request: + branches: ["main"] + push: + branches: ["main"] + +jobs: + treefmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@v14 + - uses: DeterminateSystems/magic-nix-cache-action@v8 + - name: Run treefmt + run: nix develop --command treefmt --ci + - uses: reviewdog/action-suggester@v1 + with: + fail_on_error: true + github_token: ${{ secrets.GH_TOKEN_FOR_UPDATES }} + tool_name: treefmt diff --git a/.github/workflows/pre-commit-autoupdate.yaml b/.github/workflows/update-nix-direnv.yaml similarity index 51% rename from .github/workflows/pre-commit-autoupdate.yaml rename to .github/workflows/update-nix-direnv.yaml index 1c5626b..4ca2b0b 100644 --- a/.github/workflows/pre-commit-autoupdate.yaml +++ b/.github/workflows/update-nix-direnv.yaml @@ -1,9 +1,8 @@ -name: Pre-commit auto-update +name: Update nix-direnv "on": schedule: - # Once a month on the 2nd - - cron: "0 0 2 * *" + - cron: "0 0 16 * *" workflow_dispatch: permissions: @@ -11,21 +10,19 @@ permissions: pull-requests: write jobs: - pre-commit-autoupdate: + update-nix-direnv: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: DeterminateSystems/nix-installer-action@v14 - uses: DeterminateSystems/magic-nix-cache-action@v8 - - name: Update pre-commit hooks - run: nix develop --command pre-commit autoupdate - - name: Run pre-commit hooks - run: nix develop --command pre-commit run --all-files + - name: Update nix-direnv to the latest version + run: nix develop --command nu update-nix-direnv.nu - name: Create Pull Request uses: peter-evans/create-pull-request@v7 with: assignees: ${{ github.repository_owner }} - branch: "update/pre-commit-hooks" - commit-message: "chore(deps): Update pre-commit hooks" - title: "chore(deps): Update pre-commit hooks" + branch: "update/nix-direnv" + commit-message: "chore(deps): Update nix-direnv" + title: "chore(deps): Update nix-direnv" token: ${{ secrets.GH_TOKEN_FOR_UPDATES }} diff --git a/.gitignore b/.gitignore index 5580148..2d9f851 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,12 @@ target/ # Nix result + +# git-hooks.nix +/.pre-commit-config.yaml + +# Asciidoctor +*.html + +# lychee +.lycheecache diff --git a/.justfile b/.justfile index a97ca1f..c318299 100644 --- a/.justfile +++ b/.justfile @@ -2,15 +2,13 @@ set shell := ["nu", "-c"] default: build -alias fmt := format - -format: just-fmt rustfmt - -rustfmt: - ^rustfmt **/*.rs +alias c := check -just-fmt: - ^just --fmt --unstable +check: && format + #!/usr/bin/env nu + ^yamllint . + ^asciidoctor '**/*.adoc' + ^lychee --cache **/*.html alias b := build @@ -22,6 +20,11 @@ build board="attiny85" profile="dev": ^cargo objcopy -- -O ihex "pwm-fan-controller-{{ board }}.hex" } +alias fmt := format + +format: + treefmt + alias f := run alias flash := run alias r := run @@ -43,8 +46,21 @@ run board="attiny85" profile="dev" method="": (build board profile) } else if "{{ method }}" == "elf2uf2-rs" { ^elf2uf2-rs --deploy $"boards/{{ board }}/target/thumbv6m-none-eabi/($build_type)/pwm-fan-controller-pico" } else if "{{ method }}" == "probe-rs" { - ^probe-rs run --chip RP2040 --protocol swd $"boards/{{ board }}/target/thumbv6m-none-eabi/($build_type)/pwm-fan-controller-pico" + ^probe-rs run \ + --chip RP2040 \ + --protocol swd \ + $"boards/{{ board }}/target/thumbv6m-none-eabi/($build_type)/pwm-fan-controller-pico" } + } else if "{{ board }}" == "qt-py-ch32v203" { + let build_type = { + if "{{ profile }}" == "dev" { + "debug" + } else { + "{{ profile }}" + } + } + ^wchisp flash \ + $"boards/{{ board }}target/riscvimac-unknown-none-elf/($build_type)/pwm-fan-controller-qt-py-ch32v203" } alias p := package @@ -53,8 +69,13 @@ alias pack := package package board="attiny85": ^nix build ".#pwm-fan-controller-{{ board }}" +alias t := test + +test: + nu update-nix-direnv-tests.nu + alias u := update -alias up := package +alias up := update update: ^nix flake update @@ -62,7 +83,6 @@ update: ^cargo update cd "{{ justfile_directory() }}/boards/pico" ^cargo update - -strip-image-metadata: - #!/usr/bin/env nu - check-image-metadata --strip + cd "{{ justfile_directory() }}/boards/qt-py-ch32v203" + ^cargo update + nu update-nix-direnv.nu diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index eb80a92..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,76 +0,0 @@ -exclude: | - (?x)^( - .idea/.*| - .run/.*| - .vscode/.* - )$ -repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 - hooks: - - id: check-byte-order-marker - - id: check-executables-have-shebangs - - id: check-json - - id: check-merge-conflict - - id: check-toml - - id: check-yaml - args: [--allow-multiple-documents] - - id: end-of-file-fixer - - id: mixed-line-ending - - id: pretty-format-json - args: ["--autofix"] - exclude: ^.vscode/.*\.json$ - - id: trailing-whitespace - - repo: local - hooks: - - id: just - entry: nix develop --command just --fmt --unstable - files: | - (?x)^( - \.justfile| - justfile| - .*\.just - )$ - language: system - name: just - pass_filenames: false - - id: mogrify-strip - entry: nix develop --command nu check-image-metadata.nu --strip - language: system - name: Strip Image Metadata - types: [binary, file, image] - - id: rustfmt - name: rustfmt - description: Format Rust files with rustfmt. - entry: nix develop --command rustfmt - language: system - types: [file, rust] - - id: test-check-image-metadata - entry: nix develop --command nu check-image-metadata-tests.nu - files: | - (?x)^( - check-image-metadata\.nu - check-image-metadata-tests\.nu - )$ - language: system - name: test check-image-metadata.nu - pass_filenames: false - # - id: rust-clippy-attiny85 - # name: Rust clippy ATtiny85 - # description: Run cargo clippy on files included in the commit. - # language: system - # entry: nix develop '.#attiny85' --command cargo clippy --all-targets --all-features --manifest-path boards/attiny85/Cargo.toml -- -Dclippy::all - # pass_filenames: false - # types: [file, rust] - # - id: rust-clippy-pico - # name: Rust clippy Pico - # description: Run cargo clippy on files included in the commit. - # entry: nix develop '.#pico' --command cargo clippy --all-targets --all-features --manifest-path boards/pico/Cargo.toml -- -Dclippy::all - # pass_filenames: false - # types: [file, rust] - # language: system - - id: yamllint - entry: nix develop --command yamllint - language: system - name: yamllint - types: [file, yaml] diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 6c07d9f..1e19215 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,5 +1,12 @@ { - "recommendations": [ - "probe-rs.probe-rs-debugger" - ] + "recommendations": [ + "probe-rs.probe-rs-debugger", + "asciidoctor.asciidoctor-vscode", + "mkhl.direnv", + "tamasfe.even-better-toml", + "bbenoist.nix", + "rust-lang.rust-analyzer", + "ibecker.treefmt-vscode", + "nefrob.vscode-just-syntax" + ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 8e89d2d..a23250b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,63 +1,64 @@ { - "cSpell.words": [ - "Adafruit", - "adoc", - "AHCT", - "Asciidoctor", - "assumeyes", - "attiny", - "autofix", - "avrdude", - "binutils", - "BOOTSEL", - "Boxall", - "clippy", - "CMSIS", - "Datasheet", - "Dclippy", - "devel", - "dialout", - "direnv", - "eabi", - "getent", - "hidraw", - "ifdef", - "ifndef", - "ihex", - "justfile", - "Libc", - "libusbx", - "microcontroller", - "microcontrollers", - "Micropython", - "mogrify", - "MOSI", - "Noctua", - "Nushell", - "objcopy", - "ostree", - "Perma", - "Pico", - "picoprobe", - "Pinout", - "Pinouts", - "proto", - "Protoboard", - "rustc", - "rustfmt", - "rustup", - "SWCLK", - "SWDIO", - "thumbv", - "tinyusb", - "tlsv", - "uaccess", - "UART", - "udev", - "udisksctl", - "usermod", - "VBUS", - "wchisp" - ], - "asciidoc.antora.enableAntoraSupport": false + "cSpell.words": [ + "Adafruit", + "adoc", + "AHCT", + "Asciidoctor", + "assumeyes", + "attiny", + "autofix", + "avrdude", + "binutils", + "BOOTSEL", + "Boxall", + "clippy", + "CMSIS", + "Datasheet", + "Dclippy", + "devel", + "dialout", + "direnv", + "eabi", + "getent", + "hidraw", + "ifdef", + "ifndef", + "ihex", + "justfile", + "Libc", + "libusbx", + "microcontroller", + "microcontrollers", + "Micropython", + "mogrify", + "MOSI", + "Noctua", + "Nushell", + "objcopy", + "ostree", + "Perma", + "Pico", + "picoprobe", + "Pinout", + "Pinouts", + "proto", + "Protoboard", + "rustc", + "rustfmt", + "rustup", + "SWCLK", + "SWDIO", + "thumbv", + "tinyusb", + "tlsv", + "uaccess", + "UART", + "udev", + "udisksctl", + "usermod", + "VBUS", + "wchisp" + ], + "nix.enableLanguageServer": true, + "nix.serverPath": "nil" } diff --git a/.yamlfmt.yaml b/.yamlfmt.yaml new file mode 100644 index 0000000..0d7c56d --- /dev/null +++ b/.yamlfmt.yaml @@ -0,0 +1,3 @@ +formatter: + type: basic + retain_line_breaks_single: true diff --git a/.yamllint.yaml b/.yamllint.yaml index d214411..7818ce5 100644 --- a/.yamllint.yaml +++ b/.yamllint.yaml @@ -4,3 +4,5 @@ rules: document-start: disable document-end: disable line-length: disable + comments: + min-spaces-from-content: 1 diff --git a/README.adoc b/README.adoc index a091034..d753162 100644 --- a/README.adoc +++ b/README.adoc @@ -59,7 +59,7 @@ This makes it possible to develop locally in an environment that is consistent w The `nix develop` command can be used to enter or run commands in an environment with all of the necessary dependencies. For convenience, direnv can be used to automatically load this environment when entering the project's directory. The https://marketplace.visualstudio.com/items?itemName=mkhl.direnv[mkhl.direnv VSCode extension] integrates this environment in VSCode for development. -The repository contains configuration for https://pre-commit.com/[pre-commit], which can be used to automate formatting and various checks when committing changes. +Nix also generates the configuration for https://pre-commit.com/[pre-commit], which automates formatting and various checks when committing changes. Follow the instructions here to set up your development environment. . Install an implementation of {Nix}, such as https://lix.systems[Lix] used here. diff --git a/boards/attiny85/Cargo.toml b/boards/attiny85/Cargo.toml index a54cb35..134b650 100644 --- a/boards/attiny85/Cargo.toml +++ b/boards/attiny85/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/jwillikers/pwm-fan-controller.git" [dependencies] -embedded-hal ="1.0.0" +embedded-hal = "1.0.0" nb = "1.1.0" panic-halt = "0.2.0" ufmt = "0.2.0" diff --git a/boards/attiny85/README.adoc b/boards/attiny85/README.adoc index 02fb647..898af90 100644 --- a/boards/attiny85/README.adoc +++ b/boards/attiny85/README.adoc @@ -195,7 +195,7 @@ nix run '../..#attiny85.flash.avrdude' == Contributing Contributions in the form of issues, feedback, and even pull requests are welcome. -Make sure to adhere to the project's link:../CODE_OF_CONDUCT.adoc[Code of Conduct]. +Make sure to adhere to the project's link:../../CODE_OF_CONDUCT.adoc[Code of Conduct]. == Open Source Software @@ -212,14 +212,14 @@ Several of these projects are enumerated below. == Code of Conduct -Refer to the project's link:../CODE_OF_CONDUCT.adoc[Code of Conduct] for details. +Refer to the project's link:../../CODE_OF_CONDUCT.adoc[Code of Conduct] for details. == License Licensed under either of -* Apache License, Version 2.0 (link:../LICENSE-APACHE[LICENSE-APACHE] or http://www.apache.org/licenses/LICENSE-2.0) -* MIT license (link:../LICENSE-MIT[LICENSE-MIT] or http://opensource.org/licenses/MIT) +* Apache License, Version 2.0 (link:../../LICENSE-APACHE[LICENSE-APACHE] or http://www.apache.org/licenses/LICENSE-2.0) +* MIT license (link:../../LICENSE-MIT[LICENSE-MIT] or http://opensource.org/licenses/MIT) at your option. diff --git a/boards/attiny85/default.nix b/boards/attiny85/default.nix index 741657f..1947ebd 100644 --- a/boards/attiny85/default.nix +++ b/boards/attiny85/default.nix @@ -1,10 +1,12 @@ { -craneLib -, cargoArtifacts -, commonArgs -, stdenv + cargoArtifacts, + commonArgs, + craneLib, + # deadnix: skip + stdenv, }: -craneLib.buildPackage commonArgs // { +craneLib.buildPackage commonArgs +// { inherit cargoArtifacts; version = "0.0.1"; diff --git a/boards/pico/.cargo/config.toml b/boards/pico/.cargo/config.toml index 8fea048..aa0d37f 100644 --- a/boards/pico/.cargo/config.toml +++ b/boards/pico/.cargo/config.toml @@ -9,17 +9,22 @@ runner = "probe-rs run --chip RP2040 --protocol swd" # runner = "elf2uf2-rs -d" rustflags = [ - "-C", "linker=flip-link", - "-C", "link-arg=--nmagic", - "-C", "link-arg=-Tlink.x", - "-C", "link-arg=-Tdefmt.x", + "-C", + "linker=flip-link", + "-C", + "link-arg=--nmagic", + "-C", + "link-arg=-Tlink.x", + "-C", + "link-arg=-Tdefmt.x", # Code-size optimizations. # trap unreachable can save a lot of space, but requires nightly compiler. # uncomment the next line if you wish to enable it # "-Z", "trap-unreachable=no", # "-C", "inline-threshold=5", - "-C", "no-vectorize-loops", + "-C", + "no-vectorize-loops", ] [build] diff --git a/boards/pico/Embed.toml b/boards/pico/Embed.toml index 83a4b6f..3e238d4 100644 --- a/boards/pico/Embed.toml +++ b/boards/pico/Embed.toml @@ -26,7 +26,7 @@ connect_under_reset = false enabled = true up_mode = "NoBlockSkip" channels = [ - { up = 0, down = 0, name = "name", up_mode = "NoBlockSkip", format = "Defmt" }, + { up = 0, down = 0, name = "name", up_mode = "NoBlockSkip", format = "Defmt" }, ] timeout = 3000 show_timestamps = true diff --git a/boards/pico/README.adoc b/boards/pico/README.adoc index f8de67e..3e6d539 100644 --- a/boards/pico/README.adoc +++ b/boards/pico/README.adoc @@ -218,7 +218,7 @@ curl --location --output-dir=/run/media/$USER/RPI-RP2 --remote-name \ == Contributing Contributions in the form of issues, feedback, and even pull requests are welcome. -Make sure to adhere to the project's link:../CODE_OF_CONDUCT.adoc[Code of Conduct]. +Make sure to adhere to the project's link:../../CODE_OF_CONDUCT.adoc[Code of Conduct]. == Open Source Software @@ -235,14 +235,14 @@ Several of these projects are enumerated below. == Code of Conduct -Refer to the project's link:../CODE_OF_CONDUCT.adoc[Code of Conduct] for details. +Refer to the project's link:../../CODE_OF_CONDUCT.adoc[Code of Conduct] for details. == License Licensed under either of -* Apache License, Version 2.0 (link:../LICENSE-APACHE[LICENSE-APACHE] or http://www.apache.org/licenses/LICENSE-2.0) -* MIT license (link:../LICENSE-MIT[LICENSE-MIT] or http://opensource.org/licenses/MIT) +* Apache License, Version 2.0 (link:../../LICENSE-APACHE[LICENSE-APACHE] or http://www.apache.org/licenses/LICENSE-2.0) +* MIT license (link:../../LICENSE-MIT[LICENSE-MIT] or http://opensource.org/licenses/MIT) at your option. diff --git a/boards/pico/default.nix b/boards/pico/default.nix index 7318b41..b6b38ad 100644 --- a/boards/pico/default.nix +++ b/boards/pico/default.nix @@ -1,36 +1,12 @@ { -craneLib -, pkgs -, lib -, stdenv + cargoArtifacts, + commonArgs, + craneLib, + # deadnix: skip + stdenv, }: -craneLib.buildPackage { - pname = "pwm-fan-controller-pico"; +craneLib.buildPackage commonArgs +// { + inherit cargoArtifacts; version = "0.0.1"; - - src = lib.cleanSourceWith { - src = ./.; - # Don't remove the memory.x linker script file from the sources. - filter = path: type: (craneLib.filterCargoSources path type) || (builtins.baseNameOf path == "memory.x"); - }; - - strictDeps = true; - doCheck = false; - - # Need to make the memory.x linker script available to the dummy crate. - # See https://github.com/ipetkov/crane/issues/444 - # Should I symlink instead of copy? - # ln --symbolic ${./memory.x} memory.x - CARGO_TARGET_THUMBV6M_NONE_EABI_RUSTFLAGS = "-C link-arg=--library-path=."; - extraDummyScript = '' - cp --archive ${./memory.x} $out/memory.x - rm --force --recursive $out/src/bin/crane-dummy-* - ''; - - nativeBuildInputs = [ - stdenv.cc - pkgs.flip-link - ]; - - cargoExtraArgs = "--target thumbv6m-none-eabi"; } diff --git a/boards/qt-py-ch32v203/.cargo/config.toml b/boards/qt-py-ch32v203/.cargo/config.toml index 31cdea8..7cd8ca5 100644 --- a/boards/qt-py-ch32v203/.cargo/config.toml +++ b/boards/qt-py-ch32v203/.cargo/config.toml @@ -3,8 +3,8 @@ target = "riscv32imac-unknown-none-elf" [target."riscv32imac-unknown-none-elf"] rustflags = [ -# "-C", "link-arg=-Tlink.x", -# "-C", "no-vectorize-loops", + # "-C", "link-arg=-Tlink.x", + # "-C", "no-vectorize-loops", ] # runner = "riscv64-unknown-elf-gdb -q -x openocd.gdb" # runner = "riscv-none-embed-gdb -q -x openocd.gdb" diff --git a/boards/qt-py-ch32v203/Cargo.toml b/boards/qt-py-ch32v203/Cargo.toml index 42e0dc7..d436b98 100644 --- a/boards/qt-py-ch32v203/Cargo.toml +++ b/boards/qt-py-ch32v203/Cargo.toml @@ -11,13 +11,13 @@ repository = "https://github.com/jwillikers/pwm-fan-controller.git" [dependencies.ch32-hal] default-features = false features = [ - "ch32v203g8r6", - "embassy", - "rt", - # todo It doesn't seem to matter whether I choose timer 2 or 4 here. - # The PWM is attached to timer 4 though, in case it matters. - "time-driver-tim4", - # "time-driver-tim2", + "ch32v203g8r6", + "embassy", + "rt", + # todo It doesn't seem to matter whether I choose timer 2 or 4 here. + # The PWM is attached to timer 4 though, in case it matters. + "time-driver-tim4", + # "time-driver-tim2", ] git = "https://github.com/ch32-rs/ch32-hal.git" @@ -36,4 +36,4 @@ strip = false [profile.release] lto = true opt-level = "z" # Optimize for size. -strip = false # symbols are not flashed to the microcontroller, so don't strip them. +strip = false # symbols are not flashed to the microcontroller, so don't strip them. diff --git a/boards/qt-py-ch32v203/README.adoc b/boards/qt-py-ch32v203/README.adoc index 1f38aea..cd2117e 100644 --- a/boards/qt-py-ch32v203/README.adoc +++ b/boards/qt-py-ch32v203/README.adoc @@ -122,7 +122,7 @@ nix run '../..#qt-py-ch32v203.flash.wchisp' == Contributing Contributions in the form of issues, feedback, and even pull requests are welcome. -Make sure to adhere to the project's link:../CODE_OF_CONDUCT.adoc[Code of Conduct]. +Make sure to adhere to the project's link:../../CODE_OF_CONDUCT.adoc[Code of Conduct]. == Open Source Software @@ -137,14 +137,14 @@ Several of these projects are enumerated below. == Code of Conduct -Refer to the project's link:../CODE_OF_CONDUCT.adoc[Code of Conduct] for details. +Refer to the project's link:../../CODE_OF_CONDUCT.adoc[Code of Conduct] for details. == License Licensed under either of -* Apache License, Version 2.0 (link:../LICENSE-APACHE[LICENSE-APACHE] or http://www.apache.org/licenses/LICENSE-2.0) -* MIT license (link:../LICENSE-MIT[LICENSE-MIT] or http://opensource.org/licenses/MIT) +* Apache License, Version 2.0 (link:../../LICENSE-APACHE[LICENSE-APACHE] or http://www.apache.org/licenses/LICENSE-2.0) +* MIT license (link:../../LICENSE-MIT[LICENSE-MIT] or http://opensource.org/licenses/MIT) at your option. diff --git a/boards/qt-py-ch32v203/default.nix b/boards/qt-py-ch32v203/default.nix index 5a4e5e9..b6b38ad 100644 --- a/boards/qt-py-ch32v203/default.nix +++ b/boards/qt-py-ch32v203/default.nix @@ -1,76 +1,12 @@ { -craneLib -, pkgs -, lib -, stdenv + cargoArtifacts, + commonArgs, + craneLib, + # deadnix: skip + stdenv, }: -craneLib.buildPackage { - pname = "pwm-fan-controller-qt-py-ch32v203"; +craneLib.buildPackage commonArgs +// { + inherit cargoArtifacts; version = "0.0.1"; - - src = lib.cleanSourceWith { - src = ./.; - # Don't remove the memory.x linker script file from the sources. - filter = path: type: (craneLib.filterCargoSources path type) || (builtins.baseNameOf path == "memory.x"); - }; - - strictDeps = true; - doCheck = false; - - # Need to make the memory.x linker script available to the dummy crate. - # See https://github.com/ipetkov/crane/issues/444 - # Should I symlink instead of copy? - # ln --symbolic ${./memory.x} memory.x - CARGO_TARGET_RISCV32IMAC_UNKNOWN_NONE_ELF_RUSTFLAGS = "-C link-arg=--library-path=."; - extraDummyScript = '' - cp --archive ${./memory.x} $out/memory.x - rm --force --recursive $out/src/bin/crane-dummy-* - ''; - - # Build-time tools which are target agnostic. build = host = target = your-machine. - # Emulators should essentially also go `nativeBuildInputs`. But with some packaging issue, - # currently it would cause some rebuild. - # We put them here just for a workaround. - # See: https://github.com/NixOS/nixpkgs/pull/146583 - depsBuildBuild = [ - ]; - - # Dependencies which need to be build for the current platform - # on which we are doing the cross compilation. In this case, - # pkg-config needs to run on the build platform so that the build - # script can find the location of openssl. Note that we don't - # need to specify the rustToolchain here since it was already - # overridden above. - nativeBuildInputs = [ - stdenv.cc - ]; - - # Dependencies which need to be built for the platform on which - # the binary will run. In this case, we need to compile openssl - # so that it can be linked with our executable. - # buildInputs = [ - # # Add additional build inputs here - # openssl - # ]; - - # Tell cargo about the linker and an optional emulater. So they can be used in `cargo build` - # and `cargo run`. - # Environment variables are in format `CARGO_TARGET__LINKER`. - # They are also be set in `.cargo/config.toml` instead. - # See: https://doc.rust-lang.org/cargo/reference/config.html#target - # CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = "${stdenv.cc.targetPrefix}cc"; - # CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER = "qemu-aarch64"; - - # Tell cargo which target we want to build (so it doesn't default to the build system). - # We can either set a cargo flag explicitly with a flag or with an environment variable. - cargoExtraArgs = "--target riscv32imac-unknown-none-elf"; - # CARGO_BUILD_TARGET = "riscv32imac-unknown-none-elf"; - - # These environment variables may be necessary if any of your dependencies use a - # build-script which invokes the `cc` crate to build some other code. The `cc` crate - # should automatically pick up on our target-specific linker above, but this may be - # necessary if the build script needs to compile and run some extra code on the build - # system. - # HOST_CC = "${stdenv.cc.nativePrefix}cc"; - # TARGET_CC = "${stdenv.cc.targetPrefix}cc"; } diff --git a/check-image-metadata-tests.nu b/check-image-metadata-tests.nu deleted file mode 100755 index 4c27c2b..0000000 --- a/check-image-metadata-tests.nu +++ /dev/null @@ -1,246 +0,0 @@ -#!/usr/bin/env nu -use check-image-metadata.nu contains_geolocation_metadata - -use std assert - -def test_contains_geolocation_metadata [] { - for t in [ - [input expected]; - [' -Image: - Filename: /home/jdoe/Pictures/picture.jpg - Permissions: rw-r--r-- - Format: JPEG (Joint Photographic Experts Group JFIF format) - Mime type: image/jpeg - Class: DirectClass - Geometry: 4032x3024+0+0 - Units: Undefined - Colorspace: sRGB - Type: TrueColor - Base type: Undefined - Endianness: Undefined - Depth: 8-bit - Channels: 3.0 - Channel depth: - Red: 8-bit - Green: 8-bit - Blue: 8-bit - Channel statistics: - Pixels: 12192768 - Red: - min: 0 (0) - max: 255 (1) - mean: 133.213 (0.522404) - median: 140 (0.54902) - standard deviation: 31.6085 (0.123955) - kurtosis: 6.25607 - skewness: -2.37688 - entropy: 0.788975 - Green: - min: 0 (0) - max: 255 (1) - mean: 125.504 (0.492172) - median: 130 (0.509804) - standard deviation: 32.9402 (0.129177) - kurtosis: 3.19772 - skewness: -1.42089 - entropy: 0.840793 - Blue: - min: 0 (0) - max: 255 (1) - mean: 114.747 (0.449989) - median: 114 (0.447059) - standard deviation: 37.7443 (0.148017) - kurtosis: 1.33805 - skewness: 0.112212 - entropy: 0.895613 - Image statistics: - Overall: - min: 0 (0) - max: 255 (1) - mean: 124.488 (0.488188) - median: 128 (0.501961) - standard deviation: 34.0977 (0.133716) - kurtosis: 3.59728 - skewness: -1.22852 - entropy: 0.841794 - Rendering intent: Perceptual - Gamma: 0.454545 - Chromaticity: - red primary: (0.64,0.33,0.03) - green primary: (0.3,0.6,0.1) - blue primary: (0.15,0.06,0.79) - white point: (0.3127,0.329,0.3583) - Matte color: grey74 - Background color: white - Border color: srgb(223,223,223) - Transparent color: black - Interlace: None - Intensity: Undefined - Compose: Over - Page geometry: 4032x3024+0+0 - Dispose: Undefined - Iterations: 0 - Compression: JPEG - Quality: 100 - Orientation: TopLeft - Profiles: - Profile-exif: 754 bytes - Profile-icc: 596 bytes - Properties: - exif:DateTime: 2019:10:04 14:21:48 - exif:DateTimeDigitized: 2019:10:04 14:21:48 - exif:DateTimeOriginal: 2019:10:04 14:21:48 - exif:ExifOffset: 146 - exif:ExifVersion: 0220 - exif:ExposureTime: 16661248/1000000000 - exif:Flash: 0 - exif:FNumber: 18900/10000 - exif:FocalLength: 54300/10000 - exif:GPSAltitude: 4400000/10000 - exif:GPSAltitudeRef: . - exif:GPSDateStamp: 2019:10:04 - exif:GPSInfo: 473 - exif:GPSLatitude: 77/1,50/1,477240000/10000000 - exif:GPSLatitudeRef: N - exif:GPSLongitude: 113/1,31/1,148080000/10000000 - exif:GPSLongitudeRef: E - exif:GPSProcessingMethod: gps - exif:GPSSpeed: 1/10000 - exif:GPSSpeedRef: K - exif:GPSTimeStamp: 10/1,10/1,53/1 - exif:ImageLength: 3024 - exif:ImageWidth: 4032 - exif:LightSource: 0 - exif:Make: Google - exif:Model: Pixel 7a - exif:OffsetTime: -5:00 - exif:OffsetTimeDigitized: -05:00 - exif:OffsetTimeOriginal: -5:00 - exif:PhotographicSensitivity: 92 - exif:PixelXDimension: 4032 - exif:PixelYDimension: 3024 - exif:SubSecTime: 715440 - exif:SubSecTimeDigitized: 715440 - exif:SubSecTimeOriginal: 715440 - exif:WhiteBalance: 0 - icc:copyright: Copyright (c) 2016 Google Inc. - icc:description: sRGB IEC61966-2.1 - jpeg:colorspace: 2 - jpeg:sampling-factor: 2x2,1x1,1x1 - signature: e2da0048c346c64b1027570a52ed107a7e2d8ba8948bdc3e1abb732eae876936 - Artifacts: - verbose: true - Tainted: False - Filesize: 5.61776MiB - Number pixels: 12.1928M - Pixel cache type: Memory - Pixels per second: 64.6839MP - User time: 0.190u - Elapsed time: 0:01.188 - Version: ImageMagick 7.1.1-38 Q16-HDRI x86_64 878daf986:20240901 https://imagemagick.org - ' true] - [' -Image: - Filename: qt-py-ch32v203-pwm-fan-controller-breadboard-side-1.jpg - Permissions: rw-r--r-- - Format: JPEG (Joint Photographic Experts Group JFIF format) - Mime type: image/jpeg - Class: DirectClass - Geometry: 3749x1899+0+0 - Resolution: 72x72 - Print size: 52.0694x26.375 - Units: PixelsPerInch - Colorspace: sRGB - Type: TrueColor - Base type: Undefined - Endianness: Undefined - Depth: 8-bit - Channels: 3.0 - Channel depth: - Red: 8-bit - Green: 8-bit - Blue: 8-bit - Channel statistics: - Pixels: 7119351 - Red: - min: 0 (0) - max: 255 (1) - mean: 149.173 (0.584994) - median: 162 (0.635294) - standard deviation: 42.0394 (0.16486) - kurtosis: 1.97136 - skewness: -1.53147 - entropy: 0.87033 - Green: - min: 0 (0) - max: 255 (1) - mean: 148.68 (0.583058) - median: 162 (0.635294) - standard deviation: 46.0756 (0.180689) - kurtosis: 0.653392 - skewness: -0.94745 - entropy: 0.907808 - Blue: - min: 0 (0) - max: 255 (1) - mean: 147.479 (0.578349) - median: 152 (0.596078) - standard deviation: 60.0636 (0.235543) - kurtosis: -0.834978 - skewness: -0.32204 - entropy: 0.971006 - Image statistics: - Overall: - min: 0 (0) - max: 255 (1) - mean: 148.444 (0.582133) - median: 158.667 (0.622222) - standard deviation: 49.3928 (0.193697) - kurtosis: 0.596592 - skewness: -0.933654 - entropy: 0.916381 - Rendering intent: Perceptual - Gamma: 0.454545 - Chromaticity: - red primary: (0.64,0.33,0.03) - green primary: (0.3,0.6,0.1) - blue primary: (0.15,0.06,0.79) - white point: (0.3127,0.329,0.3583) - Matte color: grey74 - Background color: white - Border color: srgb(223,223,223) - Transparent color: black - Interlace: None - Intensity: Undefined - Compose: Over - Page geometry: 3749x1899+0+0 - Dispose: Undefined - Iterations: 0 - Compression: JPEG - Quality: 100 - Orientation: Undefined - Properties: - jpeg:colorspace: 2 - jpeg:sampling-factor: 2x2,1x1,1x1 - signature: 8bf704578aa37fbb3c2425a55ad0c989779a584551aa603286a4504f23ecccad - Artifacts: - verbose: true - Tainted: False - Filesize: 3.27405MiB - Number pixels: 7.11935M - Pixel cache type: Memory - Pixels per second: 65.2504MP - User time: 0.110u - Elapsed time: 0:01.109 - Version: ImageMagick 7.1.1-38 Q16-HDRI x86_64 878daf986:20240901 https://imagemagick.org - ' false] - ] { - assert equal ($t.input | contains_geolocation_metadata) $t.expected - } -} - -def main [] [] { - test_contains_geolocation_metadata - echo "All tests passed!" -} diff --git a/check-image-metadata.nu b/check-image-metadata.nu deleted file mode 100755 index 8801485..0000000 --- a/check-image-metadata.nu +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env nu -use std log - -# Some common image file extensions. -const image_file_extensions = [ - gif - jpg - jpeg - png - webp -] - -# Determine if the given file is an image. -def is-image [] [path -> bool] { - ^file --brief --mime-type $in | str starts-with "image/" -} - -# A wrapper around the magick identify command. -def "magick identify" [] [path -> string] { - let file = $in - let result = (^magick identify -verbose $file | complete) - if $result.exit_code != 0 { - log warning $"The 'magick identify -verbose' command failed on the image file '($file)' with exit code ($result.exit_code): ($result.stderr)" - return null - } - return $result.stdout -} - -# Check if the output from the 'magick identify -verbose' command contains geolocation metadata with ImageMagick. -export def contains_geolocation_metadata [] [string -> bool] { - $in | str contains "exif:GPS" -} - -# Find if any image files which contain geolocation metadata and report an error if any do. -# -# When given no files, it checks all files that use common image file extensions. -def main [ - ...files: path - --strip -] { - let images = ( - if ($files | is-empty) { - $image_file_extensions | par-each {|image_file_extension| - glob $"**/*.($image_file_extension)" - } | flatten - } else { - $files | filter {|file| $file | is-image} - } - ) - log debug $"images: ($images)" - - let images_with_geolocation_metdata = ( - $images | filter {|image| $image | magick identify | contains_geolocation_metadata} - ) - - if ($images_with_geolocation_metdata | is-empty) { - exit 0 - } - - ( - $images_with_geolocation_metdata | par-each { - let image = $in - if $strip { - ^mogrify -strip $image - log info $"Stripped metadata from the image '($image)'." - } else { - log error $"Image '($image)' contains geolocation metadata." - } - } - ) - - if $strip { - exit 0 - } - - exit 1 -} diff --git a/flake.lock b/flake.lock index 163fb9d..cecef70 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "advisory-db": { + "flake": false, + "locked": { + "lastModified": 1727881133, + "narHash": "sha256-nnfwJjLA0uVIBgrGNYt9ButjBQFyj/I6MohQUHhJ78A=", + "owner": "rustsec", + "repo": "advisory-db", + "rev": "a68ca4a1ec3950da7c82c522e8cfc424e28ca7f0", + "type": "github" + }, + "original": { + "owner": "rustsec", + "repo": "advisory-db", + "type": "github" + } + }, "crane": { "locked": { "lastModified": 1727974419, @@ -15,6 +31,22 @@ "type": "github" } }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -33,28 +65,107 @@ "type": "github" } }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1728047338, - "narHash": "sha256-5QLjMly/QoR/vETzO8kt6Rz6Np2hEAPeUXWEofcPR2s=", + "lastModified": 1728241625, + "narHash": "sha256-yumd4fBc/hi8a9QgA9IT8vlQuLZ2oqhkJXHPKxH/tRw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c31898adf5a8ed202ce5bea9f347b1c6871f32d1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "1a8a13a27e2f9abba88064af913d83ad647256f4", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", "type": "github" }, "original": { "owner": "NixOS", - "ref": "master", + "ref": "nixos-24.05", "repo": "nixpkgs", "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1726871744, + "narHash": "sha256-V5LpfdHyQkUF7RfOaDPrZDP+oqz88lTJrMT1+stXNwo=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a1d92660c6b3b7c26fb883500a80ea9d33321be2", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1728092656, + "narHash": "sha256-eMeCTJZ5xBeQ0f9Os7K8DThNVSo9gy4umZLDfF5q6OM=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "1211305a5b237771e13fcca0c51e60ad47326a9a", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { + "advisory-db": "advisory-db", "crane": "crane", "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" + "pre-commit-hooks": "pre-commit-hooks", + "rust-overlay": "rust-overlay", + "treefmt-nix": "treefmt-nix" } }, "rust-overlay": { @@ -91,6 +202,24 @@ "repo": "default", "type": "github" } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1727984844, + "narHash": "sha256-xpRqITAoD8rHlXQafYZOLvUXCF6cnZkPfoq67ThN0Hc=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "4446c7a6fc0775df028c5a3f6727945ba8400e64", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index a4ae2fe..3c0faeb 100644 --- a/flake.nix +++ b/flake.nix @@ -1,246 +1,559 @@ { inputs = { - # nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - nixpkgs.url = "github:NixOS/nixpkgs/master"; + advisory-db = { + flake = false; + url = "github:rustsec/advisory-db"; + }; crane.url = "github:ipetkov/crane"; flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs = { + nixpkgs.follows = "nixpkgs"; + }; + }; rust-overlay = { - url = "github:oxalica/rust-overlay"; inputs = { nixpkgs.follows = "nixpkgs"; }; + url = "github:oxalica/rust-overlay"; }; + treefmt-nix.url = "github:numtide/treefmt-nix"; }; - outputs = { self, nixpkgs, crane, flake-utils, rust-overlay }: - flake-utils.lib.eachDefaultSystem - (system: - let - overlays = [ (import rust-overlay) ]; - pkgs = import nixpkgs { - inherit overlays system; + outputs = + { + # deadnix: skip + self, + advisory-db, + crane, + flake-utils, + nixpkgs, + pre-commit-hooks, + rust-overlay, + treefmt-nix, + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit overlays system; + }; + commonNativeBuildInputs = with pkgs; [ + asciidoctor + clippy + fish + just + lychee + nil + nushell + ]; + treefmt.config = { + programs = { + actionlint.enable = true; + jsonfmt.enable = true; + just.enable = true; + nixfmt.enable = true; + rustfmt.enable = true; + statix.enable = true; + taplo.enable = true; + typos.enable = true; + yamlfmt.enable = true; }; - commonNativeBuildInputs = with pkgs; [ - clippy - fish - imagemagick_light # To strip metadata from images. - just - nushell - pre-commit - rustfmt - yamllint + projectRootFile = "flake.nix"; + settings.formatter.typos.excludes = [ + "*.avif" + "*.bmp" + "*.gif" + "*.jpeg" + "*.jpg" + "*.png" + "*.svg" + "*.tiff" + "*.webp" + ".vscode/settings.json" ]; - boards = { - attiny85 = { - # The development shell requires the GCC AVR toolchain to be available. - # Thus, this cross-compilation configuration here does the trick. - avrCrossPkgs = import nixpkgs { - inherit overlays system; - config.allowUnsupportedSystem = true; - crossSystem = { - inherit overlays; - config = "avr"; - # todo Configure Rust for the proper cross-compilation target when that can be done for target without std. - # Perhaps once AVR is stabalized for Rust this will be possible? - # rust.rustcTarget = "avr-unknown-none-attiny85"; - # rust.platform = nixpkgs.lib.importJSON "${./boards/attiny85/avr-unknown-none-attiny85.json}"; - # rustc = { - # config = "avr-unknown-none-attiny85"; - # platform = nixpkgs.lib.importJSON "${./boards/attiny85/avr-unknown-none-attiny85.json}"; - # }; - }; + }; + treefmtEval = treefmt-nix.lib.evalModule pkgs treefmt.config; + pre-commit = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + check-added-large-files.enable = true; + check-builtin-literals.enable = true; + check-case-conflicts.enable = true; + check-executables-have-shebangs.enable = true; + + # todo Not integrated with Nix? + check-format = { + enable = true; + entry = "${treefmtEval.config.build.wrapper}/bin/treefmt --fail-on-change"; + }; + + check-json.enable = true; + check-shebang-scripts-are-executable.enable = true; + check-toml.enable = true; + check-yaml.enable = true; + # todo Is it possible to support clippy as a pre-commit hook for a workspace project like this? + # clippy.enable = true; + deadnix.enable = true; + detect-private-keys.enable = true; + editorconfig-checker.enable = true; + end-of-file-fixer.enable = true; + fix-byte-order-marker.enable = true; + flake-checker.enable = true; + forbid-new-submodules.enable = true; + # todo Enable lychee when asciidoc is supported. + # See https://github.com/lycheeverse/lychee/issues/291 + # lychee.enable = true; + mixed-line-endings.enable = true; + nil.enable = true; + + strip-location-metadata = { + name = "Strip location metadata"; + description = "Strip geolocation metadata from image files"; + enable = true; + entry = "${pkgs.exiftool}/bin/exiftool -duplicates -overwrite_original '-gps*='"; + package = pkgs.exiftool; + types = [ "image" ]; + }; + trim-trailing-whitespace.enable = true; + yamllint.enable = true; + }; + }; + boards = { + attiny85 = { + # The development shell requires the GCC AVR toolchain to be available. + # Thus, this cross-compilation configuration here does the trick. + avrCrossPkgs = import nixpkgs { + inherit overlays system; + config.allowUnsupportedSystem = true; + crossSystem = { + inherit overlays; + config = "avr"; + # todo Configure Rust for the proper cross-compilation target when that can be done for target without std. + # Perhaps once AVR is stabilized for Rust this will be possible? + # rust.rustcTarget = "avr-unknown-none-attiny85"; + # rust.platform = nixpkgs.lib.importJSON "${./boards/attiny85/avr-unknown-none-attiny85.json}"; + # rustc = { + # config = "avr-unknown-none-attiny85"; + # platform = nixpkgs.lib.importJSON "${./boards/attiny85/avr-unknown-none-attiny85.json}"; + # }; }; - rustToolchainFor = p: (p.rust-bin.fromRustupToolchainFile ./boards/attiny85/rust-toolchain.toml).override { + }; + rustToolchainFor = + p: + (p.rust-bin.fromRustupToolchainFile ./boards/attiny85/rust-toolchain.toml).override { # Remove the avr-unknown-none-attiny85.json file from the list of targets for the Rust toolchain. # Nix doesn't really support target JSON files specified in the toolchain and even if it did, it won't be ablet to build a toolchain for AVR. # The AVR toolchain is unstable and does not include std. targets = [ p.stdenv.hostPlatform.rust.rustcTarget ]; }; - rustToolchain = boards.attiny85.rustToolchainFor pkgs; + rustToolchain = boards.attiny85.rustToolchainFor pkgs; - craneLib = (crane.mkLib pkgs).overrideToolchain boards.attiny85.rustToolchainFor; - nativeBuildInputs = with pkgs; [ + craneLib = (crane.mkLib pkgs).overrideToolchain boards.attiny85.rustToolchainFor; + nativeBuildInputs = + with pkgs; + [ avrdude boards.attiny85.avrCrossPkgs.avrlibc boards.attiny85.avrCrossPkgs.buildPackages.binutils boards.attiny85.avrCrossPkgs.buildPackages.gcc cargo-binutils # ravedude - ] ++ commonNativeBuildInputs; - - # Common arguments can be set here to avoid repeating them later - commonArgs = { - pname = "pwm-fan-controller-attiny85"; - strictDeps = true; - doCheck = false; - - src = pkgs.lib.cleanSourceWith { - src = ./boards/attiny85; - # Don't remove the avr-unknown-none-attiny85.json file from the sources. - # See https://github.com/ipetkov/crane/issues/444 - filter = path: type: (boards.attiny85.craneLib.filterCargoSources path type) || (builtins.baseNameOf path == "avr-unknown-none-attiny85.json"); - }; + ] + ++ commonNativeBuildInputs; - cargoVendorDir = boards.attiny85.craneLib.vendorMultipleCargoDeps { - inherit (boards.attiny85.craneLib.findCargoFiles boards.attiny85.commonArgs.src) cargoConfigs; - cargoLockList = [ - ./boards/attiny85/Cargo.lock - - # Unfortunately this approach requires IFD (import-from-derivation) - # otherwise Nix will refuse to read the Cargo.lock from our toolchain - # (unless we build with `--impure`). - # - # Another way around this is to manually copy the rustlib `Cargo.lock` - # to the repo and import it with `./path/to/rustlib/Cargo.lock` which - # will avoid IFD entirely but will require manually keeping the file - # up to date! - "${boards.attiny85.rustToolchain.passthru.availableComponents.rust-src}/lib/rustlib/src/rust/Cargo.lock" - ]; - }; - cargoExtraArgs = "--target avr-unknown-none-attiny85.json -Z build-std=core"; - nativeBuildInputs = boards.attiny85.nativeBuildInputs; + commonArgs = { + pname = "pwm-fan-controller-attiny85"; + strictDeps = true; + doCheck = false; - extraDummyScript = '' - cp --archive ${./boards/attiny85/avr-unknown-none-attiny85.json} $out/avr-unknown-none-attiny85.json - rm --force --recursive $out/src/bin/crane-dummy-* - ''; + src = pkgs.lib.cleanSourceWith { + src = ./boards/attiny85; + # Don't remove the avr-unknown-none-attiny85.json file from the sources. + # See https://github.com/ipetkov/crane/issues/444 + filter = + path: type: + (boards.attiny85.craneLib.filterCargoSources path type) + || (builtins.baseNameOf path == "avr-unknown-none-attiny85.json"); }; - cargoArtifacts = boards.attiny85.craneLib.buildDepsOnly boards.attiny85.commonArgs; + cargoVendorDir = boards.attiny85.craneLib.vendorMultipleCargoDeps { + inherit (boards.attiny85.craneLib.findCargoFiles boards.attiny85.commonArgs.src) cargoConfigs; + cargoLockList = [ + ./boards/attiny85/Cargo.lock - pwm-fan-controller = pkgs.callPackage ./boards/attiny85/default.nix { - cargoArtifacts = boards.attiny85.cargoArtifacts; - commonArgs = boards.attiny85.commonArgs; - craneLib = boards.attiny85.craneLib; - stdenv = boards.attiny85.avrCrossPkgs.stdenv; + # Unfortunately this approach requires IFD (import-from-derivation) + # otherwise Nix will refuse to read the Cargo.lock from our toolchain + # (unless we build with `--impure`). + # + # Another way around this is to manually copy the rustlib `Cargo.lock` + # to the repo and import it with `./path/to/rustlib/Cargo.lock` which + # will avoid IFD entirely but will require manually keeping the file + # up to date! + "${boards.attiny85.rustToolchain.passthru.availableComponents.rust-src}/lib/rustlib/src/rust/Cargo.lock" + ]; }; - devShell = with boards.attiny85; craneLib.devShell { + cargoExtraArgs = "--target avr-unknown-none-attiny85.json -Z build-std=core"; + inherit (boards.attiny85) nativeBuildInputs; + + extraDummyScript = '' + cp --archive ${./boards/attiny85/avr-unknown-none-attiny85.json} $out/avr-unknown-none-attiny85.json + rm --force --recursive $out/src/bin/crane-dummy-* + ''; + }; + + cargoArtifacts = boards.attiny85.craneLib.buildDepsOnly boards.attiny85.commonArgs; + + pwm-fan-controller = pkgs.callPackage ./boards/attiny85/default.nix { + inherit (boards.attiny85) cargoArtifacts; + inherit (boards.attiny85) commonArgs; + inherit (boards.attiny85) craneLib; + inherit (boards.attiny85.avrCrossPkgs) stdenv; + }; + devShell = + with boards.attiny85; + craneLib.devShell { env = { # Required by rust-analyzer # todo Check if I actually need this. RUST_SRC_PATH = "${boards.attiny85.rustToolchain.passthru.availableComponents.rust-src}/lib/rustlib/src/rust/library"; }; - checks = self.checks.${system}; - packages = boards.attiny85.nativeBuildInputs; + packages = + boards.attiny85.nativeBuildInputs + ++ [ + treefmtEval.config.build.wrapper + # Make formatters available for IDE's. + (pkgs.lib.attrValues treefmtEval.config.build.programs) + ] + ++ pre-commit.enabledPackages; + inherit (pre-commit) shellHook; }; - apps = { - flash = { - avrdude = let + apps = { + flash = { + avrdude = + let script = pkgs.writeShellApplication { name = "flash-avrdude"; - runtimeInputs = with pkgs; [avrdude]; + runtimeInputs = with pkgs; [ avrdude ]; text = '' - ${pkgs.avrdude}/bin/avrdude -c USBtiny -B 4 -p attiny85 -U flash:w:${self.packages.${system}.pwm-fan-controller-attiny85}/bin/pwm-fan-controller-attiny85.hex:i + ${pkgs.avrdude}/bin/avrdude -c USBtiny -B 4 -p attiny85 -U flash:w:${ + self.packages.${system}.pwm-fan-controller-attiny85 + }/bin/pwm-fan-controller-attiny85.hex:i ''; }; - in { + in + { type = "app"; program = "${script}/bin/flash-avrdude"; }; - }; }; }; - pico = { - nativeBuildInputs = with pkgs; [ + }; + pico = { + nativeBuildInputs = + with pkgs; + [ elf2uf2-rs flip-link probe-rs - ] ++ commonNativeBuildInputs; - buildInputs = with pkgs; []; - craneLib = (crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.fromRustupToolchainFile ./boards/pico/rust-toolchain.toml); - pwm-fan-controller = pkgs.callPackage ./boards/pico/default.nix { - craneLib = boards.pico.craneLib; - }; - devShell = boards.pico.craneLib.devShell { - checks = self.checks.${system}; - packages = boards.pico.nativeBuildInputs; + ] + ++ commonNativeBuildInputs; + craneLib = (crane.mkLib pkgs).overrideToolchain ( + p: p.rust-bin.fromRustupToolchainFile ./boards/pico/rust-toolchain.toml + ); + + commonArgs = { + pname = "pwm-fan-controller-pico"; + strictDeps = true; + doCheck = false; + + src = pkgs.lib.cleanSourceWith { + src = ./boards/pico; + # Don't remove the memory.x linker script file from the sources. + filter = + path: type: + (boards.pico.craneLib.filterCargoSources path type) || (builtins.baseNameOf path == "memory.x"); }; - apps = { - flash = { - elf2uf2-rs = let + + # Need to make the memory.x linker script available to the dummy crate. + # See https://github.com/ipetkov/crane/issues/444 + # Should I symlink instead of copy? + # ln --symbolic ${./memory.x} memory.x + CARGO_TARGET_THUMBV6M_NONE_EABI_RUSTFLAGS = "-C link-arg=--library-path=."; + extraDummyScript = '' + cp --archive ${./boards/pico/memory.x} $out/memory.x + rm --force --recursive $out/src/bin/crane-dummy-* + ''; + + cargoExtraArgs = "--target thumbv6m-none-eabi"; + + nativeBuildInputs = with pkgs; [ + flip-link + ]; + }; + + cargoArtifacts = boards.pico.craneLib.buildDepsOnly boards.pico.commonArgs; + + pwm-fan-controller = pkgs.callPackage ./boards/pico/default.nix { + inherit (boards.pico) commonArgs; + inherit (boards.pico) cargoArtifacts; + inherit (boards.pico) craneLib; + }; + devShell = boards.pico.craneLib.devShell { + packages = + boards.pico.nativeBuildInputs + ++ [ + treefmtEval.config.build.wrapper + # Make formatters available for IDE's. + (pkgs.lib.attrValues treefmtEval.config.build.programs) + ] + ++ pre-commit.enabledPackages; + inherit (pre-commit) shellHook; + }; + apps = { + flash = { + elf2uf2-rs = + let script = pkgs.writeShellApplication { name = "flash-elf2uf2-rs"; - runtimeInputs = with pkgs; [elf2uf2-rs]; + runtimeInputs = with pkgs; [ elf2uf2-rs ]; text = '' - ${pkgs.elf2uf2-rs}/bin/elf2uf2-rs --deploy ${self.packages.${system}.pwm-fan-controller-pico}/bin/pwm-fan-controller-pico + ${pkgs.elf2uf2-rs}/bin/elf2uf2-rs --deploy ${ + self.packages.${system}.pwm-fan-controller-pico + }/bin/pwm-fan-controller-pico ''; }; - in { + in + { type = "app"; program = "${script}/bin/flash-elf2uf2-rs"; }; - }; - run = { - probe-rs = let + }; + run = { + probe-rs = + let script = pkgs.writeShellApplication { name = "run-probe-rs"; - runtimeInputs = with pkgs; [probe-rs]; + runtimeInputs = with pkgs; [ probe-rs ]; text = '' - ${pkgs.probe-rs}/bin/probe-rs run --chip RP2040 --protocol swd ${self.packages.${system}.pwm-fan-controller-pico}/bin/pwm-fan-controller-pico + ${pkgs.probe-rs}/bin/probe-rs run --chip RP2040 --protocol swd ${ + self.packages.${system}.pwm-fan-controller-pico + }/bin/pwm-fan-controller-pico ''; }; - in { + in + { type = "app"; program = "${script}/bin/run-probe-rs"; }; - }; }; }; - qt-py-ch32v203 = { - nativeBuildInputs = with pkgs; [ + }; + qt-py-ch32v203 = { + nativeBuildInputs = + with pkgs; + [ wchisp # probe-rs - ] ++ commonNativeBuildInputs; - buildInputs = with pkgs; []; - craneLib = (crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.fromRustupToolchainFile ./boards/qt-py-ch32v203/rust-toolchain.toml); - pwm-fan-controller = pkgs.callPackage ./boards/qt-py-ch32v203/default.nix { - craneLib = boards.qt-py-ch32v203.craneLib; - }; - devShell = boards.qt-py-ch32v203.craneLib.devShell { - packages = boards.qt-py-ch32v203.nativeBuildInputs; + ] + ++ commonNativeBuildInputs; + craneLib = (crane.mkLib pkgs).overrideToolchain ( + p: p.rust-bin.fromRustupToolchainFile ./boards/qt-py-ch32v203/rust-toolchain.toml + ); + + commonArgs = { + pname = "pwm-fan-controller-qt-py-ch32v203"; + strictDeps = true; + doCheck = false; + + src = pkgs.lib.cleanSourceWith { + src = ./boards/qt-py-ch32v203; + # Don't remove the memory.x linker script file from the sources. + filter = + path: type: + (boards.qt-py-ch32v203.craneLib.filterCargoSources path type) + || (builtins.baseNameOf path == "memory.x"); }; - apps = { - flash = { - wchisp = let + + # Need to make the memory.x linker script available to the dummy crate. + # See https://github.com/ipetkov/crane/issues/444 + # Should I symlink instead of copy? + # ln --symbolic ${./memory.x} memory.x + CARGO_TARGET_RISCV32IMAC_UNKNOWN_NONE_ELF_RUSTFLAGS = "-C link-arg=--library-path=."; + extraDummyScript = '' + cp --archive ${./boards/qt-py-ch32v203/memory.x} $out/memory.x + rm --force --recursive $out/src/bin/crane-dummy-* + ''; + + cargoExtraArgs = "--target riscv32imac-unknown-none-elf"; + }; + + cargoArtifacts = boards.qt-py-ch32v203.craneLib.buildDepsOnly boards.qt-py-ch32v203.commonArgs; + + pwm-fan-controller = pkgs.callPackage ./boards/qt-py-ch32v203/default.nix { + inherit (boards.qt-py-ch32v203) cargoArtifacts; + inherit (boards.qt-py-ch32v203) commonArgs; + inherit (boards.qt-py-ch32v203) craneLib; + }; + devShell = boards.qt-py-ch32v203.craneLib.devShell { + packages = + boards.qt-py-ch32v203.nativeBuildInputs + ++ [ + treefmtEval.config.build.wrapper + # Make formatters available for IDE's. + (pkgs.lib.attrValues treefmtEval.config.build.programs) + ] + ++ pre-commit.enabledPackages; + inherit (pre-commit) shellHook; + }; + apps = { + flash = { + wchisp = + let script = pkgs.writeShellApplication { name = "flash-wchisp"; - runtimeInputs = with pkgs; [wchisp]; + runtimeInputs = with pkgs; [ wchisp ]; text = '' - ${pkgs.wchisp}/bin/wchisp flash ${self.packages.${system}.pwm-fan-controller-qt-py-ch32v203}/bin/pwm-fan-controller-qt-py-ch32v203 + ${pkgs.wchisp}/bin/wchisp flash ${ + self.packages.${system}.pwm-fan-controller-qt-py-ch32v203 + }/bin/pwm-fan-controller-qt-py-ch32v203 ''; }; - in { + in + { type = "app"; program = "${script}/bin/flash-wchisp"; }; - }; }; }; }; - in - { - checks = { - inherit (boards.qt-py-ch32v203.pwm-fan-controller); + }; + in + { + apps = { + attiny85.flash.avrdude = boards.attiny85.apps.flash.avrdude; + default = self.apps.${system}.attiny85.flash.avrdude; + pico.flash.elf2uf2-rs = boards.pico.apps.flash.elf2uf2-rs; + pico.run.probe-rs = boards.pico.apps.run.probe-rs; + qt-py-ch32v203.flash.wchisp = boards.qt-py-ch32v203.apps.flash.wchisp; + }; + checks = { + attiny85-pwm-fan-controller = boards.attiny85.pwm-fan-controller; + pico-pwm-fan-controller = boards.pico.pwm-fan-controller; + qt-py-ch32v203-pwm-fan-controller = boards.qt-py-ch32v203.pwm-fan-controller; + + attiny85-clippy = boards.attiny85.craneLib.cargoClippy ( + boards.attiny85.commonArgs + // { + inherit (boards.attiny85) cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } + ); + pico-clippy = boards.pico.craneLib.cargoClippy ( + boards.pico.commonArgs + // { + inherit (boards.pico) cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } + ); + qt-py-ch32v203-clippy = boards.qt-py-ch32v203.craneLib.cargoClippy ( + boards.qt-py-ch32v203.commonArgs + // { + inherit (boards.qt-py-ch32v203) cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } + ); + + # attiny85.doc = craneLib.cargoDoc (boards.attiny85.commonArgs // { + # cargoArtifacts = boards.attiny85.cargoArtifacts; + # }); + # pico.doc = craneLib.cargoDoc (boards.pico.commonArgs // { + # cargoArtifacts = boards.pico.cargoArtifacts; + # }); + # qt-py-ch32v203.doc = craneLib.cargoDoc (boards.qt-py-ch32v203.commonArgs // { + # cargoArtifacts = boards.qt-py-ch32v203.cargoArtifacts; + # }); + + # attiny85.rustfmt = craneLib.cargoFmt { + # src = boards.attiny85.src; + # }; + # pico.rustfmt = craneLib.cargoFmt { + # src = boards.pico.src; + # }; + # qt-py-ch32v203.rustfmt = craneLib.cargoFmt { + # src = boards.qt-py-ch32v203.src; + # }; + + # attiny85.toml-fmt = craneLib.taploFmt { + # src = pkgs.lib.sources.sourceFilesBySuffices src [ ".toml" ]; + # # taplo arguments can be further customized below as needed + # # taploExtraArgs = "--config ./taplo.toml"; + # }; + + # Audit dependencies + attiny85-audit = boards.attiny85.craneLib.cargoAudit { + inherit advisory-db; + inherit (boards.attiny85.commonArgs) src; + }; + pico-audit = boards.pico.craneLib.cargoAudit { + inherit advisory-db; + inherit (boards.pico.commonArgs) src; + }; + qt-py-ch32v203-audit = boards.qt-py-ch32v203.craneLib.cargoAudit { + inherit advisory-db; + inherit (boards.qt-py-ch32v203.commonArgs) src; }; - packages = { - default = boards.attiny85.pwm-fan-controller; - pwm-fan-controller-attiny85 = boards.attiny85.pwm-fan-controller; - # todo Why can't it be pwm-fan-controller.pico? - pwm-fan-controller-pico = boards.pico.pwm-fan-controller; - pwm-fan-controller-qt-py-ch32v203 = boards.qt-py-ch32v203.pwm-fan-controller; + + # Audit licenses + attiny85-deny = boards.attiny85.craneLib.cargoDeny { + inherit (boards.attiny85.commonArgs) src; + }; + pico-deny = boards.pico.craneLib.cargoDeny { + inherit (boards.pico.commonArgs) src; }; - devShells = { - attiny85 = boards.attiny85.devShell; - default = boards.attiny85.devShell; - pico = boards.pico.devShell; - qt-py-ch32v203 = boards.qt-py-ch32v203.devShell; + qt-py-ch32v203-deny = boards.qt-py-ch32v203.craneLib.cargoDeny { + inherit (boards.qt-py-ch32v203.commonArgs) src; }; - apps = { - attiny85.flash.avrdude = boards.attiny85.apps.flash.avrdude; - default = boards.attiny85.apps.flash.avrdude; - pico.flash.elf2uf2-rs = boards.pico.apps.flash.elf2uf2-rs; - pico.run.probe-rs = boards.pico.apps.run.probe-rs; - qt-py-ch32v203.flash.wchisp = boards.qt-py-ch32v203.apps.flash.wchisp; + + # Run tests with cargo-nextest + # Consider setting `doCheck = false` on `my-crate` if you do not want + # the tests to run twice + # attiny85.nextest = craneLib.cargoNextest (boards.attiny85.commonArgs // { + # cargoArtifacts = boards.attiny85.cargoArtifacts; + # partitions = 1; + # partitionType = "count"; + # }); + }; + devShells = { + attiny85 = boards.attiny85.devShell; + default = pkgs.mkShell { + nativeBuildInputs = + commonNativeBuildInputs + ++ [ + treefmtEval.config.build.wrapper + # Make formatters available for IDE's. + (pkgs.lib.attrValues treefmtEval.config.build.programs) + ] + ++ pre-commit.enabledPackages; + inherit (pre-commit) shellHook; }; - } - ); + pico = boards.pico.devShell; + qt-py-ch32v203 = boards.qt-py-ch32v203.devShell; + }; + formatter = treefmtEval.config.build.wrapper; + packages = { + default = self.packages.${system}.pwm-fan-controller-attiny85; + pwm-fan-controller-attiny85 = boards.attiny85.pwm-fan-controller; + # todo Why can't it be pwm-fan-controller.pico? + pwm-fan-controller-pico = boards.pico.pwm-fan-controller; + pwm-fan-controller-qt-py-ch32v203 = boards.qt-py-ch32v203.pwm-fan-controller; + + # attiny85-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (boards.attiny85.commonArgs // { + # cargoArtifacts = boards.attiny85.cargoArtifacts; + # }); + }; + } + ); } diff --git a/lychee.toml b/lychee.toml new file mode 100644 index 0000000..4d451d4 --- /dev/null +++ b/lychee.toml @@ -0,0 +1,10 @@ +# Due to rate limiting from digikey.com and gnu.org +accept = [429] + +cache = true +exclude = [ + # Raspberry Pi's website returns 403 forbidden codes. + '^https://www.raspberrypi.com', +] +exclude_path = [".direnv/", "result/", "target/"] +max_cache_age = "2w" diff --git a/update-nix-direnv-tests.nu b/update-nix-direnv-tests.nu new file mode 100755 index 0000000..66e83f4 --- /dev/null +++ b/update-nix-direnv-tests.nu @@ -0,0 +1,29 @@ +#!/usr/bin/env nu +use update-nix-direnv.nu update_nix_direnv_in_envrc + +use std assert +use std log + +def test_update_nix_direnv_in_envrc [] { + for t in [ + [text version hash expected]; + [ +'if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM=" +fi + +use flake' "3.0.7" "TEsTJaRMf8oF5LznDrlCXbkOQrywm0IHv1VjYGaTesT=" +'if ! has nix_direnv_version || ! nix_direnv_version 3.0.7; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.7/direnvrc" "sha256-TEsTJaRMf8oF5LznDrlCXbkOQrywm0IHv1VjYGaTesT=" +fi + +use flake'] + ] { + assert equal ($t.text | update_nix_direnv_in_envrc $t.version $t.hash) $t.expected + } +} + +def main [] [] { + test_update_nix_direnv_in_envrc + echo "All tests passed!" +} diff --git a/update-nix-direnv.nu b/update-nix-direnv.nu new file mode 100755 index 0000000..f85b7b7 --- /dev/null +++ b/update-nix-direnv.nu @@ -0,0 +1,59 @@ +#!/usr/bin/env nu + +# https://github.com/nix-community/nix-direnv + +# Get the newest version of nix-direnv. +def get_latest_nix_direnv_version [] [ nothing -> string ] { + http get https://api.github.com/repos/nix-community/nix-direnv/releases/latest | get name +} + +# Get the SHA-256 hash of the direnvrc file for a particular version of nix-direnv. +def get_direnvrc_hash [ + version: string # The version of nix-direnv, i.e. 3.0.6 +] [ nothing -> string ] { + http get $"https://raw.githubusercontent.com/nix-community/nix-direnv/($version)/direnvrc" | hash sha256 --binary | encode new-base64 +} + +# Replace the current version of nix-direnv with the given version and update the SHA-256 checksum of the direnvrc file. +# +# This function takes as input the content of a .envrc file, like the following. +# +# if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then +# source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM=" +# fi +# +# use flake +# +export def update_nix_direnv_in_envrc [ + version: string # nix-direnv version, i.e. 3.0.6 + hash: string # The sha256 checksum of the release +] [ string -> string ] { + ( + $in + | str replace --regex "nix_direnv_version [0-9]+\\.[0-9]+\\.[0-9]+" + $"nix_direnv_version ($version)" + | str replace --regex "source_url \"https://raw.githubusercontent.com/nix-community/nix-direnv/[0-9]+\\.[0-9]+\\.[0-9]+/direnvrc\" \"sha256-[[:alnum:]]+=\"" + $'source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/($version)/direnvrc" "sha256-($hash)"' + ) +} + +def main [ + files: list = [] # A list of `.envrc` files to operate on. +] { + let files = ( + if ($files | is-empty) { + glob **/.envrc + } else { + $files + } + ) + + let version = get_latest_nix_direnv_version + let hash = get_direnvrc_hash $version + + for file in $files { + $file | open | update_nix_direnv_in_envrc $version $hash | save --force $file + } + + exit 0 +}