default.nix (1505B)
1 { writeText, lib }: 2 let 3 inherit (lib.attrsets) mapAttrsToList; 4 visit = 5 prefix: attrset: 6 let 7 qprint = msg: builtins.replaceStrings [ "\n" "=" "\"" "$" ] [ "=0A" "=3D" "=22" "=24" ] msg; 8 l = mapAttrsToList ( 9 filename: 10 { 11 type ? "f", 12 mode ? null, 13 target ? null, 14 contents ? null, 15 file ? null, 16 major ? null, 17 minor ? null, 18 uid ? 0, 19 gid ? 0, 20 }: 21 let 22 mode' = if mode != null then mode else (if type == "d" then "0755" else "0644"); 23 pathname = "${prefix}/${filename}"; 24 line = "${pathname} ${type} ${mode'} ${toString uid} ${toString gid}"; 25 in 26 if type == "f" then 27 "${line} echo -n \"${qprint file}\" |qprint -d" 28 else if type == "d" then 29 (visit pathname contents) + "\n" + line 30 else if type == "c" then 31 "${line} ${major} ${minor}" 32 else if type == "b" then 33 "${line} ${major} ${minor}" 34 else if type == "s" then 35 "${line} ${target}" 36 else if type == "l" then 37 "${pathname} l ${target}" 38 else if type == "i" then 39 "${line} f" 40 else 41 line 42 ) attrset; 43 in 44 builtins.concatStringsSep "\n" l; 45 in 46 { 47 write = filename: attrset: writeText filename (visit "" attrset); 48 dir = contents: { 49 type = "d"; 50 inherit contents; 51 }; 52 symlink = target: { 53 type = "s"; 54 inherit target; 55 }; 56 }