at 25.11-pre 79 lines 1.9 kB view raw
1{ 2 lib, 3 buildPlatform, 4 callPackage, 5 kaem, 6 mescc-tools-extra, 7 checkMeta, 8}: 9rec { 10 derivationWithMeta = 11 attrs: 12 let 13 passthru = attrs.passthru or { }; 14 validity = checkMeta.assertValidity { inherit meta attrs; }; 15 meta = checkMeta.commonMeta { inherit validity attrs; }; 16 baseDrv = derivation ( 17 { 18 inherit (buildPlatform) system; 19 inherit (meta) name; 20 } 21 // (builtins.removeAttrs attrs [ 22 "meta" 23 "passthru" 24 ]) 25 ); 26 passthru' = 27 passthru 28 // lib.optionalAttrs (passthru ? tests) { 29 tests = lib.mapAttrs (_: f: f baseDrv) passthru.tests; 30 }; 31 in 32 lib.extendDerivation validity.handled ( 33 { 34 inherit meta; 35 passthru = passthru'; 36 } 37 // passthru' 38 ) baseDrv; 39 40 writeTextFile = 41 { 42 name, # the name of the derivation 43 text, 44 executable ? false, # run chmod +x ? 45 destination ? "", # relative path appended to $out eg "/bin/foo" 46 }: 47 derivationWithMeta { 48 inherit name text; 49 passAsFile = [ "text" ]; 50 51 builder = "${kaem}/bin/kaem"; 52 args = [ 53 "--verbose" 54 "--strict" 55 "--file" 56 (builtins.toFile "write-text-file.kaem" ( 57 '' 58 target=''${out}''${destination} 59 '' 60 + lib.optionalString (builtins.dirOf destination == ".") '' 61 mkdir -p ''${out}''${destinationDir} 62 '' 63 + '' 64 cp ''${textPath} ''${target} 65 '' 66 + lib.optionalString executable '' 67 chmod 555 ''${target} 68 '' 69 )) 70 ]; 71 72 PATH = lib.makeBinPath [ mescc-tools-extra ]; 73 destinationDir = builtins.dirOf destination; 74 inherit destination; 75 }; 76 77 writeText = name: text: writeTextFile { inherit name text; }; 78 79}