diff --git a/.cargo/audit.toml b/.cargo/audit.toml new file mode 100644 index 000000000..d068ac3f5 --- /dev/null +++ b/.cargo/audit.toml @@ -0,0 +1,4 @@ +# Doesn't work in the sandbox +[yanked] +enabled = false # Warn for yanked crates in Cargo.lock (default: true) +update_index = false # Auto-update the crates.io index (default: true) diff --git a/.envrc b/.envrc new file mode 100644 index 000000000..3550a30f2 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.github/flake.yml b/.github/flake.yml new file mode 100644 index 000000000..36125b433 --- /dev/null +++ b/.github/flake.yml @@ -0,0 +1,24 @@ +name: update-flake-lock + +on: + workflow_dispatch: # allows manual triggering + schedule: + - cron: '0 0 * * 0' # runs weekly on Sunday at 00:00 + +jobs: + lockfile: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Determinate Nix + uses: DeterminateSystems/nix-installer-action@main + with: + determinate: true + - name: Update flake.lock + uses: DeterminateSystems/update-flake-lock@main + with: + pr-title: "Update flake.lock" # Title of PR to be created + pr-labels: | # Labels to be set on the PR + dependencies + automated diff --git a/.gitignore b/.gitignore index 2cdbd84c9..046f515da 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /stage /parts /prime +.direnv .gitignore.swp .DS_Store result diff --git a/deny.toml b/deny.toml new file mode 100644 index 000000000..ab173681c --- /dev/null +++ b/deny.toml @@ -0,0 +1,2 @@ +[licenses] +allow = ["MIT"] diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..5bd539d10 --- /dev/null +++ b/flake.lock @@ -0,0 +1,94 @@ +{ + "nodes": { + "advisory-db": { + "flake": false, + "locked": { + "lastModified": 1746174207, + "narHash": "sha256-/ZPWm1dsz3tXREXGQfa/W6UsQ+J3Pvi0A0U1DZVgLqU=", + "owner": "rustsec", + "repo": "advisory-db", + "rev": "4584ad9a5ea16ce196317cf4d3593e974fb4a8a1", + "type": "github" + }, + "original": { + "owner": "rustsec", + "repo": "advisory-db", + "type": "github" + } + }, + "crane": { + "locked": { + "lastModified": 1746291859, + "narHash": "sha256-DdWJLA+D5tcmrRSg5Y7tp/qWaD05ATI4Z7h22gd1h7Q=", + "owner": "ipetkov", + "repo": "crane", + "rev": "dfd9a8dfd09db9aad544c4d3b6c47b12562544a5", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1746300365, + "narHash": "sha256-thYTdWqCRipwPRxWiTiH1vusLuAy0okjOyzRx4hLWh4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f21e4546e3ede7ae34d12a84602a22246b31f7e0", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "advisory-db": "advisory-db", + "crane": "crane", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..e786205ad --- /dev/null +++ b/flake.nix @@ -0,0 +1,139 @@ +{ + description = "Git repository summary on your terminal"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + crane.url = "github:ipetkov/crane"; + + flake-utils.url = "github:numtide/flake-utils"; + + advisory-db = { + url = "github:rustsec/advisory-db"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, crane, flake-utils, advisory-db, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + inherit (pkgs) lib; + + craneLib = crane.mkLib pkgs; + src = ./.; + + # Common arguments can be set here to avoid repeating them later + commonArgs = { + inherit src; + strictDeps = true; + + buildInputs = with pkgs; + [ + # package dependencies + zstd + ] ++ lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ + # additional dependencies on Darwin systems + CoreFoundation + libresolv + Security + ]); + nativeBuildInputs = with pkgs; [ cmake pkg-config ]; + nativeCheckInputs = with pkgs; [ git ]; + + # Additional environment variables can be set directly + # MY_CUSTOM_VAR = "some value"; + }; + + # Build *just* the cargo dependencies, so we can reuse + # all of that work (e.g. via cachix) when running in CI + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + # Build the actual crate itself, reusing the dependency + # artifacts from above. + onefetch = + craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; }); + in { + checks = { + # Build the crate as part of `nix flake check` for convenience + inherit onefetch; + + # Run clippy (and deny all warnings) on the crate source, + # again, reusing the dependency artifacts from above. + # + # Note that this is done as a separate derivation so that + # we can block the CI if there are issues here, but not + # prevent downstream consumers from building our crate by itself. + onefetch-clippy = craneLib.cargoClippy (commonArgs // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }); + + onefetch-doc = + craneLib.cargoDoc (commonArgs // { inherit cargoArtifacts; }); + + # Check formatting + onefetch-fmt = craneLib.cargoFmt { inherit src; }; + + onefetch-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 + onefetch-audit = craneLib.cargoAudit { inherit src advisory-db; }; + + # Audit licenses + onefetch-deny = craneLib.cargoDeny { inherit src; }; + + # Run tests with cargo-nextest + # Consider setting `doCheck = false` on `my-crate` if you do not want + # the tests to run twice + onefetch-nextest = craneLib.cargoNextest (commonArgs // { + inherit cargoArtifacts; + partitions = 1; + partitionType = "count"; + cargoNextestPartitionsExtraArgs = "--no-tests=pass"; + }); + }; + + packages = rec { + onefetch-debug = onefetch // { + cargoExtraArgs = lib.concatStringsSep " " [ + # Just to get more human-readable look + "--profile dev" + ]; + }; + inherit onefetch; + default = onefetch-debug; + }; + + apps.default = flake-utils.lib.mkApp { drv = onefetch; }; + + devShells.default = craneLib.devShell { + # Inherit inputs from checks. + checks = self.checks.${system}; + + # Additional dev-shell environment variables can be set directly + # MY_CUSTOM_DEVELOPMENT_VAR = "something else"; + + # Extra inputs can be added here; cargo and rustc are provided by default. + packages = with pkgs; [ + # pkgs.ripgrep + nixd + nixfmt + ]; + }; + }); + # Sets substituters to avoid locally building something already built + nixConfig = { + extra-substituters = + [ "https://crane.cachix.org" "https://cache.garnix.io" ]; + extra-trusted-public-keys = [ + "crane.cachix.org-1:8Scfpmn9w+hGdXH/Q9tTLiYAE/2dnJYRJP7kl80GuRk=" + "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" + ]; + }; +} diff --git a/taplo.toml b/taplo.toml new file mode 100644 index 000000000..e832af10f --- /dev/null +++ b/taplo.toml @@ -0,0 +1,13 @@ +# Sorts `Cargo.toml` dependencies. All other `.toml` files are formatted with the default config. +# +# https://taplo.tamasfe.dev/configuration/file.html#configuration-file + +[formatting] +reorder_keys = false + +[[rule]] +include = ["**/Cargo.toml"] +keys = ["dependencies"] + +[rule.formatting] +reorder_keys = true