8 withPgsql ? true, # “strongly recommended” according to docs
10 minifyStaticFiles ? false, # default files are often not minified
25 browserslist = "defaults, Firefox ESR, last 20 Firefox major versions, last 20 Chrome major versions, last 3 Safari major versions, last 1 KaiOS version, and supports css-variables";
32 minify = lib.recursiveUpdate defaultMinifyOpts (
33 if lib.isBool minifyStaticFiles && minifyStaticFiles then
39 else if lib.isAttrs minifyStaticFiles then
40 lib.filterAttrsRecursive (_: v: v != null) minifyStaticFiles
45 php.buildComposerProject (finalAttrs: {
49 src = fetchFromGitHub {
52 tag = "v${finalAttrs.version}";
53 hash = "sha256-hAOT3n0i9t3uWMjqWJlOs4Vakq3y4+GhiFZ4n3jVqtw=";
70 ++ lib.optionals withPgsql (
77 ++ lib.optionals withMysql (
87 // lib.optionalAttrs (phpCfg != null) {
93 lib.optional minify.script.enable esbuild
94 ++ lib.optional minify.style.enable lightningcss
95 ++ lib.optional minify.svg.enable scour;
99 composerStrictValidation = false;
101 vendorHash = "sha256-uma3evj/81qz/+1+poIl0FJqWe1e2Ay0Jm446CKOGP0=";
104 # Our modules are already wrapped, removes missing *.so warnings;
105 # replacing `$configuration` with actually-used flags.
106 substituteInPlace src/Movim/Daemon/Session.php \
108 "'exec ' . PHP_BINARY . ' ' . \$configuration . '" \
109 "'exec ' . PHP_BINARY . ' -dopcache.enable=1 -dopcache.enable_cli=1 ' . '"
111 # Point to PHP + PHP INI in the Nix store
112 substituteInPlace src/Movim/Console/DaemonCommand.php \
113 --replace-fail "<info>php vendor/bin/phinx migrate</info>" \
114 "<info>${lib.getBin finalAttrs.php} vendor/bin/phinx migrate</info>" \
115 --replace-fail "<info>php daemon.php setAdmin {jid}</info>" \
116 "<info>${finalAttrs.meta.mainProgram} setAdmin {jid}</info>"
118 # BUGFIX: Imagick API Changes for 7.x+
119 # See additionally: https://github.com/movim/movim/pull/1122
120 substituteInPlace src/Movim/Image.php \
121 --replace-fail "Imagick::ALPHACHANNEL_REMOVE" "Imagick::ALPHACHANNEL_OFF" \
122 --replace-fail "Imagick::ALPHACHANNEL_ACTIVATE" "Imagick::ALPHACHANNEL_ON"
126 lib.optionalString minify.script.enable ''
127 find ./public -type f -iname "*.js" -print0 \
128 | xargs -0 -n 1 -P $NIX_BUILD_CORES ${writeShellScript "movim_script_minify" ''
131 esbuild $file --minify --target=${lib.escapeShellArg minify.script.target} --outfile=$tmp
132 [[ "$(stat -c %s $tmp)" -lt "$(stat -c %s $file)" ]] && mv $tmp $file
135 + lib.optionalString minify.style.enable ''
136 find ./public -type f -iname "*.css" -print0 \
137 | xargs -0 -n 1 -P $NIX_BUILD_CORES ${writeShellScript "movim_style_minify" ''
138 export BROWSERLIST="${lib.escapeShellArg minify.style.browserslist}"
141 lightningcss $file --minify --browserslist --output-file=$tmp
142 [[ "$(stat -c %s $tmp)" -lt "$(stat -c %s $file)" ]] && mv $tmp $file
145 + lib.optionalString minify.svg.enable ''
146 find ./public -type f -iname "*.svg" -a -not -path "*/emojis/*" -print0 \
147 | xargs -0 -n 1 -P $NIX_BUILD_CORES ${writeShellScript "movim_svg_minify" ''
150 scour -i $file -o $tmp --disable-style-to-xml --enable-comment-stripping --enable-viewboxing --indent=tab
151 [[ "$(stat -c %s $tmp)" -lt "$(stat -c %s $file)" ]] && mv $tmp $file
157 echo "#!${lib.getExe dash}" > $out/bin/movim
158 echo "${lib.getExe finalAttrs.php} $out/share/php/${finalAttrs.pname}/daemon.php \"\$@\"" >> $out/bin/${finalAttrs.meta.mainProgram}
159 chmod +x $out/bin/${finalAttrs.meta.mainProgram}
162 mkdir -p $out/share/{bash-completion/completion,fish/vendor_completions.d,zsh/site-functions}
163 $out/bin/movim completion bash | sed "s/daemon.php/movim/g" > $out/share/bash-completion/completion/movim.bash
164 $out/bin/movim completion fish | sed "s/daemon.php/movim/g" > $out/share/fish/vendor_completions.d/movim.fish
165 $out/bin/movim completion zsh | sed "s/daemon.php/movim/g" > $out/share/zsh/site-functions/_movim
166 chmod +x $out/share/{bash-completion/completion/movim.bash,fish/vendor_completions.d/movim.fish,zsh/site-functions/_movim}
170 tests = { inherit (nixosTests) movim; };
174 description = "Federated blogging & chat platform that acts as a web front end for the XMPP protocol";
175 homepage = "https://movim.eu";
176 license = lib.licenses.agpl3Plus;
177 maintainers = with lib.maintainers; [ toastal ];
178 mainProgram = "movim";