@@ -1383,10 +1383,10 @@ in
1383
1383
hooks.rustfmt.packageOverrides.rustfmt = pkgs.rustfmt;
1384
1384
```
1385
1385
'' ;
1386
- type = types . submodule
1387
- ( { config , ... } : {
1388
- imports = [ hookModule ] ;
1389
- options . packageOverrides = {
1386
+ type = types . submodule ( { config , ... } : {
1387
+ imports = [ hookModule ] ;
1388
+ options = {
1389
+ packageOverrides = {
1390
1390
cargo = mkOption {
1391
1391
type = types . package ;
1392
1392
description = "The cargo package to use." ;
@@ -1396,12 +1396,80 @@ in
1396
1396
description = "The rustfmt package to use." ;
1397
1397
} ;
1398
1398
} ;
1399
-
1400
- config . extraPackages = [
1401
- config . packageOverrides . cargo
1402
- config . packageOverrides . rustfmt
1403
- ] ;
1404
- } ) ;
1399
+ settings =
1400
+ let
1401
+ nameType = types . strMatching "[][*?!0-9A-Za-z_-]+" ;
1402
+ in
1403
+ {
1404
+ all = mkOption {
1405
+ type = types . bool ;
1406
+ description = "Format all packages, and also their local path-based dependencies" ;
1407
+ default = true ;
1408
+ } ;
1409
+ check = mkOption {
1410
+ type = types . bool ;
1411
+ description = "Run rustfmt in check mode" ;
1412
+ default = false ;
1413
+ } ;
1414
+ color = mkOption {
1415
+ type = types . enum [ "auto" "always" "never" ] ;
1416
+ description = "Coloring the output" ;
1417
+ default = "always" ;
1418
+ } ;
1419
+ config = mkOption {
1420
+ type = types . attrs ;
1421
+ description = "Override configuration values" ;
1422
+ default = { } ;
1423
+ apply = config :
1424
+ let
1425
+ config' = lib . mapAttrsToList
1426
+ ( key : value : "${ key } =${ toString value } " )
1427
+ config ;
1428
+ in
1429
+ lib . optionalString ( config != { } ) ( builtins . concatStringsSep "," config' ) ;
1430
+ } ;
1431
+ config-path = mkOption {
1432
+ type = types . nullOr types . str ;
1433
+ description = "Path to rustfmt.toml config file" ;
1434
+ default = null ;
1435
+ } ;
1436
+ emit = mkOption {
1437
+ type = types . nullOr ( types . enum [ "files" "stdout" ] ) ;
1438
+ description = "What data to emit and how" ;
1439
+ default = null ;
1440
+ } ;
1441
+ files-with-diff = mkOption {
1442
+ type = types . bool ;
1443
+ description = "" ;
1444
+ default = hooks . rustfmt . settings . message-format == "short" ;
1445
+ } ;
1446
+ manifest-path = mkOption {
1447
+ type = types . nullOr types . str ;
1448
+ description = "Path to Cargo.toml" ;
1449
+ default = settings . rust . cargoManifestPath ;
1450
+ } ;
1451
+ message-format = mkOption {
1452
+ type = types . nullOr ( types . enum [ "human" "short" ] ) ;
1453
+ description = "The output format of diagnostic messages" ;
1454
+ default = null ;
1455
+ } ;
1456
+ package = mkOption {
1457
+ type = types . listOf nameType ;
1458
+ description = "Package(s) to check" ;
1459
+ default = [ ] ;
1460
+ } ;
1461
+ verbose = mkOption {
1462
+ type = types . bool ;
1463
+ description = "Use verbose output" ;
1464
+ default = false ;
1465
+ } ;
1466
+ } ;
1467
+ } ;
1468
+ config . extraPackages = [
1469
+ config . packageOverrides . cargo
1470
+ config . packageOverrides . rustfmt
1471
+ ] ;
1472
+ } ) ;
1405
1473
} ;
1406
1474
shfmt = mkOption {
1407
1475
description = "shfmt hook" ;
@@ -3261,23 +3329,36 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
3261
3329
} ;
3262
3330
rustfmt =
3263
3331
let
3332
+ mkAdditionalArgs = args : lib . optionalString ( args != "" ) " -- ${ args } " ;
3333
+
3264
3334
inherit ( hooks . rustfmt ) packageOverrides ;
3265
3335
wrapper = pkgs . symlinkJoin {
3266
3336
name = "rustfmt-wrapped" ;
3267
3337
paths = [ packageOverrides . rustfmt ] ;
3268
3338
nativeBuildInputs = [ pkgs . makeWrapper ] ;
3269
3339
postBuild = ''
3270
3340
wrapProgram $out/bin/cargo-fmt \
3271
- --prefix PATH : ${ lib . makeBinPath [ packageOverrides . cargo packageOverrides . rustfmt ] }
3341
+ --prefix PATH : ${ lib . makeBinPath ( builtins . attrValues packageOverrides ) }
3272
3342
'' ;
3273
3343
} ;
3274
3344
in
3275
3345
{
3276
3346
name = "rustfmt" ;
3277
3347
description = "Format Rust code." ;
3278
3348
package = wrapper ;
3279
- packageOverrides = { cargo = tools . cargo ; rustfmt = tools . rustfmt ; } ;
3280
- entry = "${ hooks . rustfmt . package } /bin/cargo-fmt fmt ${ cargoManifestPathArg } --all -- --color always" ;
3349
+ packageOverrides = { inherit ( tools ) cargo rustfmt ; } ;
3350
+ entry =
3351
+ let
3352
+ inherit ( hooks ) rustfmt ;
3353
+ inherit ( rustfmt ) settings ;
3354
+ cargoArgs = lib . cli . toGNUCommandLineShell {
3355
+ inherit ( settings ) all package verbose ;
3356
+ } ;
3357
+ rustfmtArgs = lib . cli . toGNUCommandLineShell {
3358
+ inherit ( settings ) check color config emit verbose ;
3359
+ } ;
3360
+ in
3361
+ "${ rustfmt . package } /bin/cargo-fmt fmt ${ cargoArgs } ${ mkAdditionalArgs rustfmtArgs } " ;
3281
3362
files = "\\ .rs$" ;
3282
3363
pass_filenames = false ;
3283
3364
} ;
0 commit comments