tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
writers/data.nix: Remove duplicate implementations
Robert Hensing
2 years ago
79130267
2caca43d
+9
-23
2 changed files
expand all
collapse all
unified
split
pkgs
build-support
writers
data.nix
test.nix
+6
-22
pkgs/build-support/writers/data.nix
···
1
1
-
{ lib, runCommand, dasel }:
1
1
+
{ lib, pkgs, formats, runCommand, dasel }:
2
2
let
3
3
daselBin = lib.getExe dasel;
4
4
···
40
40
mkdir -p $out/$(dirname "${nameOrPath}")
41
41
mv tmp $out/${nameOrPath}
42
42
''}
43
43
-
'';
43
43
+
'');
44
44
45
45
-
# Writes the content to text.
46
46
-
#
47
47
-
# Example:
48
48
-
# writeText "filename.txt" "file content"
49
49
-
writeText = makeDataWriter {
50
50
-
input = toString;
51
51
-
output = "cp $inputPath $out";
52
52
-
};
45
45
+
inherit (pkgs) writeText;
53
46
54
47
# Writes the content to a JSON file.
55
48
#
56
49
# Example:
57
50
# writeJSON "data.json" { hello = "world"; }
58
58
-
writeJSON = makeDataWriter {
59
59
-
input = builtins.toJSON;
60
60
-
output = "${daselBin} -f $inputPath -r json -w json > $out";
61
61
-
};
51
51
+
writeJSON = (pkgs.formats.json {}).generate;
62
52
63
53
# Writes the content to a TOML file.
64
54
#
65
55
# Example:
66
56
# writeTOML "data.toml" { hello = "world"; }
67
67
-
writeTOML = makeDataWriter {
68
68
-
input = builtins.toJSON;
69
69
-
output = "${daselBin} -f $inputPath -r json -w toml > $out";
70
70
-
};
57
57
+
writeTOML = (pkgs.formats.toml {}).generate;
71
58
72
59
# Writes the content to a YAML file.
73
60
#
74
61
# Example:
75
62
# writeYAML "data.yaml" { hello = "world"; }
76
76
-
writeYAML = makeDataWriter {
77
77
-
input = builtins.toJSON;
78
78
-
output = "${daselBin} -f $inputPath -r json -w yaml > $out";
79
79
-
};
63
63
+
writeYAML = (pkgs.formats.yaml {}).generate;
80
64
}
+3
-1
pkgs/build-support/writers/test.nix
···
261
261
262
262
toml = expectDataEqual {
263
263
file = writeTOML "data.toml" { hello = "world"; };
264
264
-
expected = "hello = 'world'\n";
264
264
+
expected = ''
265
265
+
hello = "world"
266
266
+
'';
265
267
};
266
268
267
269
yaml = expectDataEqual {