diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 120000 index 000000000..442a58d93 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1 @@ +/nix/store/0nnfmi5rkin522yp2df1cqzx6g0ls4al-pre-commit-config.json \ No newline at end of file diff --git a/flake.lock b/flake.lock index e2af89244..d1c2efee3 100644 --- a/flake.lock +++ b/flake.lock @@ -1,93 +1,18 @@ { "nodes": { - "android-nixpkgs": { - "inputs": { - "devshell": "devshell", - "flake-utils": "flake-utils_3", - "nixpkgs": [ - "flakebox", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1719001124, - "narHash": "sha256-JXrMwYlQarZPyjN5UkD4fS9mrHSE1PUa7P//1Z5Sqr0=", - "owner": "tadfisher", - "repo": "android-nixpkgs", - "rev": "7fa1348249564e43185d3053f579f9fa923d46cc", - "type": "github" - }, - "original": { - "owner": "tadfisher", - "repo": "android-nixpkgs", - "rev": "7fa1348249564e43185d3053f579f9fa923d46cc", - "type": "github" - } - }, - "crane": { - "inputs": { - "nixpkgs": [ - "flakebox", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1717383740, - "narHash": "sha256-559HbY4uhNeoYvK3H6AMZAtVfmR3y8plXZ1x6ON/cWU=", - "owner": "ipetkov", - "repo": "crane", - "rev": "b65673fce97d277934488a451724be94cc62499a", - "type": "github" - }, - "original": { - "owner": "ipetkov", - "repo": "crane", - "rev": "b65673fce97d277934488a451724be94cc62499a", - "type": "github" - } - }, - "devshell": { - "inputs": { - "flake-utils": "flake-utils_2", - "nixpkgs": [ - "flakebox", - "android-nixpkgs", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1717408969, - "narHash": "sha256-Q0OEFqe35fZbbRPPRdrjTUUChKVhhWXz3T9ZSKmaoVY=", - "owner": "numtide", - "repo": "devshell", - "rev": "1ebbe68d57457c8cae98145410b164b5477761f4", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, - "fenix": { - "inputs": { - "nixpkgs": [ - "flakebox", - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" - }, + "flake-compat": { + "flake": false, "locked": { - "lastModified": 1717827974, - "narHash": "sha256-ixopuTeTouxqTxfMuzs6IaRttbT8JqRW5C9Q/57WxQw=", - "owner": "nix-community", - "repo": "fenix", - "rev": "ab655c627777ab5f9964652fe23bbb1dfbd687a8", + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", "type": "github" }, "original": { - "owner": "nix-community", - "repo": "fenix", + "owner": "edolstra", + "repo": "flake-compat", "type": "github" } }, @@ -109,85 +34,24 @@ "type": "github" } }, - "flake-utils_2": { - "inputs": { - "systems": "systems_2" - }, - "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_3": { - "inputs": { - "systems": "systems_3" - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_4": { + "gitignore": { "inputs": { - "systems": [ - "flakebox", - "systems" - ] - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flakebox": { - "inputs": { - "android-nixpkgs": "android-nixpkgs", - "crane": "crane", - "fenix": "fenix", - "flake-utils": "flake-utils_4", "nixpkgs": [ + "pre-commit-hooks", "nixpkgs" - ], - "systems": "systems_4" + ] }, "locked": { - "lastModified": 1723222819, - "narHash": "sha256-qjnbsopwTlnjKxjSbtchRm+kMP87FAmN0xIHLf7dQWw=", - "owner": "rustshop", - "repo": "flakebox", - "rev": "703a23a027b853d7fff36182b5875cd7d82b264a", + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", "type": "github" }, "original": { - "owner": "rustshop", - "repo": "flakebox", + "owner": "hercules-ci", + "repo": "gitignore.nix", "type": "github" } }, @@ -207,76 +71,88 @@ "type": "github" } }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "flakebox": "flakebox", - "nixpkgs": "nixpkgs" - } - }, - "rust-analyzer-src": { - "flake": false, + "nixpkgs-stable": { "locked": { - "lastModified": 1717583671, - "narHash": "sha256-+lRAmz92CNUxorqWusgJbL9VE1eKCnQQojglRemzwkw=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "48bbdd6a74f3176987d5c809894ac33957000d19", + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", "type": "github" }, "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", "type": "github" } }, - "systems": { + "nixpkgs_2": { "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "lastModified": 1719082008, + "narHash": "sha256-jHJSUH619zBQ6WdC21fFAlDxHErKVDJ5fpN0Hgx4sjs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9693852a2070b398ee123a329e68f0dab5526681", "type": "github" }, "original": { - "owner": "nix-systems", - "repo": "default", + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", "type": "github" } }, - "systems_2": { + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "lastModified": 1724857454, + "narHash": "sha256-Qyl9Q4QMTLZnnBb/8OuQ9LSkzWjBU1T5l5zIzTxkkhk=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "4509ca64f1084e73bc7a721b20c669a8d4c5ebe6", "type": "github" }, "original": { - "owner": "nix-systems", - "repo": "default", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", "type": "github" } }, - "systems_3": { + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "lastModified": 1725157860, + "narHash": "sha256-DhqyM7XJYKj+WAEaYwMtXaYX66tA+lOd31sd5QkxLDM=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "1fd72e343c6890f695243a37b367a1e3b90a49ee", "type": "github" }, "original": { - "owner": "nix-systems", - "repo": "default", + "owner": "oxalica", + "repo": "rust-overlay", "type": "github" } }, - "systems_4": { + "systems": { "locked": { "lastModified": 1681028828, "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", diff --git a/flake.nix b/flake.nix index 9a3764c60..4e3df0e05 100644 --- a/flake.nix +++ b/flake.nix @@ -1,62 +1,131 @@ { - description = "Cashu Development Kit"; + description = "CDK Flake"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; - flakebox = { - url = "github:rustshop/flakebox"; - inputs.nixpkgs.follows = "nixpkgs"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; }; flake-utils.url = "github:numtide/flake-utils"; + + pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; }; - outputs = { self, nixpkgs, flakebox, flake-utils }: + outputs = { self, nixpkgs, rust-overlay, flake-utils, pre-commit-hooks, ... }: flake-utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { system = system; }; + overlays = [ (import rust-overlay) ]; lib = pkgs.lib; - flakeboxLib = flakebox.lib.${system} { }; - rustSrc = flakeboxLib.filterSubPaths { - root = builtins.path { - name = "cdk"; - path = ./.; - }; - paths = [ "crates/*" ]; + stdenv = pkgs.stdenv; + isDarwin = stdenv.isDarwin; + libsDarwin = with pkgs; lib.optionals isDarwin [ + # Additional darwin specific inputs can be set here + darwin.apple_sdk.frameworks.Security + darwin.apple_sdk.frameworks.SystemConfiguration + ]; + + # Dependencies + pkgs = import nixpkgs { + inherit system overlays; }; - targetsStd = flakeboxLib.mkStdTargets { }; - toolchainsStd = flakeboxLib.mkStdToolchains { }; - toolchainNative = flakeboxLib.mkFenixToolchain { - targets = (pkgs.lib.getAttrs [ "default" "wasm32-unknown" ] targetsStd); + # Toolchains + # latest stable + stable_toolchain = pkgs.rust-bin.stable.latest.default.override { + targets = [ "wasm32-unknown-unknown" ]; # wasm + }; + # MSRV stable + msrv_toolchain = pkgs.rust-bin.stable."1.63.0".default.override { + targets = [ "wasm32-unknown-unknown" ]; # wasm }; - commonArgs = { - buildInputs = [ pkgs.openssl ] ++ lib.optionals pkgs.stdenv.isDarwin - [ pkgs.darwin.apple_sdk.frameworks.SystemConfiguration ]; - nativeBuildInputs = [ pkgs.pkg-config ]; + # Common inputs + envVars = { }; - outputs = (flakeboxLib.craneMultiBuild { toolchains = toolchainsStd; }) - (craneLib': - let - craneLib = (craneLib'.overrideArgs { - pname = "flexbox-multibuild"; - src = rustSrc; - }).overrideArgs commonArgs; - in - rec { - workspaceDeps = craneLib.buildWorkspaceDepsOnly { }; - workspaceBuild = - craneLib.buildWorkspace { cargoArtifacts = workspaceDeps; }; - }); + buildInputs = with pkgs; [ + # Add additional build inputs here + git + pkg-config + curl + just + protobuf3_20 + ] ++ libsDarwin; + + # WASM deps + WASMInputs = with pkgs; [ + ]; + + nativeBuildInputs = with pkgs; [ + # Add additional build inputs here + ] ++ lib.optionals isDarwin [ + # Additional darwin specific native inputs can be set here + ]; in { - devShells = flakeboxLib.mkShells { - toolchain = toolchainNative; - packages = [ ]; - nativeBuildInputs = with pkgs; [ wasm-pack sqlx-cli protobuf3_20 ]; + checks = { + # Pre-commit checks + pre-commit-check = + let + # this is a hack based on https://github.com/cachix/pre-commit-hooks.nix/issues/126 + # we want to use our own rust stuff from oxalica's overlay + _rust = pkgs.rust-bin.stable.latest.default; + rust = pkgs.buildEnv { + name = _rust.name; + inherit (_rust) meta; + buildInputs = [ pkgs.makeWrapper ]; + paths = [ _rust ]; + pathsToLink = [ "/" "/bin" ]; + postBuild = '' + for i in $out/bin/*; do + wrapProgram "$i" --prefix PATH : "$out/bin" + done + ''; + }; + in + pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + rustfmt = { + enable = true; + entry = lib.mkForce "${rust}/bin/cargo-fmt fmt --all -- --config format_code_in_doc_comments=true --check --color always"; + }; + nixpkgs-fmt.enable = true; + typos.enable = true; + commitizen.enable = true; # conventional commits + }; + }; }; - }); + + devShells = + let + # pre-commit-checks + _shellHook = (self.checks.${system}.pre-commit-check.shellHook or ""); + + # devShells + msrv = pkgs.mkShell ({ + shellHook = "${_shellHook}"; + buildInputs = buildInputs ++ WASMInputs ++ [ msrv_toolchain ]; + inherit nativeBuildInputs; + } // envVars); + + stable = pkgs.mkShell ({ + shellHook = "${_shellHook}"; + buildInputs = buildInputs ++ WASMInputs ++ [ stable_toolchain ]; + inherit nativeBuildInputs; + } // envVars); + + in + { + inherit msrv stable; + default = msrv; + }; + } + ); } diff --git a/justfile b/justfile index e82be95f6..84b94a2b2 100644 --- a/justfile +++ b/justfile @@ -1,17 +1,12 @@ -# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION - import "./misc/justfile.custom.just" alias b := build alias c := check alias t := test - -[private] default: @just --list - # run `cargo build` on everything build *ARGS="--workspace --all-targets": #!/usr/bin/env bash @@ -21,7 +16,6 @@ build *ARGS="--workspace --all-targets": fi cargo build {{ARGS}} - # run `cargo check` on everything check *ARGS="--workspace --all-targets": #!/usr/bin/env bash @@ -31,17 +25,6 @@ check *ARGS="--workspace --all-targets": fi cargo check {{ARGS}} - -# run all checks recommended before opening a PR -final-check: lint clippy - #!/usr/bin/env bash - set -euo pipefail - if [ ! -f Cargo.toml ]; then - cd {{invocation_directory()}} - fi - just test - - # run code formatters format: #!/usr/bin/env bash @@ -50,15 +33,7 @@ format: cd {{invocation_directory()}} fi cargo fmt --all - nixpkgs-fmt $(git ls-files | grep "\.nix$") - - -# run lints (git pre-commit hook) -lint: - #!/usr/bin/env bash - set -euo pipefail - env NO_STASH=true $(git rev-parse --git-common-dir)/hooks/pre-commit - + nixpkgs-fmt $(echo **.nix) # run tests test: build @@ -69,52 +44,15 @@ test: build fi cargo test - -# run and restart on changes -watch *ARGS="-x run": - #!/usr/bin/env bash - set -euo pipefail - if [ ! -f Cargo.toml ]; then - cd {{invocation_directory()}} - fi - env RUST_LOG=${RUST_LOG:-debug} cargo watch {{ARGS}} - - # run `cargo clippy` on everything clippy *ARGS="--locked --offline --workspace --all-targets": - cargo clippy {{ARGS}} -- --deny warnings --allow deprecated + cargo clippy {{ARGS}} # run `cargo clippy --fix` on everything clippy-fix *ARGS="--locked --offline --workspace --all-targets": cargo clippy {{ARGS}} --fix - -# run `semgrep` -semgrep: - env SEMGREP_ENABLE_VERSION_CHECK=0 \ - semgrep --error --no-rewrite-rule-ids --config .config/semgrep.yaml - - -# check typos -[no-exit-message] -typos *PARAMS: - #!/usr/bin/env bash - set -eo pipefail - - export FLAKEBOX_GIT_LS - FLAKEBOX_GIT_LS="$(git ls-files)" - export FLAKEBOX_GIT_LS_TEXT - FLAKEBOX_GIT_LS_TEXT="$(echo "$FLAKEBOX_GIT_LS" | grep -v -E "^db/|\.(png|ods|jpg|jpeg|woff2|keystore|wasm|ttf|jar|ico)\$")" - - - if ! echo "$FLAKEBOX_GIT_LS_TEXT" | typos {{PARAMS}} --file-list - --force-exclude ; then - >&2 echo "Typos found: Valid new words can be added to '.typos.toml'" - return 1 - fi - # fix all typos [no-exit-message] -typos-fix-all: +typos-fix: just typos -w - -# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION