From ceecc82aae3dc1c8fa59523635e6040363c1de5c Mon Sep 17 00:00:00 2001 From: ulic-youthlic Date: Fri, 6 Jun 2025 11:02:49 +0800 Subject: [PATCH] Add treefmt-nix for formatting all the files --- .typos.toml | 3 +- .zed/settings.json | 3 +- .../radicle-explorer/youthlic-seed-avatar.jpg | Bin .../radicle-explorer/youthlic-seed-header.png | Bin flake.lock | 37 ++++++++- flake.nix | 66 +++++++++++++++- home/modules/programs/starship/config.toml | 2 - pkgs/default.nix | 5 +- .../default.nix => radicle-explorer.nix} | 9 ++- templates/rust/.cargo/audit.toml | 4 +- templates/rust/deny.toml | 74 +++++++++--------- 11 files changed, 151 insertions(+), 52 deletions(-) rename {pkgs => assets}/radicle-explorer/youthlic-seed-avatar.jpg (100%) rename {pkgs => assets}/radicle-explorer/youthlic-seed-header.png (100%) rename pkgs/{radicle-explorer/default.nix => radicle-explorer.nix} (67%) diff --git a/.typos.toml b/.typos.toml index e296d3d..5ca76d9 100644 --- a/.typos.toml +++ b/.typos.toml @@ -4,9 +4,10 @@ ignore-parent = true ignore-hidden = false ignore-files = true ignore-vcs = true -extend-exclude = ["secrets/", ".git/", "public-key.txt"] +extend-exclude = ["secrets/*", ".git/*", "**/public-key.txt"] [default] +binary = false check-filename = true check-file = true unicode = true diff --git a/.zed/settings.json b/.zed/settings.json index 2c63c08..0967ef4 100644 --- a/.zed/settings.json +++ b/.zed/settings.json @@ -1,2 +1 @@ -{ -} +{} diff --git a/pkgs/radicle-explorer/youthlic-seed-avatar.jpg b/assets/radicle-explorer/youthlic-seed-avatar.jpg similarity index 100% rename from pkgs/radicle-explorer/youthlic-seed-avatar.jpg rename to assets/radicle-explorer/youthlic-seed-avatar.jpg diff --git a/pkgs/radicle-explorer/youthlic-seed-header.png b/assets/radicle-explorer/youthlic-seed-header.png similarity index 100% rename from pkgs/radicle-explorer/youthlic-seed-header.png rename to assets/radicle-explorer/youthlic-seed-header.png diff --git a/flake.lock b/flake.lock index 494f726..3a3d491 100644 --- a/flake.lock +++ b/flake.lock @@ -605,6 +605,22 @@ "type": "github" } }, + "nixpkgs_3": { + "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" + } + }, "nur": { "inputs": { "flake-parts": [ @@ -665,7 +681,8 @@ "nixpkgs": "nixpkgs_2", "nur-rycee": "nur-rycee", "sops-nix": "sops-nix", - "stylix": "stylix" + "stylix": "stylix", + "treefmt-nix": "treefmt-nix_2" } }, "rust-overlay": { @@ -904,6 +921,24 @@ "type": "github" } }, + "treefmt-nix_2": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1748243702, + "narHash": "sha256-9YzfeN8CB6SzNPyPm2XjRRqSixDopTapaRsnTpXUEY8=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "1f3f7b784643d488ba4bf315638b2b0a4c5fb007", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + }, "xwayland-satellite-stable": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index a663bd3..50ad429 100644 --- a/flake.nix +++ b/flake.nix @@ -133,6 +133,12 @@ utils.follows = "flake-utils"; }; }; + + treefmt-nix = { + type = "github"; + owner = "numtide"; + repo = "treefmt-nix"; + }; }; outputs = { self, @@ -153,6 +159,7 @@ systems = flake-utils.lib.defaultSystems; imports = [ inputs.home-manager.flakeModules.home-manager + inputs.treefmt-nix.flakeModule nixos home deploy @@ -169,11 +176,10 @@ allowUnfree = true; }; }; - formatter = pkgs.alejandra; packages = import ./pkgs ( args // { - inherit inputs; + inherit inputs rootPath; } ); devShells.default = pkgs.mkShell { @@ -185,6 +191,62 @@ nvfetcher ]; }; + treefmt = { + programs = { + alejandra = { + enable = true; + excludes = ["pkgs/_sources/*.nix"]; + }; + biome = { + enable = true; + includes = ["*.json"]; + excludes = ["pkgs/_sources/*.json"]; + settings = { + javascript.formatter.enabled = false; + css.formatter.enabled = false; + }; + }; + dprint = { + enable = true; + includes = ["*.md" "*.toml" "*.yaml"]; + excludes = ["secrets/*.yaml"]; + settings = { + plugins = pkgs.dprint-plugins.getPluginList (plugins: + with plugins; [ + dprint-plugin-toml + dprint-plugin-markdown + g-plane-pretty_yaml + ]); + }; + }; + just = { + enable = true; + includes = [".justfile"]; + }; + typos = let + config = ./.typos.toml |> builtins.readFile |> builtins.fromTOML; + in { + enable = true; + includes = ["*"]; + excludes = ["assets/*"] ++ config.files.extend-exclude; + configFile = "${toString ./.typos.toml}"; + # Disable all extra option in treefmt module. + # Use config file. + sort = false; + isolated = false; + hidden = false; + noIgnore = false; + noIgnoreDot = false; + noIgnoreGlobal = false; + noIgnoreParent = false; + noIgnoreVCS = false; + binary = false; + noCheckFilenames = false; + noCheckFiles = false; + noUnicode = false; + }; + }; + }; }; flake = { overlays = { diff --git a/home/modules/programs/starship/config.toml b/home/modules/programs/starship/config.toml index 09f1906..c56813b 100644 --- a/home/modules/programs/starship/config.toml +++ b/home/modules/programs/starship/config.toml @@ -51,7 +51,6 @@ repo_root_style = "bold green" use_os_path_sep = false read_only = " 󰌾" - [aws] symbol = " " @@ -210,4 +209,3 @@ symbol = " " [zig] symbol = " " - diff --git a/pkgs/default.nix b/pkgs/default.nix index c899ec2..94d4ac2 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,10 +1,11 @@ { pkgs, inputs, + rootPath, ... }: let srcs = pkgs.callPackage ./_sources/generated.nix {}; - callPackage = pkgs.lib.callPackageWith (pkgs // {inherit inputs srcs callPackage;}); + callPackage = pkgs.lib.callPackageWith (pkgs // {inherit inputs srcs callPackage rootPath;}); in { pinentry-selector = callPackage ./pinentry-selector.nix {}; @@ -13,7 +14,7 @@ in rime-ice = callPackage ./rime-ice.nix {}; dioxionary = callPackage ./dioxionary.nix {}; spotifyx = callPackage ./spotifyx.nix {}; - radicle-explorer = callPackage ./radicle-explorer {}; + radicle-explorer = callPackage ./radicle-explorer.nix {}; TrackersListCollection = callPackage ./TrackersListCollection.nix {}; wshowkeys-mao = callPackage ./wshowkeys-mao.nix {}; OuterWildsTextAdventure = callPackage ./OuterWildsTextAdventure.nix {}; diff --git a/pkgs/radicle-explorer/default.nix b/pkgs/radicle-explorer.nix similarity index 67% rename from pkgs/radicle-explorer/default.nix rename to pkgs/radicle-explorer.nix index 0533829..790cd47 100644 --- a/pkgs/radicle-explorer/default.nix +++ b/pkgs/radicle-explorer.nix @@ -1,4 +1,7 @@ -{pkgs}: +{ + pkgs, + rootPath, +}: (pkgs.radicle-explorer.withConfig { preferredSeeds = [ { @@ -26,7 +29,7 @@ postInstall = (prev.postInstall or "") + '' - ln -s ${./youthlic-seed-header.png} $out/images/youthlic-seed-header.png - ln -s ${./youthlic-seed-avatar.jpg} $out/images/youthlic-seed-avatar.jpg + ln -s ${rootPath + "/assets/radicle-explorer/youthlic-seed-header.png"} $out/images/youthlic-seed-header.png + ln -s ${rootPath + "/assets/radicle-explorer/youthlic-seed-avatar.jpg"} $out/images/youthlic-seed-avatar.jpg ''; }) diff --git a/templates/rust/.cargo/audit.toml b/templates/rust/.cargo/audit.toml index fd7bf33..c81ec0e 100644 --- a/templates/rust/.cargo/audit.toml +++ b/templates/rust/.cargo/audit.toml @@ -12,8 +12,8 @@ stale = false [output] deny = ["unmaintained"] # exit on error if unmaintained dependencies are found -format = "terminal" # "terminal" (human readable report) or "json" -quiet = false # Only print information on error +format = "terminal" # "terminal" (human readable report) or "json" +quiet = false # Only print information on error show_tree = true [target] diff --git a/templates/rust/deny.toml b/templates/rust/deny.toml index 295c557..6f58a9b 100644 --- a/templates/rust/deny.toml +++ b/templates/rust/deny.toml @@ -25,11 +25,11 @@ targets = [ # The triple can be any string, but only the target triples built in to # rustc (as of 1.40) can be checked against actual config expressions - #"x86_64-unknown-linux-musl", + # "x86_64-unknown-linux-musl", # You can also specify which target_features you promise are enabled for a # particular target. target_features are currently not validated against # the actual valid features supported by the target architecture. - #{ triple = "wasm32-unknown-unknown", features = ["atomics"] }, + # { triple = "wasm32-unknown-unknown", features = ["atomics"] }, ] # When creating the dependency graph used as the source of truth when checks are # executed, this field can be used to prune crates from the graph, removing them @@ -38,7 +38,7 @@ targets = [ # they are connected to another crate in the graph that hasn't been pruned, # so it should be used with care. The identifiers are [Package ID Specifications] # (https://doc.rust-lang.org/cargo/reference/pkgid-spec.html) -#exclude = [] +# exclude = [] # If true, metadata will be collected with `--all-features`. Note that this can't # be toggled off if true, if you want to conditionally enable `--all-features` it # is recommended to pass `--all-features` on the cmd line instead @@ -48,7 +48,7 @@ all-features = false no-default-features = false # If set, these feature will be enabled when collecting metadata. If `--features` # is specified on the cmd line they will take precedence over this option. -#features = [] +# features = [] # The output table provides options for how/if diagnostics are outputted [output] @@ -64,22 +64,22 @@ feature-depth = 1 # https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html [advisories] # The path where the advisory databases are cloned/fetched into -#db-path = "$CARGO_HOME/advisory-dbs" +# db-path = "$CARGO_HOME/advisory-dbs" # The url(s) of the advisory databases to use -#db-urls = ["https://github.com/rustsec/advisory-db"] +# db-urls = ["https://github.com/rustsec/advisory-db"] # A list of advisory IDs to ignore. Note that ignored advisories will still # output a note when they are encountered. ignore = [ - #"RUSTSEC-0000-0000", - #{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" }, - #"a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish - #{ crate = "a-crate-that-is-yanked@0.1.1", reason = "you can specify why you are ignoring the yanked crate" }, + # "RUSTSEC-0000-0000", + # { id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" }, + # "a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish + # { crate = "a-crate-that-is-yanked@0.1.1", reason = "you can specify why you are ignoring the yanked crate" }, ] # If this is true, then cargo deny will use the git executable to fetch advisory database. # If this is false, then it uses a built-in git library. # Setting this to true can be helpful if you have special authentication requirements that cargo-deny does not support. # See Git Authentication for more information about setting up git authentication. -#git-fetch-with-cli = true +# git-fetch-with-cli = true # This section is considered when running `cargo deny check licenses` # More documentation for the licenses section can be found here: @@ -90,9 +90,9 @@ ignore = [ # [possible values: any SPDX 3.11 short identifier (+ optional exception)]. allow = [ "MIT", - #"Apache-2.0", - #"Apache-2.0 WITH LLVM-exception", - "GPL-3.0" + # "Apache-2.0", + # "Apache-2.0 WITH LLVM-exception", + "GPL-3.0", ] # The confidence threshold for detecting a license from license text. # The higher the value, the more closely the license text must be to the @@ -104,26 +104,26 @@ confidence-threshold = 0.8 exceptions = [ # Each entry is the crate and version constraint, and its specific allow # list - #{ allow = ["Zlib"], crate = "adler32" }, + # { allow = ["Zlib"], crate = "adler32" }, ] # Some crates don't have (easily) machine readable licensing information, # adding a clarification entry for it allows you to manually specify the # licensing information -#[[licenses.clarify]] +# [[licenses.clarify]] # The package spec the clarification applies to -#crate = "ring" +# crate = "ring" # The SPDX expression for the license requirements of the crate -#expression = "MIT AND ISC AND OpenSSL" +# expression = "MIT AND ISC AND OpenSSL" # One or more files in the crate's source used as the "source of truth" for # the license expression. If the contents match, the clarification will be used # when running the license check, otherwise the clarification will be ignored # and the crate will be checked normally, which may produce warnings or errors # depending on the rest of your configuration -#license-files = [ +# license-files = [ # Each entry is a crate relative path, and the (opaque) hash of its contents -#{ path = "LICENSE", hash = 0xbd0eed23 } -#] +# { path = "LICENSE", hash = 0xbd0eed23 } +# ] [licenses.private] # If true, ignores workspace crates that aren't published, or are only @@ -135,7 +135,7 @@ ignore = false # is only published to private registries, and ignore is true, the crate will # not have its license(s) checked registries = [ - #"https://sekretz.com/registry + # "https://sekretz.com/registry ] # This section is considered when running `cargo deny check bans`. @@ -162,27 +162,27 @@ workspace-default-features = "allow" external-default-features = "allow" # List of crates that are allowed. Use with care! allow = [ - #"ansi_term@0.11.0", - #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason it is allowed" }, + # "ansi_term@0.11.0", + # { crate = "ansi_term@0.11.0", reason = "you can specify a reason it is allowed" }, ] # List of crates to deny deny = [ - #"ansi_term@0.11.0", - #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason it is banned" }, + # "ansi_term@0.11.0", + # { crate = "ansi_term@0.11.0", reason = "you can specify a reason it is banned" }, # Wrapper crates can optionally be specified to allow the crate when it # is a direct dependency of the otherwise banned crate - #{ crate = "ansi_term@0.11.0", wrappers = ["this-crate-directly-depends-on-ansi_term"] }, + # { crate = "ansi_term@0.11.0", wrappers = ["this-crate-directly-depends-on-ansi_term"] }, ] # List of features to allow/deny # Each entry the name of a crate and a version range. If version is # not specified, all versions will be matched. -#[[bans.features]] -#crate = "reqwest" +# [[bans.features]] +# crate = "reqwest" # Features to not allow -#deny = ["json"] +# deny = ["json"] # Features to allow -#allow = [ +# allow = [ # "rustls", # "__rustls", # "__tls", @@ -192,23 +192,23 @@ deny = [ # "rustls-tls-webpki-roots", # "tokio-rustls", # "webpki-roots", -#] +# ] # If true, the allowed features must exactly match the enabled feature set. If # this is set there is no point setting `deny` -#exact = true +# exact = true # Certain crates/versions that will be skipped when doing duplicate detection. skip = [ - #"ansi_term@0.11.0", - #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason why it can't be updated/removed" }, + # "ansi_term@0.11.0", + # { crate = "ansi_term@0.11.0", reason = "you can specify a reason why it can't be updated/removed" }, ] # Similarly to `skip` allows you to skip certain crates during duplicate # detection. Unlike skip, it also includes the entire tree of transitive # dependencies starting at the specified crate, up to a certain depth, which is # by default infinite. skip-tree = [ - #"ansi_term@0.11.0", # will be skipped along with _all_ of its direct and transitive dependencies - #{ crate = "ansi_term@0.11.0", depth = 20 }, + # "ansi_term@0.11.0", # will be skipped along with _all_ of its direct and transitive dependencies + # { crate = "ansi_term@0.11.0", depth = 20 }, ] # This section is considered when running `cargo deny check sources`.