diff --git a/.cargo/audit.toml b/.cargo/audit.toml new file mode 100644 index 000000000..4baecd006 --- /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/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 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/.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 322457aa9..9a97dc4c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,96 +1,96 @@ [workspace.package] -authors = ["o2sh "] -edition = "2021" -license = "MIT" -version = "2.24.0" -repository = "https://github.com/o2sh/onefetch" + authors = [ "o2sh " ] + edition = "2021" + license = "MIT" + repository = "https://github.com/o2sh/onefetch" + version = "2.24.0" [workspace] -members = ["ascii", "image", "manifest"] + members = [ "ascii", "image", "manifest" ] -[workspace.dependencies] -owo-colors = "4.2.1" -anyhow = "1.0" -clap = { version = "4.5.34", features = ["derive"] } -image = { version = "0.25.6", 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.34", features = [ "derive" ] } + image = { version = "0.25.6", default-features = false, features = [ + "color_quant", + "jpeg", + "png", + "webp", + ] } + owo-colors = "4.2.1" + 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.82.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.82.0" + version.workspace = true [dependencies] -anyhow.workspace = true -askalono = "0.5.0" -byte-unit = "5.1.6" -clap.workspace = true -clap_complete = "4.5.47" -crossbeam-channel = "0.5.15" -gix = { version = "0.72.1", 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.47" + crossbeam-channel = "0.5.15" + gix = { version = "0.72.1", default-features = false, features = [ "blob-diff", - "mailmap", "index", + "mailmap", + "max-performance-safe", "status", -] } -gix-features = { version = "0.42.1", features = ["zlib-ng"] } -globset = "0.4.16" -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.41", features = ["formatting"] } -time-humanize = { version = "0.1.3", features = ["time"] } -tokei = "13.0.0-alpha.8" -typetag = "0.2" + ] } + gix-features = { version = "0.42.1", features = [ "zlib-ng" ] } + globset = "0.4.16" + 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.41", features = [ "formatting" ] } + time-humanize = { version = "0.1.3", features = [ "time" ] } + tokei = "13.0.0-alpha.8" + typetag = "0.2" [dev-dependencies] -criterion = "0.6.0" -gix-testtools = "0.16.1" -insta = { version = "1.43.1", features = ["json", "redactions"] } -rstest = "0.25.0" + criterion = "0.6.0" + gix-testtools = "0.16.1" + insta = { version = "1.43.1", features = [ "json", "redactions" ] } + rstest = "0.25.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 new file mode 100644 index 000000000..673687ccc --- /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..4803ad979 --- /dev/null +++ b/flake.lock @@ -0,0 +1,129 @@ +{ + "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" + } + }, + "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", + "treefmt": "treefmt" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "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", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..ac159fa3c --- /dev/null +++ b/flake.nix @@ -0,0 +1,193 @@ +{ + 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"; + treefmt.url = "github:numtide/treefmt-nix"; + + advisory-db = { + url = "github:rustsec/advisory-db"; + flake = false; + }; + }; + + outputs = + { + self, + nixpkgs, + crane, + flake-utils, + treefmt, + advisory-db, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + 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 = { + inherit src; + strictDeps = true; + + # Bunch of libraries required for package proper work + buildInputs = + with pkgs; + [ + # package dependencies + zstd + ] + ++ lib.optionals pkgs.stdenv.isDarwin ( + with pkgs; + [ + # additional dependencies on Darwin systems + CoreFoundation + libresolv + Security + ] + ); + # Software required for project build + nativeBuildInputs = with pkgs; [ + cmake + pkg-config + ]; + # Tools required for checks + nativeCheckInputs = with pkgs; [ git ]; + + # 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 + cargoArtifacts = craneLib.buildDepsOnly common; + + # Build the actual crate itself, reusing the dependency + # artifacts from above. + build = craneLib.buildPackage (common // { inherit cargoArtifacts; }); + in + { + checks = { + # Build the crate as part of `nix flake check` for convenience + inherit build; + + # Run clippy (and deny all warnings) on the crate source, + # again, reusing the dependency artifacts from above. + clippy = craneLib.cargoClippy ( + common + // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } + ); + + doc = craneLib.cargoDoc (common // { inherit cargoArtifacts; }); + + # Check formatting + fmt = craneLib.cargoFmt { inherit src; }; + + 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 + audit = craneLib.cargoAudit { inherit src advisory-db; }; + + # Audit licenses + 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 + nextest = craneLib.cargoNextest ( + common + // { + inherit cargoArtifacts; + partitions = 1; + partitionType = "count"; + cargoNextestPartitionsExtraArgs = "--no-tests=pass"; + } + ); + }; + + packages = rec { + onefetch-debug = craneLib.buildPackage ( + common + // { + inherit cargoArtifacts; + doCheck = false; + } + ); + onefetch = craneLib.buildPackage ( + common + // { + CARGO_PROFILE = "release"; + inherit cargoArtifacts; + doCheck = false; + } + ); + default = onefetch-debug; + }; + + apps.default = flake-utils.lib.mkApp { drv = (build // { CARGO_PROFILE = "release"; }); }; + + 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-rfc-style + ]; + }; + + formatter = (treefmt.lib.evalModule pkgs ./treefmt.nix).config.build.wrapper; + } + ); + # 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/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 b1edab274..2c88994c9 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.22.1" -npm-package-json = "0.1.3" -strum.workspace = true + anyhow.workspace = true + cargo_toml = "0.22.1" + 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" diff --git a/taplo.toml b/taplo.toml new file mode 100644 index 000000000..91ac09963 --- /dev/null +++ b/taplo.toml @@ -0,0 +1,20 @@ +# 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 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; + }; +}