1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
{
stdenv,
lib,
writeText,
makeBinaryWrapper,
factor-lang,
factor-no-gui,
librsvg,
gdk-pixbuf,
}@initAttrs:
drvArgs:
let
flang = factor-lang; # workaround to satisfy nixf-tidy
in
(stdenv.mkDerivation drvArgs).overrideAttrs (
finalAttrs:
{
name ? "${finalAttrs.pname}-${finalAttrs.version}",
factor-lang ? if enableUI then flang else factor-no-gui,
enableUI ? false,
# Allow overriding the path to the deployed vocabulary name. A
# $vocabName.factor file must exist!
vocabName ? finalAttrs.pname or name,
# Allow overriding the binary name
binName ? lib.last (lib.splitString "/" vocabName),
# Extra libraries needed
extraLibs ? [ ],
# Extra binaries in PATH
extraPaths ? [ ],
# Extra vocabularies needed by this application
extraVocabs ? [ ],
deployScriptText ? /* factor */ ''
USING: command-line io io.backend io.pathnames kernel namespaces sequences
tools.deploy tools.deploy.config tools.deploy.backend vocabs.loader
io.directories.unix ;
IN: deploy-me
! The Nix sandbox’s seccomp filter blocks chmod(2). Factor’s
! copy-file calls set-file-permissions which chmod’s the target
! to the source’s mode, 0o444. The blocked syscall returns
! EACCES, crashing the deploys. The method override skips the
! set-file-permissions call (Nix will manage its output
! permissions).
!
! Surfaced with Factor 0.101 which added icon PNG resources to
! the definitions.icons vocab to copy-vocab-resources.
M: unix copy-file call-next-method ;
: load-and-deploy ( path/vocab -- )
normalize-path [
parent-directory add-vocab-root
] [
file-name dup reload deploy
] bi ;
! Factor 0.101 added a .out extension on not macOS. Rather than
! having shell scripts dealing path name changes per-OS &
! per-version, the deploy script prints its deploy path to a file.
: deploy-vocab ( path/vocab path/target -- )
normalize-path deploy-directory set
f open-directory-after-deploy? set
dup file-name
[ load-and-deploy ] dip
deploy-path "deploy-path.txt" utf8 set-file-contents ;
: deploy-me ( -- )
command-line get dup length 2 = [
first2 deploy-vocab
] [
drop
"Usage: deploy-me <PATH-TO-VOCAB> <TARGET-DIR>" print
nl
] if ;
MAIN: deploy-me
'',
...
}@attrs:
let
deployScript = writeText "deploy-me.factor" finalAttrs.deployScriptText;
wrapped-factor = finalAttrs.factor-lang.override {
inherit (finalAttrs) extraLibs extraVocabs;
doInstallCheck = false;
};
runtimePaths = with finalAttrs.wrapped-factor; defaultBins ++ binPackages ++ finalAttrs.extraPaths;
in
{
inherit
enableUI
vocabName
deployScriptText
extraLibs
extraPaths
extraVocabs
binName
factor-lang
wrapped-factor
;
nativeBuildInputs = [
makeBinaryWrapper
(lib.hiPrio finalAttrs.wrapped-factor)
]
++ attrs.nativeBuildInputs or [ ];
buildInputs = (lib.optional enableUI gdk-pixbuf) ++ attrs.buildInputs or [ ];
buildPhase =
attrs.buildPhase or /* bash */ ''
runHook preBuild
vocabBaseName=$(basename "$vocabName")
mkdir -p "$out/lib/factor" "$TMPDIR/.cache"
export XDG_CACHE_HOME="$TMPDIR/.cache"
# Deploy script writes the deploy path to to $PWD/deploy-path.txt
factor "${deployScript}" "./$vocabName" "$out/lib/factor"
deploy_path=$(cat "$PWD/deploy-path.txt")
if [ ! -x "$deploy_path" ]; then
echo "Not a valid deploy path for Factor: $deploy_path"
exit 1
fi
cp "$TMPDIR/factor-temp"/*.image "$(dirname "$deploy_path")/$(basename "$deploy_path").image"
runHook postBuild
'';
__structuredAttrs = true;
installPhase =
attrs.installPhase or /* bash */ ''
runHook preInstall
${lib.optionalString finalAttrs.enableUI /* bash */ ''
# Set Gdk pixbuf loaders file to the one from the build dependencies here
unset GDK_PIXBUF_MODULE_FILE
# Defined in gdk-pixbuf setup hook
findGdkPixbufLoaders "${librsvg}"
appendToVar makeWrapperArgs --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE"
appendToVar makeWrapperArgs --prefix LD_LIBRARY_PATH : /run/opengl-driver/lib
''}
${lib.optionalString (wrapped-factor.runtimeLibs != [ ]) /* bash */ ''
appendToVar makeWrapperArgs --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath wrapped-factor.runtimeLibs}"
''}
mkdir -p "$out/bin"
makeWrapper "$deploy_path" \
"$out/bin/$binName" \
--prefix PATH : "${lib.makeBinPath runtimePaths}" \
"''${makeWrapperArgs[@]}"
runHook postInstall
'';
passthru = {
vocab = finalAttrs.src;
}
// attrs.passthru or { };
meta = {
platforms = wrapped-factor.meta.platforms;
mainProgram = finalAttrs.binName;
}
// attrs.meta or { };
}
)
|