diff --git a/.github/workflows/check-shell.yml b/.github/workflows/check-shell.yml index 6f63cb8..c1c2b4e 100644 --- a/.github/workflows/check-shell.yml +++ b/.github/workflows/check-shell.yml @@ -1,22 +1,18 @@ name: Rainix CI check shell on: [push] - jobs: rainix-check-shell: strategy: matrix: - os: [ - ubuntu-latest, - # intel mac - macos-13, - # apple silicon - macos-latest, - ] + os: [ubuntu-latest, + # intel mac + macos-13, + # apple silicon + macos-latest] fail-fast: false runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - - uses: nixbuild/nix-quick-install-action@v30 with: nix_conf: | @@ -33,7 +29,7 @@ jobs: # before trying to save a new cache # 1G = 1073741824 gc-max-store-size-linux: 1G - + - run: NIXPKGS_ALLOW_INSECURE=1 nix flake check --impure - run: nix develop --command cargo release --version - run: nix develop --command flamegraph --help - run: nix develop --command graph --version diff --git a/.github/workflows/pr-assessment.yaml b/.github/workflows/pr-assessment.yaml index 71c5461..18e484f 100644 --- a/.github/workflows/pr-assessment.yaml +++ b/.github/workflows/pr-assessment.yaml @@ -3,7 +3,6 @@ on: pull_request: types: - closed - jobs: assess-pr-size-on-merge: uses: rainlanguage/github-chore/.github/workflows/pr-assessment.yml@main diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dc4aabb..bbc3f0a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,5 @@ name: Rainix CI on: [push] - jobs: rainix: strategy: @@ -29,7 +28,6 @@ jobs: working-directory: test/fixture steps: - uses: actions/checkout@v4 - - uses: nixbuild/nix-quick-install-action@v30 with: nix_conf: | @@ -46,7 +44,6 @@ jobs: # before trying to save a new cache # 1G = 1073741824 gc-max-store-size-linux: 1G - - run: nix run ../..#rainix-sol-prelude - run: nix run ../..#rainix-rs-prelude - name: Run ${{ matrix.task }} diff --git a/.gitignore b/.gitignore index d38617e..6bfc3f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ result -.env \ No newline at end of file +.env +.pre-commit-config.yaml diff --git a/.vscode/extensions.json b/.vscode/extensions.json index fce5ab4..76d746c 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,5 +1,5 @@ { - "recommendations": [ - "jnoortheen.nix-ide" - ] -} \ No newline at end of file + "recommendations": [ + "jnoortheen.nix-ide" + ] +} diff --git a/REUSE.toml b/REUSE.toml index 6a47568..80217e4 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -9,7 +9,7 @@ path = [ "REUSE.toml", ".github/**/", ".vscode/**/", - "test/**/" + "test/**/", ] SPDX-FileCopyrightText = "Copyright (c) 2020 thedavidmeister" SPDX-License-Identifier = "LicenseRef-DCL-1.0" diff --git a/flake.lock b/flake.lock index a69ab30..1c332c7 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -57,11 +73,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1769324704, - "narHash": "sha256-aef15vEgiMEls1hTMt46rJuKNSO2cIOfiP99patq9yc=", + "lastModified": 1773126975, + "narHash": "sha256-f3bmp4aJTAaruN5SNzz/uwZ4zUTBRanUz8BLfLxVC20=", "owner": "shazow", "repo": "foundry.nix", - "rev": "e830409ba1bdecdc5ef9a1ec92660fc2da9bc68d", + "rev": "56aa74fe1db1c57600328eb87fdd5ad33f54beb8", "type": "github" }, "original": { @@ -70,6 +86,47 @@ "type": "github" } }, + "git-hooks-nix": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1772893680, + "narHash": "sha256-JDqZMgxUTCq85ObSaFw0HhE+lvdOre1lx9iI6vYyOEs=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "8baab586afc9c9b57645a734c820e4ac0a604af9", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "git-hooks-nix", + "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": 1666753130, @@ -102,11 +159,27 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1769364508, - "narHash": "sha256-Wy8EVYSLq5Fb/rYH3LRxAMCnW75f9hOg2562AXVFmPk=", + "lastModified": 1770073757, + "narHash": "sha256-Vy+G+F+3E/Tl+GMNgiHl9Pah2DgShmIUBJXmbiQPHbI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "47472570b1e607482890801aeaf29bfb749884f6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1773161593, + "narHash": "sha256-oM5Nhob3rAu3CVNr/FhDreDlIyLNL239kZYtDVm6+m8=", "owner": "nixos", "repo": "nixpkgs", - "rev": "6077bc4fb29be43d525984f63b69d37b9b1e62fe", + "rev": "d292ac24f957a689b2f0e48a44cdb41fa4c59046", "type": "github" }, "original": { @@ -115,7 +188,7 @@ "type": "github" } }, - "nixpkgs_3": { + "nixpkgs_4": { "locked": { "lastModified": 1744536153, "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", @@ -131,13 +204,13 @@ "type": "github" } }, - "nixpkgs_4": { + "nixpkgs_5": { "locked": { - "lastModified": 1766653575, - "narHash": "sha256-TPgxCS7+hWc4kPhzkU5dD2M5UuPhLuuaMNZ/IpwKQvI=", + "lastModified": 1771923393, + "narHash": "sha256-Fy0+UXELv9hOE8WjYhJt8fMDLYTU2Dqn3cX4BwoGBos=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3c1016e6acd16ad96053116d0d3043029c9e2649", + "rev": "ea7f1f06811ce7fcc81d6c6fd4213150c23edcf2", "type": "github" }, "original": { @@ -151,7 +224,8 @@ "inputs": { "flake-utils": "flake-utils", "foundry": "foundry", - "nixpkgs": "nixpkgs_2", + "git-hooks-nix": "git-hooks-nix", + "nixpkgs": "nixpkgs_3", "nixpkgs-old": "nixpkgs-old", "rust-overlay": "rust-overlay", "solc": "solc" @@ -159,14 +233,14 @@ }, "rust-overlay": { "inputs": { - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1769309768, - "narHash": "sha256-AbOIlNO+JoqRJkK1VrnDXhxuX6CrdtIu2hSuy4pxi3g=", + "lastModified": 1773115373, + "narHash": "sha256-bfK9FJFcQth6f3ydYggS5m0z2NRGF/PY6Y2XgZDJ6pg=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "140c9dc582cb73ada2d63a2180524fcaa744fad5", + "rev": "1924b4672a2b8e4aee6e6652ec2e59a8d3c5648e", "type": "github" }, "original": { @@ -178,15 +252,15 @@ "solc": { "inputs": { "flake-utils": "flake-utils_3", - "nixpkgs": "nixpkgs_4", + "nixpkgs": "nixpkgs_5", "solc-macos-amd64-list-json": "solc-macos-amd64-list-json" }, "locked": { - "lastModified": 1768831671, - "narHash": "sha256-0mmlYRtZK+eomevkQCCH7PL8QlSuALZQsjLroCWGE08=", + "lastModified": 1772085240, + "narHash": "sha256-+NEcuhT2A0QQumVx9Ze6g2iuNicyuW028Jq/HUJHGh4=", "owner": "hellwolf", "repo": "solc.nix", - "rev": "80ad871b93d15c7bccf71617f78f73c2d291a9c7", + "rev": "d3cc119973e484ea366f4b997b404bb00d7829ca", "type": "github" }, "original": { @@ -198,13 +272,13 @@ "solc-macos-amd64-list-json": { "flake": false, "locked": { - "narHash": "sha256-P+ZslplK4cQ/wnV/wykVKb+yTCviI0eylA3sk9uHmRo=", + "narHash": "sha256-oEiXc95EghuYCudzkPA9XBFOnMdgWFfTO2/4XUfSTpc=", "type": "file", - "url": "https://github.com/argotorg/solc-bin/raw/a11f1ad/macosx-amd64/list.json" + "url": "https://github.com/argotorg/solc-bin/raw/83cb756/macosx-amd64/list.json" }, "original": { "type": "file", - "url": "https://github.com/argotorg/solc-bin/raw/a11f1ad/macosx-amd64/list.json" + "url": "https://github.com/argotorg/solc-bin/raw/83cb756/macosx-amd64/list.json" } }, "systems": { diff --git a/flake.nix b/flake.nix index 1a33f7c..3fe31a8 100644 --- a/flake.nix +++ b/flake.nix @@ -8,10 +8,13 @@ foundry.url = "github:shazow/foundry.nix"; solc.url = "github:hellwolf/solc.nix"; # old nixpkgs, pinned for webkitgtk and libsoup-2.4 needed for tauri shell and build - nixpkgs-old.url = "github:nixos/nixpkgs?rev=48975d7f9b9960ed33c4e8561bcce20cc0c2de5b"; + nixpkgs-old.url = + "github:nixos/nixpkgs?rev=48975d7f9b9960ed33c4e8561bcce20cc0c2de5b"; + git-hooks-nix.url = "github:cachix/git-hooks.nix"; }; - outputs = { self, nixpkgs, flake-utils, rust-overlay, foundry, solc, nixpkgs-old }: + outputs = { nixpkgs, flake-utils, rust-overlay, foundry, solc, nixpkgs-old + , git-hooks-nix, ... }: flake-utils.lib.eachDefaultSystem (system: let wasm-bindgen-overlay = final: prev: { @@ -41,9 +44,8 @@ pkgs.cargo-flamegraph ] ++ (pkgs.lib.optionals (!pkgs.stdenv.isDarwin) [ # pkgs.glibc - ]) ++ (pkgs.lib.optionals pkgs.stdenv.isDarwin [ - pkgs.darwin.DarwinTools - ]); + ]) ++ (pkgs.lib.optionals pkgs.stdenv.isDarwin + [ pkgs.darwin.DarwinTools ]); sol-build-inputs = [ pkgs.git @@ -150,7 +152,7 @@ # https://ertt.ca/nix/shell-scripts/ mkTask = { name, body, additionalBuildInputs ? [ ] }: pkgs.symlinkJoin { - name = name; + inherit name; paths = [ ((pkgs.writeScriptBin name body).overrideAttrs (old: { buildCommand = '' @@ -351,15 +353,53 @@ additionalBuildInputs = [ pkgs.bats ]; }; + pre-commit = git-hooks-nix.lib.${system}.run { + src = ./.; + hooks = { + # Nix + nil.enable = true; + nixfmt-classic.enable = true; + + deadnix.enable = true; + # excluded for files generated by bun2nix + deadnix.excludes = [ "bun\\.nix$" ]; + + statix.enable = true; + statix.settings.ignore = [ "lib/" ]; + + # Rust + taplo.enable = true; + # Conditional rustfmt - only runs if Cargo.toml exists + rustfmt-conditional = { + enable = true; + name = "rustfmt"; + entry = "${pkgs.writeShellScript "rustfmt-conditional" '' + if [ -f Cargo.toml ] || [ -f */Cargo.toml ]; then + exec ${rust-toolchain}/bin/cargo-fmt fmt + else + exit 0 + fi + ''}"; + files = "\\.rs$"; + pass_filenames = false; + }; + + # Misc + denofmt = { + enable = true; + excludes = [ ".*\\.ts$" ".*\\.js$" ".*\\.json$" ]; + }; + yamlfmt.enable = true; + yamlfmt.settings.lint-only = false; + shellcheck.enable = true; + }; + }; + in { - pkgs = pkgs; - old-pkgs = old-pkgs; - rust-toolchain = rust-toolchain; - rust-build-inputs = rust-build-inputs; - sol-build-inputs = sol-build-inputs; - node-build-inputs = node-build-inputs; - mkTask = mkTask; - network-list = network-list; + checks.pre-commit = pre-commit; + + inherit pkgs old-pkgs rust-toolchain rust-build-inputs sol-build-inputs + node-build-inputs mkTask network-list; packages = { inherit rainix-sol-prelude rainix-sol-static rainix-sol-test @@ -371,8 +411,10 @@ devShells.default = pkgs.mkShell { buildInputs = sol-build-inputs ++ rust-build-inputs ++ node-build-inputs ++ rainix-tasks ++ subgraph-tasks - ++ [ the-graph goldsky pkgs.sqlite ]; + ++ [ the-graph goldsky pkgs.sqlite pkgs.pre-commit ] + ++ pre-commit.enabledPackages; shellHook = '' + ${pre-commit.shellHook} ${source-dotenv} if [ -f ./package.json ]; then @@ -385,8 +427,10 @@ devShells.tauri-shell = pkgs.mkShell { packages = [ tauri-shellhook-test ]; buildInputs = sol-build-inputs ++ rust-build-inputs - ++ node-build-inputs ++ tauri-build-inputs; + ++ node-build-inputs ++ tauri-build-inputs ++ [ pkgs.pre-commit ] + ++ pre-commit.enabledPackages; shellHook = '' + ${pre-commit.shellHook} ${source-dotenv} export TMP_BASE64_PATH=$(mktemp -d) diff --git a/test/bats/devshell/tauri/shellhook.test.bats b/test/bats/devshell/tauri/shellhook.test.bats index 1f2dbdd..4794c7e 100644 --- a/test/bats/devshell/tauri/shellhook.test.bats +++ b/test/bats/devshell/tauri/shellhook.test.bats @@ -3,7 +3,8 @@ } @test "nixpkgs apple_sdk xcrun should NOT be in PATH" { - ! bash -c 'echo "$PATH" | grep -q "xcrun"' + # shellcheck disable=SC2016 + run ! bash -c 'echo "$PATH" | grep -q "xcrun"' } @test "should have access to native macos xcrun" { diff --git a/test/fixture/.github/workflows/test.yml b/test/fixture/.github/workflows/test.yml index 9282e82..f5cc201 100644 --- a/test/fixture/.github/workflows/test.yml +++ b/test/fixture/.github/workflows/test.yml @@ -1,33 +1,26 @@ name: test - on: workflow_dispatch - env: FOUNDRY_PROFILE: ci - jobs: check: strategy: fail-fast: true - name: Foundry project runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 with: version: nightly - - name: Run Forge build run: | forge --version forge build --sizes id: build - - name: Run Forge tests run: | forge test -vvv diff --git a/test/fixture/Cargo.toml b/test/fixture/Cargo.toml index fc7afe7..c5b7fed 100644 --- a/test/fixture/Cargo.toml +++ b/test/fixture/Cargo.toml @@ -1,5 +1,3 @@ [workspace] resolver = "2" -members = [ - "crates/test-rs" -] \ No newline at end of file +members = ["crates/test-rs"] diff --git a/test/fixture/README.md b/test/fixture/README.md index 9265b45..fb26d44 100644 --- a/test/fixture/README.md +++ b/test/fixture/README.md @@ -1,13 +1,15 @@ ## Foundry -**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** +**Foundry is a blazing fast, portable and modular toolkit for Ethereum +application development written in Rust.** Foundry consists of: -- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). -- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. -- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. -- **Chisel**: Fast, utilitarian, and verbose solidity REPL. +- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). +- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending + transactions and getting chain data. +- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. +- **Chisel**: Fast, utilitarian, and verbose solidity REPL. ## Documentation diff --git a/test/fixture/REUSE.toml b/test/fixture/REUSE.toml index 6ef901d..8fb9753 100644 --- a/test/fixture/REUSE.toml +++ b/test/fixture/REUSE.toml @@ -11,7 +11,7 @@ path = [ "foundry.toml", "crates/**/", "devshell/**/", - "foundry.lock" + "foundry.lock", ] SPDX-FileCopyrightText = "Copyright (c) 2020 thedavidmeister" SPDX-License-Identifier = "LicenseRef-DCL-1.0"