mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-29 00:53:57 +00:00
4f0dadbf38
After final improvements to the official formatter implementation, this commit now performs the first treewide reformat of Nix files using it. This is part of the implementation of RFC 166. Only "inactive" files are reformatted, meaning only files that aren't being touched by any PR with activity in the past 2 months. This is to avoid conflicts for PRs that might soon be merged. Later we can do a full treewide reformat to get the rest, which should not cause as many conflicts. A CI check has already been running for some time to ensure that new and already-formatted files are formatted, so the files being reformatted here should also stay formatted. This commit was automatically created and can be verified using nix-builda08b3a4d19
.tar.gz \ --argstr baseRevb32a094368
result/bin/apply-formatting $NIXPKGS_PATH
100 lines
2.2 KiB
Nix
100 lines
2.2 KiB
Nix
{
|
|
lib,
|
|
pkgs,
|
|
formats,
|
|
runCommand,
|
|
}:
|
|
let
|
|
inherit (lib)
|
|
last
|
|
optionalString
|
|
types
|
|
;
|
|
in
|
|
{
|
|
/**
|
|
Creates a transformer function that writes input data to disk, transformed
|
|
by both the `input` and `output` arguments.
|
|
|
|
# Example
|
|
|
|
```nix
|
|
writeJSON = makeDataWriter { input = builtins.toJSON; output = "cp $inputPath $out"; };
|
|
myConfig = writeJSON "config.json" { hello = "world"; }
|
|
```
|
|
|
|
# Type
|
|
|
|
```
|
|
makeDataWriter :: input -> output -> nameOrPath -> data -> (any -> string) -> string -> string -> any -> derivation
|
|
|
|
input :: T -> string: function that takes the nix data and returns a string
|
|
output :: string: script that takes the $inputFile and write the result into $out
|
|
nameOrPath :: string: if the name contains a / the files gets written to a sub-folder of $out. The derivation name is the basename of this argument.
|
|
data :: T: the data that will be converted.
|
|
```
|
|
*/
|
|
makeDataWriter = lib.warn "pkgs.writers.makeDataWriter is deprecated. Use pkgs.writeTextFile." (
|
|
{
|
|
input ? lib.id,
|
|
output ? "cp $inputPath $out",
|
|
}:
|
|
nameOrPath: data:
|
|
assert
|
|
(types.path.check nameOrPath)
|
|
|| (builtins.match "([0-9A-Za-z._])[0-9A-Za-z._-]*" nameOrPath != null);
|
|
let
|
|
name = last (builtins.split "/" nameOrPath);
|
|
in
|
|
runCommand name
|
|
{
|
|
input = input data;
|
|
passAsFile = [ "input" ];
|
|
}
|
|
''
|
|
${output}
|
|
|
|
${optionalString (types.path.check nameOrPath) ''
|
|
mv $out tmp
|
|
mkdir -p $out/$(dirname "${nameOrPath}")
|
|
mv tmp $out/${nameOrPath}
|
|
''}
|
|
''
|
|
);
|
|
|
|
inherit (pkgs) writeText;
|
|
|
|
/**
|
|
Writes the content to a JSON file.
|
|
|
|
# Example
|
|
|
|
```nix
|
|
writeJSON "data.json" { hello = "world"; }
|
|
```
|
|
*/
|
|
writeJSON = (pkgs.formats.json { }).generate;
|
|
|
|
/**
|
|
Writes the content to a TOML file.
|
|
|
|
# Example
|
|
|
|
```nix
|
|
writeTOML "data.toml" { hello = "world"; }
|
|
```
|
|
*/
|
|
writeTOML = (pkgs.formats.toml { }).generate;
|
|
|
|
/**
|
|
Writes the content to a YAML file.
|
|
|
|
# Example
|
|
|
|
```nix
|
|
writeYAML "data.yaml" { hello = "world"; }
|
|
```
|
|
*/
|
|
writeYAML = (pkgs.formats.yaml { }).generate;
|
|
}
|