liminix-fork/pkgs/pseudofile/default.nix
Daniel Barlow 45025f128a switch to s6-linux-init and s6-rc
This is at the point where it runs a getty and a pile of s6-supervise
processes, though it doesn't seem to run the things being supervised
2022-09-21 23:01:21 +01:00

37 lines
1.2 KiB
Nix

{
writeText
, lib
}:
filename : attrset :
let
inherit (lib.debug) traceSeqN;
inherit (lib.attrsets) mapAttrsToList;
visit = prefix: attrset:
let
qprint = msg : builtins.replaceStrings ["\n" "=" "\""] ["=0A" "=3D" "=22"] msg;
l =
mapAttrsToList
(filename: attrs:
let
attrs' = {type = "f"; } // attrs;
mode = if attrs ? mode then attrs.mode else
(if attrs'.type == "d" then "0755" else "0644");
line = "${prefix}/${filename} ${attrs'.type} ${mode} 0 0";
in
if attrs'.type == "f" then
"${line} echo -n \"${qprint attrs'.file}\" |qprint -d"
else if attrs'.type == "d" then
(visit "${prefix}/${filename}" attrs.contents) +
"\n" + line
else if attrs'.type == "s" then
"${line} ${attrs'.target}"
else if attrs'.type == "l" then
"${prefix}/${filename} l ${attrs'.target}"
else if attrs'.type == "i" then
"${line} ${attrs.subtype}"
else
line)
attrset;
in builtins.concatStringsSep "\n" l;
res = (visit "" attrset);
in writeText filename res