2022-09-22 00:01:21 +02:00
|
|
|
{
|
|
|
|
writeText
|
|
|
|
, lib
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
inherit (lib.attrsets) mapAttrsToList;
|
|
|
|
visit = prefix: attrset:
|
|
|
|
let
|
2023-03-04 01:23:21 +01:00
|
|
|
qprint = msg : builtins.replaceStrings
|
2023-03-05 22:33:51 +01:00
|
|
|
["\n" "=" "\"" "$" ]
|
|
|
|
["=0A" "=3D" "=22" "=24"]
|
|
|
|
msg;
|
2022-09-22 00:01:21 +02:00
|
|
|
l =
|
|
|
|
mapAttrsToList
|
2023-04-04 22:11:28 +02:00
|
|
|
(filename: {
|
|
|
|
type ? "f"
|
|
|
|
, mode ? null
|
|
|
|
, target ? null
|
|
|
|
, contents ? null
|
|
|
|
, file ? null
|
|
|
|
, major ? null
|
|
|
|
, minor ? null
|
2023-04-14 01:18:27 +02:00
|
|
|
, uid ? 0
|
|
|
|
, gid ? 0
|
2023-04-04 22:11:28 +02:00
|
|
|
}:
|
2022-09-22 00:01:21 +02:00
|
|
|
let
|
2023-04-04 22:11:28 +02:00
|
|
|
mode' = if mode != null then mode else
|
|
|
|
(if type == "d" then "0755" else "0644");
|
|
|
|
pathname = "${prefix}/${filename}";
|
2023-04-14 01:18:27 +02:00
|
|
|
line = "${pathname} ${type} ${mode'} ${toString uid} ${toString gid}";
|
2022-09-22 00:01:21 +02:00
|
|
|
in
|
2023-04-04 22:11:28 +02:00
|
|
|
if type == "f" then
|
|
|
|
"${line} echo -n \"${qprint file}\" |qprint -d"
|
|
|
|
else if type == "d" then
|
|
|
|
(visit pathname contents) + "\n" + line
|
|
|
|
else if type == "c" then "${line} ${major} ${minor}"
|
|
|
|
else if type == "b" then "${line} ${major} ${minor}"
|
|
|
|
else if type == "s" then "${line} ${target}"
|
|
|
|
else if type == "l" then "${pathname} l ${target}"
|
2023-04-05 00:23:22 +02:00
|
|
|
else if type == "i" then "${line} f"
|
2023-04-04 22:11:28 +02:00
|
|
|
else line)
|
2022-09-22 00:01:21 +02:00
|
|
|
attrset;
|
|
|
|
in builtins.concatStringsSep "\n" l;
|
2022-09-26 19:27:43 +02:00
|
|
|
in {
|
|
|
|
write = filename : attrset : writeText filename (visit "" attrset);
|
|
|
|
dir = contents: { type = "d"; inherit contents; };
|
|
|
|
symlink = target: { type = "s"; inherit target; };
|
|
|
|
}
|