Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 141 lines 4.1 kB view raw
1{ 2 stdenv, 3 lib, 4 writeText, 5 makeWrapper, 6 factor-lang, 7 factor-no-gui, 8 librsvg, 9 gdk-pixbuf, 10}@initAttrs: 11 12drvArgs: 13 14let 15 flang = factor-lang; # workaround to satisfy nixf-tidy 16in 17(stdenv.mkDerivation drvArgs).overrideAttrs ( 18 finalAttrs: 19 { 20 name ? "${finalAttrs.pname}-${finalAttrs.version}", 21 factor-lang ? if enableUI then flang else factor-no-gui, 22 enableUI ? false, 23 # Allow overriding the path to the deployed vocabulary name. A 24 # $vocabName.factor file must exist! 25 vocabName ? finalAttrs.pname or name, 26 # Allow overriding the binary name 27 binName ? lib.last (lib.splitString "/" vocabName), 28 # Extra libraries needed 29 extraLibs ? [ ], 30 # Extra binaries in PATH 31 extraPaths ? [ ], 32 # Extra vocabularies needed by this application 33 extraVocabs ? [ ], 34 deployScriptText ? '' 35 USING: command-line io io.backend io.pathnames kernel namespaces sequences 36 tools.deploy tools.deploy.config tools.deploy.backend vocabs.loader ; 37 38 IN: deploy-me 39 40 : load-and-deploy ( path/vocab -- ) 41 normalize-path [ 42 parent-directory add-vocab-root 43 ] [ 44 file-name dup reload deploy 45 ] bi ; 46 47 : deploy-vocab ( path/vocab path/target -- ) 48 normalize-path deploy-directory set 49 f open-directory-after-deploy? set 50 load-and-deploy ; 51 52 : deploy-me ( -- ) 53 command-line get dup length 2 = [ 54 first2 deploy-vocab 55 ] [ 56 drop 57 "usage: deploy-me <PATH-TO-VOCAB> <TARGET-DIR>" print 58 nl 59 ] if ; 60 61 MAIN: deploy-me 62 '', 63 ... 64 }@attrs: 65 let 66 deployScript = writeText "deploy-me.factor" finalAttrs.deployScriptText; 67 wrapped-factor = finalAttrs.factor-lang.override { 68 inherit (finalAttrs) extraLibs extraVocabs; 69 doInstallCheck = false; 70 }; 71 runtimePaths = with finalAttrs.wrapped-factor; defaultBins ++ binPackages ++ finalAttrs.extraPaths; 72 in 73 { 74 inherit 75 enableUI 76 vocabName 77 deployScriptText 78 extraLibs 79 extraPaths 80 extraVocabs 81 binName 82 factor-lang 83 wrapped-factor 84 ; 85 nativeBuildInputs = [ 86 makeWrapper 87 (lib.hiPrio finalAttrs.wrapped-factor) 88 ] ++ attrs.nativeBuildInputs or [ ]; 89 90 buildInputs = (lib.optional enableUI gdk-pixbuf) ++ attrs.buildInputs or [ ]; 91 92 buildPhase = 93 attrs.buildPhase or '' 94 runHook preBuild 95 vocabBaseName=$(basename "$vocabName") 96 mkdir -p "$out/lib/factor" "$TMPDIR/.cache" 97 export XDG_CACHE_HOME="$TMPDIR/.cache" 98 99 factor "${deployScript}" "./$vocabName" "$out/lib/factor" 100 cp "$TMPDIR/factor-temp"/*.image "$out/lib/factor/$vocabBaseName" 101 runHook postBuild 102 ''; 103 104 __structuredAttrs = true; 105 106 installPhase = 107 attrs.installPhase or ( 108 '' 109 runHook preInstall 110 '' 111 + (lib.optionalString finalAttrs.enableUI '' 112 # Set Gdk pixbuf loaders file to the one from the build dependencies here 113 unset GDK_PIXBUF_MODULE_FILE 114 # Defined in gdk-pixbuf setup hook 115 findGdkPixbufLoaders "${librsvg}" 116 appendToVar makeWrapperArgs --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" 117 appendToVar makeWrapperArgs --prefix LD_LIBRARY_PATH : /run/opengl-driver/lib 118 '') 119 + (lib.optionalString (wrapped-factor.runtimeLibs != [ ])) '' 120 appendToVar makeWrapperArgs --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath wrapped-factor.runtimeLibs}" 121 '' 122 + '' 123 mkdir -p "$out/bin" 124 makeWrapper "$out/lib/factor/$vocabBaseName/$vocabBaseName" \ 125 "$out/bin/$binName" \ 126 --prefix PATH : "${lib.makeBinPath runtimePaths}" \ 127 "''${makeWrapperArgs[@]}" 128 runHook postInstall 129 '' 130 ); 131 132 passthru = { 133 vocab = finalAttrs.src; 134 } // attrs.passthru or { }; 135 136 meta = { 137 platforms = wrapped-factor.meta.platforms; 138 mainProgram = finalAttrs.binName; 139 } // attrs.meta or { }; 140 } 141)