From 8c712041ceebd08048868273fd9e4e4e606b1721 Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Sun, 4 May 2025 19:04:19 +0000 Subject: [PATCH 01/19] 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 02/19] 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 03/19] 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 04/19] 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 05/19] 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 06/19] 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 From 7d29e150c4dc379867bb25669b4638d4f7a48bbb Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Mon, 2 Jun 2025 19:16:15 +0000 Subject: [PATCH 07/19] flake: fmt, comments, renames --- flake.nix | 95 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 59 insertions(+), 36 deletions(-) diff --git a/flake.nix b/flake.nix index e786205ad..126e8e4b6 100644 --- a/flake.nix +++ b/flake.nix @@ -1,11 +1,11 @@ { - description = "Git repository summary on your terminal"; + 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 = { @@ -14,8 +14,17 @@ }; }; - outputs = { self, nixpkgs, crane, flake-utils, advisory-db, ... }: - flake-utils.lib.eachDefaultSystem (system: + outputs = + { + self, + nixpkgs, + crane, + flake-utils, + advisory-db, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: let pkgs = nixpkgs.legacyPackages.${system}; @@ -25,78 +34,89 @@ src = ./.; # Common arguments can be set here to avoid repeating them later - commonArgs = { + common = { inherit src; strictDeps = true; - buildInputs = with pkgs; + # Bunch of libraries required for package proper work + buildInputs = + with pkgs; [ # package dependencies zstd - ] ++ lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ + ] + ++ lib.optionals pkgs.stdenv.isDarwin ( + with pkgs; + [ # additional dependencies on Darwin systems CoreFoundation libresolv Security - ]); - nativeBuildInputs = with pkgs; [ cmake pkg-config ]; + ] + ); + # Software required for project build + nativeBuildInputs = with pkgs; [ + cmake + pkg-config + ]; + # Tools required for checks 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 dependencies only, so we will be able to reuse them further + cargoArtifacts = craneLib.buildDepsOnly common; # Build the actual crate itself, reusing the dependency # artifacts from above. - onefetch = - craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; }); - in { + build = craneLib.buildPackage (common // { inherit cargoArtifacts; }); + in + { checks = { # Build the crate as part of `nix flake check` for convenience - inherit onefetch; + inherit build; # 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 // { + clippy = craneLib.cargoClippy ( + common + // { inherit cargoArtifacts; cargoClippyExtraArgs = "--all-targets -- --deny warnings"; - }); + } + ); - onefetch-doc = - craneLib.cargoDoc (commonArgs // { inherit cargoArtifacts; }); + doc = craneLib.cargoDoc (common // { inherit cargoArtifacts; }); # Check formatting - onefetch-fmt = craneLib.cargoFmt { inherit src; }; + fmt = craneLib.cargoFmt { inherit src; }; - onefetch-toml-fmt = craneLib.taploFmt { + tomlFmt = 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 = craneLib.cargoAudit { inherit src advisory-db; }; # Audit licenses - onefetch-deny = craneLib.cargoDeny { inherit src; }; + 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 // { + nextest = craneLib.cargoNextest ( + common + // { inherit cargoArtifacts; partitions = 1; partitionType = "count"; cargoNextestPartitionsExtraArgs = "--no-tests=pass"; - }); + } + ); }; packages = rec { @@ -110,7 +130,7 @@ default = onefetch-debug; }; - apps.default = flake-utils.lib.mkApp { drv = onefetch; }; + apps.default = flake-utils.lib.mkApp { drv = build; }; devShells.default = craneLib.devShell { # Inherit inputs from checks. @@ -123,14 +143,17 @@ packages = with pkgs; [ # pkgs.ripgrep nixd - nixfmt + nixfmt-rfc-style ]; }; - }); + } + ); # Sets substituters to avoid locally building something already built nixConfig = { - extra-substituters = - [ "https://crane.cachix.org" "https://cache.garnix.io" ]; + 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 5eda373a83337c63ac34672b4c7cd8e32b4f930c Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Mon, 2 Jun 2025 19:16:35 +0000 Subject: [PATCH 08/19] flake: fix packages --- flake.nix | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index 126e8e4b6..68ab66992 100644 --- a/flake.nix +++ b/flake.nix @@ -120,13 +120,21 @@ }; packages = rec { - onefetch-debug = onefetch // { - cargoExtraArgs = lib.concatStringsSep " " [ - # Just to get more human-readable look - "--profile dev" - ]; - }; - inherit onefetch; + onefetch-debug = craneLib.buildPackage ( + common + // { + inherit cargoArtifacts; + doCheck = false; + CARGO_PROFILE = "dev"; + } + ); + onefetch = craneLib.buildPackage ( + common + // { + inherit cargoArtifacts; + doCheck = false; + } + ); default = onefetch-debug; }; From 575e04cb20af8728bc1895343974af109cb28199 Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Mon, 2 Jun 2025 19:26:32 +0000 Subject: [PATCH 09/19] onefetch-image: make clippy happy --- image/src/kitty.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/image/src/kitty.rs b/image/src/kitty.rs index 6ec60de62..290badea6 100644 --- a/image/src/kitty.rs +++ b/image/src/kitty.rs @@ -31,11 +31,7 @@ impl KittyBackend { // generate red rgba test image let mut test_image = Vec::::with_capacity(32 * 32 * 4); - test_image.extend( - std::iter::repeat([255, 0, 0, 255].iter()) - .take(32 * 32) - .flatten(), - ); + test_image.extend(std::iter::repeat_n([255, 0, 0, 255].iter(), 32 * 32).flatten()); // print the test image with the action set to query print!( From 6f6e2a3d1003750b80ffc183f0d13111d7f2128d Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Tue, 3 Jun 2025 12:55:58 +0000 Subject: [PATCH 10/19] onefetch-image: make clippy unhappy again(( --- image/src/kitty.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/image/src/kitty.rs b/image/src/kitty.rs index 290badea6..6ec60de62 100644 --- a/image/src/kitty.rs +++ b/image/src/kitty.rs @@ -31,7 +31,11 @@ impl KittyBackend { // generate red rgba test image let mut test_image = Vec::::with_capacity(32 * 32 * 4); - test_image.extend(std::iter::repeat_n([255, 0, 0, 255].iter(), 32 * 32).flatten()); + test_image.extend( + std::iter::repeat([255, 0, 0, 255].iter()) + .take(32 * 32) + .flatten(), + ); // print the test image with the action set to query print!( From 8241a02c338717832fa89db1ae9bd635ab8cf945 Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Tue, 3 Jun 2025 16:32:23 +0000 Subject: [PATCH 11/19] taplo: detailed configuration --- taplo.toml | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/taplo.toml b/taplo.toml index e832af10f..f44c266c5 100644 --- a/taplo.toml +++ b/taplo.toml @@ -1,13 +1,24 @@ -# 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 +# Sorts `Cargo.toml` dependencies. All other `.toml` files are formatted with the default config. +# +# https://taplo.tamasfe.dev/configuration/file.html#configuration-file + +[formatting] + align_comments = true + align_entries = true + # + array_auto_collapse = false + array_auto_expand = true + array_trailing_comma = true + # + compact_arrays = false + compact_entries = false + compact_inline_tables = false + # + indent_entries = true + indent_tables = true + # + reorder_arrays = true + reorder_inline_tables = true + reorder_keys = true + # + crlf = true From c2ae2b3daab78e6fae2297a2f73af897c6201811 Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Wed, 4 Jun 2025 05:35:33 +0000 Subject: [PATCH 12/19] taplo: disable CRLF --- taplo.toml | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/taplo.toml b/taplo.toml index f44c266c5..bf6bbc169 100644 --- a/taplo.toml +++ b/taplo.toml @@ -1,24 +1,22 @@ -# Sorts `Cargo.toml` dependencies. All other `.toml` files are formatted with the default config. -# -# https://taplo.tamasfe.dev/configuration/file.html#configuration-file - -[formatting] - align_comments = true - align_entries = true - # - array_auto_collapse = false - array_auto_expand = true - array_trailing_comma = true - # - compact_arrays = false - compact_entries = false - compact_inline_tables = false - # - indent_entries = true - indent_tables = true - # - reorder_arrays = true - reorder_inline_tables = true - reorder_keys = true - # - crlf = true +# Sorts `Cargo.toml` dependencies. All other `.toml` files are formatted with the default config. +# +# https://taplo.tamasfe.dev/configuration/file.html#configuration-file + +[formatting] + align_comments = true + align_entries = true + # + array_auto_collapse = false + array_auto_expand = true + array_trailing_comma = true + # + compact_arrays = false + compact_entries = false + compact_inline_tables = false + # + indent_entries = true + indent_tables = true + # + reorder_arrays = true + reorder_inline_tables = true + reorder_keys = true From 5586b14f482272148ca980855c3e44d1d17ba4a6 Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Wed, 4 Jun 2025 08:33:21 +0000 Subject: [PATCH 13/19] flake: sources filter --- flake.nix | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 68ab66992..ae2ad484e 100644 --- a/flake.nix +++ b/flake.nix @@ -29,9 +29,26 @@ pkgs = nixpkgs.legacyPackages.${system}; inherit (pkgs) lib; - craneLib = crane.mkLib pkgs; + + # This filter prevent project from being rebuilded then changing + # unrelated files ,e.g. README + filter' = + path: _type: + builtins.match (lib.concatStringsSep "|" [ + ".*tera" + ".*yaml" + ".*zstd" + ".*snap" + ".*sh" + ".+LICENSE.md" + ]) path != null; + filter = path: type: (filter' path type) || (craneLib.filterCargoSources path type); + src = lib.cleanSourceWith { src = ./.; + inherit filter; + name = "source"; + }; # Common arguments can be set here to avoid repeating them later common = { From 2827fe651dcbb1b1a7add6bb40e5ec2b3844e2fe Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Wed, 4 Jun 2025 08:33:57 +0000 Subject: [PATCH 14/19] flake: set default CARGO_PROFILE to "dev" --- flake.nix | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/flake.nix b/flake.nix index ae2ad484e..080222c29 100644 --- a/flake.nix +++ b/flake.nix @@ -45,7 +45,7 @@ ]) path != null; filter = path: type: (filter' path type) || (craneLib.filterCargoSources path type); src = lib.cleanSourceWith { - src = ./.; + src = ./.; inherit filter; name = "source"; }; @@ -65,10 +65,10 @@ ++ lib.optionals pkgs.stdenv.isDarwin ( with pkgs; [ - # additional dependencies on Darwin systems - CoreFoundation - libresolv - Security + # additional dependencies on Darwin systems + CoreFoundation + libresolv + Security ] ); # Software required for project build @@ -79,8 +79,10 @@ # Tools required for checks nativeCheckInputs = with pkgs; [ git ]; - # Additional environment variables can be set directly - # MY_CUSTOM_VAR = "some value"; + # Additional environment variables + # This one overrides build profile (default is 'release') + CARGO_PROFILE = "dev"; + }; # Build dependencies only, so we will be able to reuse them further @@ -100,8 +102,8 @@ clippy = craneLib.cargoClippy ( common // { - inherit cargoArtifacts; - cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; } ); @@ -128,10 +130,10 @@ nextest = craneLib.cargoNextest ( common // { - inherit cargoArtifacts; - partitions = 1; - partitionType = "count"; - cargoNextestPartitionsExtraArgs = "--no-tests=pass"; + inherit cargoArtifacts; + partitions = 1; + partitionType = "count"; + cargoNextestPartitionsExtraArgs = "--no-tests=pass"; } ); }; @@ -142,12 +144,12 @@ // { inherit cargoArtifacts; doCheck = false; - CARGO_PROFILE = "dev"; } ); onefetch = craneLib.buildPackage ( common // { + CARGO_PROFILE = "release"; inherit cargoArtifacts; doCheck = false; } @@ -155,7 +157,7 @@ default = onefetch-debug; }; - apps.default = flake-utils.lib.mkApp { drv = build; }; + apps.default = flake-utils.lib.mkApp { drv = (build // { CARGO_PROFILE = "release"; }); }; devShells.default = craneLib.devShell { # Inherit inputs from checks. From 76071540d3a242fa643c4e85b6899e3ceb9bb33a Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Thu, 5 Jun 2025 13:07:53 +0000 Subject: [PATCH 15/19] taplo: remove odd comment --- taplo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/taplo.toml b/taplo.toml index bf6bbc169..91ac09963 100644 --- a/taplo.toml +++ b/taplo.toml @@ -1,5 +1,3 @@ -# Sorts `Cargo.toml` dependencies. All other `.toml` files are formatted with the default config. -# # https://taplo.tamasfe.dev/configuration/file.html#configuration-file [formatting] From 5c33e8a4630a271bdeda3fbbe95a80141719a355 Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Thu, 5 Jun 2025 15:18:17 +0000 Subject: [PATCH 16/19] nix: treefmt formatter --- flake.nix | 4 ++++ treefmt.nix | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 treefmt.nix diff --git a/flake.nix b/flake.nix index 080222c29..ac159fa3c 100644 --- a/flake.nix +++ b/flake.nix @@ -7,6 +7,7 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; crane.url = "github:ipetkov/crane"; flake-utils.url = "github:numtide/flake-utils"; + treefmt.url = "github:numtide/treefmt-nix"; advisory-db = { url = "github:rustsec/advisory-db"; @@ -20,6 +21,7 @@ nixpkgs, crane, flake-utils, + treefmt, advisory-db, ... }: @@ -173,6 +175,8 @@ nixfmt-rfc-style ]; }; + + formatter = (treefmt.lib.evalModule pkgs ./treefmt.nix).config.build.wrapper; } ); # Sets substituters to avoid locally building something already built diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 000000000..eacb2c3a8 --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,13 @@ +{ pkgs, ... }: +{ + projectRootFile = "flake.nix"; + + programs = { + taplo.enable = true; + rustfmt = { + enable = true; + edition = "2021"; + }; + nixfmt.enable = true; + }; +} From 15759b6c3cd633defe1ec135865bd0a01e4df77e Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Thu, 5 Jun 2025 15:18:42 +0000 Subject: [PATCH 17/19] toml: fmt --- .cargo/audit.toml | 4 +- .rustfmt.toml | 2 +- Cargo.toml | 146 +++++++++++------------ ascii/Cargo.toml | 16 +-- deny.toml | 2 +- image/Cargo.toml | 26 ++-- manifest/Cargo.toml | 22 ++-- manifest/tests/fixtures/cargo/Cargo.toml | 28 ++--- 8 files changed, 123 insertions(+), 123 deletions(-) diff --git a/.cargo/audit.toml b/.cargo/audit.toml index d068ac3f5..4baecd006 100644 --- a/.cargo/audit.toml +++ b/.cargo/audit.toml @@ -1,4 +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) + 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/.rustfmt.toml b/.rustfmt.toml index ec8c4bf76..e12de3eef 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,3 +1,3 @@ # See also https://rust-lang.github.io/rustfmt for more settings. -edition = "2021" +edition = "2021" newline_style = "Unix" diff --git a/Cargo.toml b/Cargo.toml index 40752c915..6027bd4e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,96 +1,96 @@ [workspace.package] -authors = ["o2sh "] -edition = "2021" -license = "MIT" -version = "2.23.1" -repository = "https://github.com/o2sh/onefetch" + authors = [ "o2sh " ] + edition = "2021" + license = "MIT" + repository = "https://github.com/o2sh/onefetch" + version = "2.23.1" [workspace] -members = ["ascii", "image", "manifest"] + members = [ "ascii", "image", "manifest" ] -[workspace.dependencies] -owo-colors = "4.1.0" -anyhow = "1.0" -clap = { version = "4.5.26", features = ["derive"] } -image = { version = "0.25.5", default-features = false, features = [ - "color_quant", - "jpeg", - "png", - "webp", -] } -strum = { version = "0.26.3", features = ["derive"] } + [workspace.dependencies] + anyhow = "1.0" + clap = { version = "4.5.26", features = [ "derive" ] } + image = { version = "0.25.5", default-features = false, features = [ + "color_quant", + "jpeg", + "png", + "webp", + ] } + owo-colors = "4.1.0" + strum = { version = "0.26.3", features = [ "derive" ] } [package] -authors.workspace = true -edition.workspace = true -version.workspace = true -license.workspace = true -repository.workspace = true -categories = ["command-line-utilities"] -description = "Command-line Git information tool" -exclude = ["docs/vercel/*"] -keywords = ["git", "cli", "terminal"] -name = "onefetch" -homepage = "https://onefetch.dev" -rust-version = "1.81.0" + authors.workspace = true + categories = [ "command-line-utilities" ] + description = "Command-line Git information tool" + edition.workspace = true + exclude = [ "docs/vercel/*" ] + homepage = "https://onefetch.dev" + keywords = [ "cli", "git", "terminal" ] + license.workspace = true + name = "onefetch" + repository.workspace = true + rust-version = "1.81.0" + version.workspace = true [dependencies] -anyhow.workspace = true -askalono = "0.5.0" -byte-unit = "5.1.6" -clap.workspace = true -clap_complete = "4.5.42" -crossbeam-channel = "0.5.14" -gix = { version = "0.70.0", default-features = false, features = [ - "max-performance-safe", + anyhow.workspace = true + askalono = "0.5.0" + byte-unit = "5.1.6" + clap.workspace = true + clap_complete = "4.5.42" + crossbeam-channel = "0.5.14" + gix = { version = "0.70.0", default-features = false, features = [ "blob-diff", - "mailmap", "index", + "mailmap", + "max-performance-safe", "status", -] } -gix-features = { version = "0.40.0", features = ["zlib-ng"] } -globset = "0.4.15" -human-panic = "2.0.2" -image.workspace = true -num-format = "0.4.4" -onefetch-ascii = { path = "ascii", version = "2.19.0" } -onefetch-image = { path = "image", version = "2.19.0" } -onefetch-manifest = { path = "manifest", version = "2.19.0" } -owo-colors.workspace = true -regex = "1.11.1" -serde = "1.0" -serde_json = "1.0" -serde_yaml = "0.9.34" -# TODO With the new value parsers, we're really close to being able to eliminate -# the strum dependency -strum.workspace = true -time = { version = "0.3.37", features = ["formatting"] } -time-humanize = { version = "0.1.3", features = ["time"] } -tokei = "13.0.0-alpha.8" -typetag = "0.2" + ] } + gix-features = { version = "0.40.0", features = [ "zlib-ng" ] } + globset = "0.4.15" + human-panic = "2.0.2" + image.workspace = true + num-format = "0.4.4" + onefetch-ascii = { path = "ascii", version = "2.19.0" } + onefetch-image = { path = "image", version = "2.19.0" } + onefetch-manifest = { path = "manifest", version = "2.19.0" } + owo-colors.workspace = true + regex = "1.11.1" + serde = "1.0" + serde_json = "1.0" + serde_yaml = "0.9.34" + # TODO With the new value parsers, we're really close to being able to eliminate + # the strum dependency + strum.workspace = true + time = { version = "0.3.37", features = [ "formatting" ] } + time-humanize = { version = "0.1.3", features = [ "time" ] } + tokei = "13.0.0-alpha.8" + typetag = "0.2" [dev-dependencies] -criterion = "0.5.1" -gix-testtools = "0.15.0" -insta = { version = "1.42.1", features = ["json", "redactions"] } -rstest = "0.24.0" + criterion = "0.5.1" + gix-testtools = "0.15.0" + insta = { version = "1.42.1", features = [ "json", "redactions" ] } + rstest = "0.24.0" [[bench]] -name = "repo" -harness = false + harness = false + name = "repo" [build-dependencies] -lazy_static = "1" -regex = "1" -serde_json = "1" -serde_yaml = "0.9" -tera = { version = "1", default-features = false } + lazy_static = "1" + regex = "1" + serde_json = "1" + serde_yaml = "0.9" + tera = { version = "1", default-features = false } [target.'cfg(windows)'.build-dependencies] -winres = "0.1" + winres = "0.1" [target.'cfg(windows)'.dependencies] -enable-ansi-support = "0.2.1" + enable-ansi-support = "0.2.1" [features] -fail-on-deprecated = [] + fail-on-deprecated = [ ] diff --git a/ascii/Cargo.toml b/ascii/Cargo.toml index 0f1135ab9..e33898e3b 100644 --- a/ascii/Cargo.toml +++ b/ascii/Cargo.toml @@ -1,11 +1,11 @@ [package] -authors.workspace = true -edition.workspace = true -version.workspace = true -license.workspace = true -repository.workspace = true -name = "onefetch-ascii" -description = "Display colorized ascii art to the terminal" + authors.workspace = true + description = "Display colorized ascii art to the terminal" + edition.workspace = true + license.workspace = true + name = "onefetch-ascii" + repository.workspace = true + version.workspace = true [dependencies] -owo-colors.workspace = true + owo-colors.workspace = true diff --git a/deny.toml b/deny.toml index ab173681c..673687ccc 100644 --- a/deny.toml +++ b/deny.toml @@ -1,2 +1,2 @@ [licenses] -allow = ["MIT"] + allow = [ "MIT" ] diff --git a/image/Cargo.toml b/image/Cargo.toml index 015e2060d..e090ae916 100644 --- a/image/Cargo.toml +++ b/image/Cargo.toml @@ -1,18 +1,18 @@ [package] -authors.workspace = true -edition.workspace = true -version.workspace = true -license.workspace = true -repository.workspace = true -name = "onefetch-image" -description = "Display images in the terminal" + authors.workspace = true + description = "Display images in the terminal" + edition.workspace = true + license.workspace = true + name = "onefetch-image" + repository.workspace = true + version.workspace = true [dependencies] -anyhow.workspace = true -clap.workspace = true -image.workspace = true + anyhow.workspace = true + clap.workspace = true + image.workspace = true [target.'cfg(not(windows))'.dependencies] -color_quant = "1.1.0" -base64 = "0.22.1" -libc = "0.2.169" + base64 = "0.22.1" + color_quant = "1.1.0" + libc = "0.2.169" diff --git a/manifest/Cargo.toml b/manifest/Cargo.toml index 646f7809c..754a16562 100644 --- a/manifest/Cargo.toml +++ b/manifest/Cargo.toml @@ -1,14 +1,14 @@ [package] -authors.workspace = true -edition.workspace = true -version.workspace = true -license.workspace = true -repository.workspace = true -name = "onefetch-manifest" -description = "Detect and parse manifest files" + authors.workspace = true + description = "Detect and parse manifest files" + edition.workspace = true + license.workspace = true + name = "onefetch-manifest" + repository.workspace = true + version.workspace = true [dependencies] -anyhow.workspace = true -cargo_toml = "0.21.0" -npm-package-json = "0.1.3" -strum.workspace = true + anyhow.workspace = true + cargo_toml = "0.21.0" + npm-package-json = "0.1.3" + strum.workspace = true diff --git a/manifest/tests/fixtures/cargo/Cargo.toml b/manifest/tests/fixtures/cargo/Cargo.toml index f932174b3..399eee655 100644 --- a/manifest/tests/fixtures/cargo/Cargo.toml +++ b/manifest/tests/fixtures/cargo/Cargo.toml @@ -1,20 +1,20 @@ [package] -name = "project" -version = "0.1.0" -edition = "2018" -description = "this is a description" -license = "MIT" + description = "this is a description" + edition = "2018" + license = "MIT" + name = "project" + version = "0.1.0" [dependencies] -cortex-m-rtic = "0.6.0-alpha.1" -anyhow = "1.0" + anyhow = "1.0" + cortex-m-rtic = "0.6.0-alpha.1" -[dependencies.cortex-m] -version = "0.7.1" + [dependencies.cortex-m] + version = "0.7.1" -[dependencies.cortex-m-rt] -version = "0.6.11" + [dependencies.cortex-m-rt] + version = "0.6.11" -[dependencies.stm32f4xx-hal] -version = "0.8.3" -features = ["rt", "stm32f401"] + [dependencies.stm32f4xx-hal] + features = [ "rt", "stm32f401" ] + version = "0.8.3" From ac320caa01cc5d3c92784a9f9cc4ae49cf959276 Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Thu, 5 Jun 2025 15:35:22 +0000 Subject: [PATCH 18/19] flake update --- flake.lock | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/flake.lock b/flake.lock index 5bd539d10..4803ad979 100644 --- a/flake.lock +++ b/flake.lock @@ -65,12 +65,29 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1747958103, + "narHash": "sha256-qmmFCrfBwSHoWw7cVK4Aj+fns+c54EBP8cGqp/yK410=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "fe51d34885f7b5e3e7b59572796e1bcb427eccb1", + "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" + "nixpkgs": "nixpkgs", + "treefmt": "treefmt" } }, "systems": { @@ -87,6 +104,24 @@ "repo": "default", "type": "github" } + }, + "treefmt": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1748243702, + "narHash": "sha256-9YzfeN8CB6SzNPyPm2XjRRqSixDopTapaRsnTpXUEY8=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "1f3f7b784643d488ba4bf315638b2b0a4c5fb007", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", From 1a6f4d9bffeb79d5af753404f881ddc974ead5fb Mon Sep 17 00:00:00 2001 From: Sk7Str1p3 Date: Fri, 6 Jun 2025 08:08:37 +0000 Subject: [PATCH 19/19] workflow: implement flake.lock automatic update --- .github/flake.yml | 24 ------------------------ .github/workflows/flake.yml | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 24 deletions(-) delete mode 100644 .github/flake.yml create mode 100644 .github/workflows/flake.yml diff --git a/.github/flake.yml b/.github/flake.yml deleted file mode 100644 index 36125b433..000000000 --- a/.github/flake.yml +++ /dev/null @@ -1,24 +0,0 @@ -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/.github/workflows/flake.yml b/.github/workflows/flake.yml new file mode 100644 index 000000000..137cf3a14 --- /dev/null +++ b/.github/workflows/flake.yml @@ -0,0 +1,30 @@ +name: Weekly flake.lock update + +on: + schedule: + - cron: '0 11 * * 4' + workflow_dispatch: + +jobs: + update-flake: + permissions: + contents: write + id-token: write + issues: write + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: get date + id: date + run: echo "date=$(date '+%B %d, %Y')" >> $GITHUB_OUTPUT + + - uses: DeterminateSystems/determinate-nix-action@v3 + - name: Update flake.lock + id: flake-upd + uses: DeterminateSystems/update-flake-lock@v25 + with: + pr-title: "Update flake.lock on ${{ steps.date.outputs.date }}" + pr-labels: | + dependencies + nix