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