1
1
{ config , lib , pkgs , ... } :
2
2
let
3
- inherit ( config ) tools ;
3
+ inherit ( config ) hooks tools settings ;
4
4
cfg = config ;
5
- hooks = config . hooks ;
6
- settings = config . settings ;
7
5
inherit ( lib ) flatten mapAttrs mapAttrsToList mkDefault mkOption mkRenamedOptionModule types ;
8
6
9
7
hookModule =
142
140
description = lib . mdDoc "Additional clippy settings" ;
143
141
type = types . submodule {
144
142
imports = hookModule ;
143
+ options . packageInputs = {
144
+ cargo = mkOption {
145
+ type = types . package ;
146
+ description = lib . mdDoc "The cargo package to use for clippy" ;
147
+ } ;
148
+ clippy = mkOption {
149
+ type = types . package ;
150
+ description = lib . mdDoc "The clippy package to use for clippy" ;
151
+ } ;
152
+ } ;
145
153
options . settings = {
146
154
denyWarnings = mkOption {
147
155
type = types . bool ;
@@ -1230,6 +1238,22 @@ in
1230
1238
} ;
1231
1239
} ;
1232
1240
} ;
1241
+ rustfmt = mkOption {
1242
+ description = lib . mdDoc "Additional rustfmt settings" ;
1243
+ type = types . submodule {
1244
+ imports = hookModule ;
1245
+ options . packageInputs = {
1246
+ cargo = mkOption {
1247
+ type = types . package ;
1248
+ description = lib . mdDoc "The cargo package to use." ;
1249
+ } ;
1250
+ rustfmt = mkOption {
1251
+ type = types . package ;
1252
+ description = lib . mdDoc "The rustfmt package to use." ;
1253
+ } ;
1254
+ } ;
1255
+ } ;
1256
+ } ;
1233
1257
statix = mkOption {
1234
1258
description = lib . mdDoc "Additional statix settings" ;
1235
1259
type = types . submodule {
@@ -1252,41 +1276,18 @@ in
1252
1276
} ;
1253
1277
} ;
1254
1278
} ;
1255
- # TODO: should this be an option like `packages` or `formatters`?
1256
- # A list of packages to wrap in an env with treefmt.
1257
- # treefmt = mkOption {
1258
- # description = lib.mdDoc "Additional treefmt settings";
1259
- # type = types.submodule {
1260
- # imports = hookModule;
1261
- # options.settings = {
1262
- # package = mkOption {
1263
- # type = types.package;
1264
- # description = lib.mdDoc
1265
- # ''
1266
- # The `treefmt` package to use.
1267
- #
1268
- # Should include all the formatters configured by treefmt.
1269
- #
1270
- # For example:
1271
- # ```nix
1272
- # pkgs.writeShellApplication {
1273
- # name = "treefmt";
1274
- # runtimeInputs = [
1275
- # pkgs.treefmt
1276
- # pkgs.nixpkgs-fmt
1277
- # pkgs.black
1278
- # ];
1279
- # text =
1280
- # '''
1281
- # exec treefmt "$@"
1282
- # ''';
1283
- # }
1284
- # ```
1285
- # '';
1286
- # };
1287
- # };
1288
- # };
1289
- # };
1279
+ treefmt = mkOption {
1280
+ description = lib . mdDoc "Additional treefmt settings" ;
1281
+ type = types . submodule {
1282
+ imports = hookModule ;
1283
+ options . packageInputs = {
1284
+ treefmt = mkOption {
1285
+ type = types . package ;
1286
+ description = lib . mdDoc "The treefmt package to use." ;
1287
+ } ;
1288
+ } ;
1289
+ } ;
1290
+ } ;
1290
1291
typos = mkOption {
1291
1292
description = lib . mdDoc "Additional typos settings" ;
1292
1293
type = types . submodule {
@@ -1640,20 +1641,22 @@ in
1640
1641
} ;
1641
1642
clippy =
1642
1643
let
1644
+ inherit ( hooks . clippy ) packageInputs ;
1643
1645
wrapper = pkgs . symlinkJoin {
1644
1646
name = "clippy-wrapped" ;
1645
- paths = [ tools . clippy ] ;
1647
+ paths = [ packageInputs . clippy ] ;
1646
1648
nativeBuildInputs = [ pkgs . makeWrapper ] ;
1647
1649
postBuild = ''
1648
1650
wrapProgram $out/bin/cargo-clippy \
1649
- --prefix PATH : ${ lib . makeBinPath [ tools . cargo ] }
1651
+ --prefix PATH : ${ lib . makeBinPath [ packageInputs . cargo ] }
1650
1652
'' ;
1651
1653
} ;
1652
1654
in
1653
1655
{
1654
1656
name = "clippy" ;
1655
1657
description = "Lint Rust code." ;
1656
1658
package = wrapper ;
1659
+ packageInputs = { cargo = tools . cargo ; clippy = tools . clippy ; } ;
1657
1660
entry = "${ hooks . clippy . package } /bin/cargo-clippy clippy ${ cargoManifestPathArg } ${ lib . optionalString hooks . clippy . settings . offline "--offline" } ${ lib . optionalString hooks . clippy . settings . allFeatures "--all-features" } -- ${ lib . optionalString hooks . clippy . settings . denyWarnings "-D warnings" } " ;
1658
1661
files = "\\ .rs$" ;
1659
1662
pass_filenames = false ;
@@ -2654,20 +2657,22 @@ in
2654
2657
} ;
2655
2658
rustfmt =
2656
2659
let
2660
+ inherit ( hooks . rustfmt ) packageInputs ;
2657
2661
wrapper = pkgs . symlinkJoin {
2658
2662
name = "rustfmt-wrapped" ;
2659
- paths = [ tools . rustfmt ] ;
2663
+ paths = [ packageInputs . rustfmt ] ;
2660
2664
nativeBuildInputs = [ pkgs . makeWrapper ] ;
2661
2665
postBuild = ''
2662
2666
wrapProgram $out/bin/cargo-fmt \
2663
- --prefix PATH : ${ lib . makeBinPath [ tools . cargo tools . rustfmt ] }
2667
+ --prefix PATH : ${ lib . makeBinPath [ packageInputs . cargo packageInputs . rustfmt ] }
2664
2668
'' ;
2665
2669
} ;
2666
2670
in
2667
2671
{
2668
2672
name = "rustfmt" ;
2669
2673
description = "Format Rust code." ;
2670
2674
package = wrapper ;
2675
+ packageInputs = { cargo = tools . cargo ; rustfmt = tools . rustfmt ; } ;
2671
2676
entry = "${ hooks . rustfmt . package } /bin/cargo-fmt fmt ${ cargoManifestPathArg } -- --color always" ;
2672
2677
files = "\\ .rs$" ;
2673
2678
pass_filenames = false ;
@@ -2803,12 +2808,28 @@ in
2803
2808
files = "(\\ .json$)|(\\ .toml$)|(\\ .mli?$)" ;
2804
2809
} ;
2805
2810
treefmt =
2811
+ let
2812
+ inherit ( hooks . treefmt ) packageInputs ;
2813
+ wrapper =
2814
+ pkgs . writeShellApplication {
2815
+ name = "treefmt" ;
2816
+ runtimeInputs = [
2817
+ packageInputs . treefmt
2818
+ ] ++ builtins . attrValues ( builtins . removeAttrs packageInputs [ "treefmt" ] ) ;
2819
+
2820
+ text =
2821
+ ''
2822
+ exec treefmt "$@"
2823
+ '' ;
2824
+ } ;
2825
+ in
2806
2826
{
2807
2827
name = "treefmt" ;
2808
2828
description = "One CLI to format the code tree." ;
2809
2829
types = [ "file" ] ;
2810
2830
pass_filenames = true ;
2811
- package = tools . treefmt ;
2831
+ package = wrapper ;
2832
+ packageInputs = { treefmt = tools . treefmt ; } ;
2812
2833
entry = "${ hooks . treefmt . package } /bin/treefmt --fail-on-change" ;
2813
2834
} ;
2814
2835
typos =
0 commit comments