liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

default.nix (1576B)


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