Generate flake.nix from module options. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ dendrix.oeiuwq.com/Dendritic.html
dendritic nix inputs
at main 81 lines 1.6 kB view raw
1lib: 2let 3 4 isNonEmptyString = s: lib.isStringLike s && lib.stringLength (lib.trim s) > 0; 5 6 isEmpty = 7 x: 8 ( 9 (builtins.isNull x) 10 || (lib.isStringLike x && lib.stringLength (lib.trim x) == 0) 11 || (lib.isList x && lib.length x == 0) 12 || (lib.isAttrs x && x == { }) 13 ); 14 15 mergeNonEmpty = 16 from: name: 17 { 18 testEmpty ? isEmpty, 19 onEmptyMerge ? { }, 20 nonEmptyMerge ? { 21 ${name} = from.${name}; 22 }, 23 }: 24 acc: acc // (if (!from ? ${name}) || testEmpty from.${name} then onEmptyMerge else nonEmptyMerge); 25 26 mergeNonEmptyAttrs = 27 from: attrs: 28 let 29 m = mergeNonEmpty from; 30 ops = lib.mapAttrsToList (name: spec: (m name spec)) attrs; 31 in 32 lib.pipe { } ops; 33 34 nonEmptyInputs = input: { 35 nonEmptyMerge = { 36 inputs = inputsFollow input.inputs; 37 }; 38 }; 39 40 inputsFollow = lib.mapAttrs ( 41 _: input: 42 mergeNonEmptyAttrs input { 43 follows = { 44 testEmpty = v: !builtins.isString v; 45 }; 46 inputs = nonEmptyInputs input; 47 } 48 ); 49 50 inputsExpr = lib.mapAttrs ( 51 _name: input: 52 mergeNonEmptyAttrs input { 53 url = { }; 54 type = { }; 55 submodules = { }; 56 owner = { }; 57 repo = { }; 58 path = { }; 59 id = { }; 60 dir = { }; 61 narHash = { }; 62 rev = { }; 63 ref = { }; 64 host = { }; 65 flake = { 66 testEmpty = v: v; 67 nonEmptyMerge = { 68 flake = false; 69 }; 70 }; 71 follows = { 72 testEmpty = x: !builtins.isString x; 73 }; 74 inputs = nonEmptyInputs input; 75 } 76 ); 77 78in 79{ 80 inherit inputsExpr isNonEmptyString; 81}