16 Creates a transformer function that writes input data to disk, transformed
17 by both the `input` and `output` arguments.
22 writeJSON = makeDataWriter { input = builtins.toJSON; output = "cp $inputPath $out"; };
23 myConfig = writeJSON "config.json" { hello = "world"; }
29 makeDataWriter :: input -> output -> nameOrPath -> data -> (any -> string) -> string -> string -> any -> derivation
31 input :: T -> string: function that takes the nix data and returns a string
32 output :: string: script that takes the $inputFile and write the result into $out
33 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.
34 data :: T: the data that will be converted.
37 makeDataWriter = lib.warn "pkgs.writers.makeDataWriter is deprecated. Use pkgs.writeTextFile." (
40 output ? "cp $inputPath $out",
44 (types.path.check nameOrPath)
45 || (builtins.match "([0-9A-Za-z._])[0-9A-Za-z._-]*" nameOrPath != null);
47 name = last (builtins.split "/" nameOrPath);
52 passAsFile = [ "input" ];
57 ${optionalString (types.path.check nameOrPath) ''
59 mkdir -p $out/$(dirname "${nameOrPath}")
60 mv tmp $out/${nameOrPath}
65 inherit (pkgs) writeText;
68 Writes the content to a JSON file.
73 writeJSON "data.json" { hello = "world"; }
76 writeJSON = (pkgs.formats.json { }).generate;
79 Writes the content to a TOML file.
84 writeTOML "data.toml" { hello = "world"; }
87 writeTOML = (pkgs.formats.toml { }).generate;
90 Writes the content to a YAML file.
95 writeYAML "data.yaml" { hello = "world"; }
98 writeYAML = (pkgs.formats.yaml { }).generate;