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 ]
89 ++ attrs.nativeBuildInputs or [ ];
90
91 buildInputs = (lib.optional enableUI gdk-pixbuf) ++ attrs.buildInputs or [ ];
92
93 buildPhase =
94 attrs.buildPhase or ''
95 runHook preBuild
96 vocabBaseName=$(basename "$vocabName")
97 mkdir -p "$out/lib/factor" "$TMPDIR/.cache"
98 export XDG_CACHE_HOME="$TMPDIR/.cache"
99
100 factor "${deployScript}" "./$vocabName" "$out/lib/factor"
101 cp "$TMPDIR/factor-temp"/*.image "$out/lib/factor/$vocabBaseName"
102 runHook postBuild
103 '';
104
105 __structuredAttrs = true;
106
107 installPhase =
108 attrs.installPhase or (
109 ''
110 runHook preInstall
111 ''
112 + (lib.optionalString finalAttrs.enableUI ''
113 # Set Gdk pixbuf loaders file to the one from the build dependencies here
114 unset GDK_PIXBUF_MODULE_FILE
115 # Defined in gdk-pixbuf setup hook
116 findGdkPixbufLoaders "${librsvg}"
117 appendToVar makeWrapperArgs --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE"
118 appendToVar makeWrapperArgs --prefix LD_LIBRARY_PATH : /run/opengl-driver/lib
119 '')
120 + (lib.optionalString (wrapped-factor.runtimeLibs != [ ])) ''
121 appendToVar makeWrapperArgs --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath wrapped-factor.runtimeLibs}"
122 ''
123 + ''
124 mkdir -p "$out/bin"
125 makeWrapper "$out/lib/factor/$vocabBaseName/$vocabBaseName" \
126 "$out/bin/$binName" \
127 --prefix PATH : "${lib.makeBinPath runtimePaths}" \
128 "''${makeWrapperArgs[@]}"
129 runHook postInstall
130 ''
131 );
132
133 passthru = {
134 vocab = finalAttrs.src;
135 }
136 // attrs.passthru or { };
137
138 meta = {
139 platforms = wrapped-factor.meta.platforms;
140 mainProgram = finalAttrs.binName;
141 }
142 // attrs.meta or { };
143 }
144)