From 8c712041ceebd08048868273fd9e4e4e606b1721 Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Sun, 4 May 2025 19:04:19 +0000 Subject: [PATCH 1/6] crane: init --- flake.nix | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 flake.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..fb7f0b56d --- /dev/null +++ b/flake.nix @@ -0,0 +1,126 @@ +{ + 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 = craneLib.cleanCargoSource ./.; + + # Common arguments can be set here to avoid repeating them later + commonArgs = { + inherit src; + strictDeps = true; + + buildInputs = [ + # Add additional build inputs here + ] ++ lib.optionals pkgs.stdenv.isDarwin [ + # Additional darwin specific inputs can be set here + pkgs.libiconv + ]; + + # 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. + my-crate = craneLib.buildPackage (commonArgs // { + inherit cargoArtifacts; + }); + in + { + checks = { + # Build the crate as part of `nix flake check` for convenience + inherit my-crate; + + # 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. + my-crate-clippy = craneLib.cargoClippy (commonArgs // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }); + + my-crate-doc = craneLib.cargoDoc (commonArgs // { + inherit cargoArtifacts; + }); + + # Check formatting + my-crate-fmt = craneLib.cargoFmt { + inherit src; + }; + + my-crate-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 + my-crate-audit = craneLib.cargoAudit { + inherit src advisory-db; + }; + + # Audit licenses + my-crate-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 + my-crate-nextest = craneLib.cargoNextest (commonArgs // { + inherit cargoArtifacts; + partitions = 1; + partitionType = "count"; + cargoNextestPartitionsExtraArgs = "--no-tests=pass"; + }); + }; + + packages = { + default = my-crate; + }; + + apps.default = flake-utils.lib.mkApp { + drv = my-crate; + }; + + 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 = [ + # pkgs.ripgrep + ]; + }; + }); +} From 7928e447654f1f0055d4a35579b3c3f2b69877d0 Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Sun, 4 May 2025 19:04:39 +0000 Subject: [PATCH 2/6] direnv: init --- .envrc | 1 + .gitignore | 1 + 2 files changed, 2 insertions(+) create mode 100644 .envrc 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/.gitignore b/.gitignore index 2cdbd84c9..046f515da 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /stage /parts /prime +.direnv .gitignore.swp .DS_Store result From 0211e9005e01004b68b6f8aa0b9cc9bce0dae133 Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Sun, 4 May 2025 19:05:05 +0000 Subject: [PATCH 3/6] workflow: attempt on automatic flake update --- .github/flake.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/flake.yml 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 From 77afd7098a743f6f23802e1bd173a0ef5bd7bc11 Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Sun, 4 May 2025 19:07:28 +0000 Subject: [PATCH 4/6] flake: fixes > add nix tools to devShell (rust-required stuff provided by default) > add build dependencies > add build profiles --- flake.lock | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 72 +++++++++++++++++++++-------------------- 2 files changed, 132 insertions(+), 34 deletions(-) create mode 100644 flake.lock 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 index fb7f0b56d..9e76dd95f 100644 --- a/flake.nix +++ b/flake.nix @@ -22,19 +22,25 @@ inherit (pkgs) lib; craneLib = crane.mkLib pkgs; - src = craneLib.cleanCargoSource ./.; + src = ./.; # Common arguments can be set here to avoid repeating them later commonArgs = { inherit src; strictDeps = true; - buildInputs = [ - # Add additional build inputs here - ] ++ lib.optionals pkgs.stdenv.isDarwin [ - # Additional darwin specific inputs can be set here - pkgs.libiconv - ]; + 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"; @@ -46,14 +52,12 @@ # Build the actual crate itself, reusing the dependency # artifacts from above. - my-crate = craneLib.buildPackage (commonArgs // { - inherit cargoArtifacts; - }); - in - { + onefetch = + craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; }); + in { checks = { # Build the crate as part of `nix flake check` for convenience - inherit my-crate; + inherit onefetch; # Run clippy (and deny all warnings) on the crate source, # again, reusing the dependency artifacts from above. @@ -61,40 +65,33 @@ # 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. - my-crate-clippy = craneLib.cargoClippy (commonArgs // { + onefetch-clippy = craneLib.cargoClippy (commonArgs // { inherit cargoArtifacts; cargoClippyExtraArgs = "--all-targets -- --deny warnings"; }); - my-crate-doc = craneLib.cargoDoc (commonArgs // { - inherit cargoArtifacts; - }); + onefetch-doc = + craneLib.cargoDoc (commonArgs // { inherit cargoArtifacts; }); # Check formatting - my-crate-fmt = craneLib.cargoFmt { - inherit src; - }; + onefetch-fmt = craneLib.cargoFmt { inherit src; }; - my-crate-toml-fmt = craneLib.taploFmt { + 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 - my-crate-audit = craneLib.cargoAudit { - inherit src advisory-db; - }; + onefetch-audit = craneLib.cargoAudit { inherit src advisory-db; }; # Audit licenses - my-crate-deny = craneLib.cargoDeny { - inherit src; - }; + 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 - my-crate-nextest = craneLib.cargoNextest (commonArgs // { + onefetch-nextest = craneLib.cargoNextest (commonArgs // { inherit cargoArtifacts; partitions = 1; partitionType = "count"; @@ -102,13 +99,18 @@ }); }; - packages = { - default = my-crate; + 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 = my-crate; - }; + apps.default = flake-utils.lib.mkApp { drv = onefetch; }; devShells.default = craneLib.devShell { # Inherit inputs from checks. @@ -118,8 +120,10 @@ # MY_CUSTOM_DEVELOPMENT_VAR = "something else"; # Extra inputs can be added here; cargo and rustc are provided by default. - packages = [ + packages = with pkgs; [ # pkgs.ripgrep + nixd + nixfmt ]; }; }); From f2b9f7b45d9f9b33279fc5aaf9496071e265a6fa Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Sun, 4 May 2025 19:07:59 +0000 Subject: [PATCH 5/6] flake: binary caches --- flake.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/flake.nix b/flake.nix index 9e76dd95f..e786205ad 100644 --- a/flake.nix +++ b/flake.nix @@ -127,4 +127,13 @@ ]; }; }); + # 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=" + ]; + }; } From b7d3fe6b3c13a78ed01d29da87168772dfe4ccc6 Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Sun, 4 May 2025 19:08:21 +0000 Subject: [PATCH 6/6] crane: additionals init --- .cargo/audit.toml | 4 ++++ deny.toml | 2 ++ taplo.toml | 13 +++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 .cargo/audit.toml create mode 100644 deny.toml create mode 100644 taplo.toml 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/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/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