Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add taploFmt TOML format function to mkLib #674

Merged
merged 5 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/quick-start-workspace/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
inherit src;
};

my-workspace-toml-fmt = craneLib.taploFmt {
inherit src;
eureka-cpu marked this conversation as resolved.
Show resolved Hide resolved
taploExtraArgs = "--config ./taplo.toml";
};

# Audit dependencies
my-workspace-audit = craneLib.cargoAudit {
inherit src advisory-db;
Expand Down
13 changes: 13 additions & 0 deletions examples/quick-start-workspace/taplo.toml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions examples/quick-start/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
inherit src;
};

my-crate-toml-fmt = craneLib.taploFmt {
inherit src;
eureka-cpu marked this conversation as resolved.
Show resolved Hide resolved
taploExtraArgs = "--config ./taplo.toml";
};

# Audit dependencies
my-crate-audit = craneLib.cargoAudit {
inherit src advisory-db;
Expand Down
13 changes: 13 additions & 0 deletions examples/quick-start/taplo.toml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ let
registryFromSparse = callPackage ./registryFromSparse.nix { };
removeReferencesToVendoredSourcesHook = callPackage ./setupHooks/removeReferencesToVendoredSources.nix { };
replaceCargoLockHook = callPackage ./setupHooks/replaceCargoLockHook.nix { };
taploFmt = callPackage ./taploFmt.nix { };
urlForCargoPackage = callPackage ./urlForCargoPackage.nix { };
vendorCargoDeps = callPackage ./vendorCargoDeps.nix { };
vendorMultipleCargoDeps = callPackage ./vendorMultipleCargoDeps.nix { };
Expand Down
24 changes: 24 additions & 0 deletions lib/taploFmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{ taplo
, mkCargoDerivation
}:

{ taploExtraArgs ? ""
ipetkov marked this conversation as resolved.
Show resolved Hide resolved
, ...
}@origArgs:
let
args = builtins.removeAttrs origArgs [ "taploExtraArgs" ];
in
mkCargoDerivation (args // {
cargoArtifacts = null;
cargoVendorDir = null;
pnameSuffix = "-tomlfmt";

buildPhaseCargoCommand = "taplo fmt --check ${taploExtraArgs}";

nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ taplo ];

preInstallPhases = [ "ensureTargetDir" ] ++ (args.preInstallPhases or [ ]);
ensureTargetDir = ''
mkdir -p ''${CARGO_TARGET_DIR:-target}
'';
})
Loading