7 , withPgsql ? true # “strongly recommended” according to docs
9 , minifyStaticFiles ? false # default files are often not minified
24 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";
31 minify = lib.recursiveUpdate defaultMinifyOpts
32 (if lib.isBool minifyStaticFiles && minifyStaticFiles then
33 { script.enable = true; style.enable = true; svg.enable = true; }
34 else if lib.isAttrs minifyStaticFiles then
35 lib.filterAttrsRecursive (_: v: v != null) minifyStaticFiles
39 php.buildComposerProject (finalAttrs: {
43 src = fetchFromGitHub {
46 rev = "refs/tags/v${finalAttrs.version}";
47 hash = "sha256-VshDFHDCfemHS/TN5qEe8CGizZksf44xENSmvX44uAc=";
51 extensions = ({ all, enabled }:
53 ++ (with all; [ curl dom gd imagick mbstring pdo simplexml ])
54 ++ lib.optionals withPgsql (with all; [ pdo_pgsql pgsql ])
55 ++ lib.optionals withMysql (with all; [ mysqli mysqlnd pdo_mysql ])
57 } // lib.optionalAttrs (phpCfg != null) {
62 lib.optional minify.script.enable esbuild
63 ++ lib.optional minify.style.enable lightningcss
64 ++ lib.optional minify.svg.enable scour;
68 composerStrictValidation = false;
70 vendorHash = "sha256-nxbsw0re/7zKhpWxtA8JAf7JL3RLghqaYsi4rkM6VZg=";
73 # Our modules are already wrapped, removes missing *.so warnings;
74 # replacing `$configuration` with actually-used flags.
75 substituteInPlace src/Movim/Daemon/Session.php \
76 --replace-fail "exec php ' . \$configuration " "exec php -dopcache.enable=1 -dopcache.enable_cli=1 ' "
78 # Point to PHP + PHP INI in the Nix store
79 substituteInPlace src/Movim/{Console/DaemonCommand.php,Daemon/Session.php} \
80 --replace-fail "exec php " "exec ${lib.getExe finalAttrs.php} "
81 substituteInPlace src/Movim/Console/DaemonCommand.php \
82 --replace-fail "<info>php vendor/bin/phinx migrate</info>" \
83 "<info>${lib.getBin finalAttrs.php} vendor/bin/phinx migrate</info>" \
84 --replace-fail "<info>php daemon.php setAdmin {jid}</info>" \
85 "<info>${finalAttrs.meta.mainProgram} setAdmin {jid}</info>"
87 # BUGFIX: Imagick API Changes for 7.x+
88 # See additionally: https://github.com/movim/movim/pull/1122
89 substituteInPlace src/Movim/Image.php \
90 --replace-fail "Imagick::ALPHACHANNEL_REMOVE" "Imagick::ALPHACHANNEL_OFF" \
91 --replace-fail "Imagick::ALPHACHANNEL_ACTIVATE" "Imagick::ALPHACHANNEL_ON"
94 preBuild = lib.optionalString minify.script.enable ''
95 find ./public -type f -iname "*.js" -print0 \
96 | xargs -0 -n 1 -P $NIX_BUILD_CORES ${writeShellScript "movim_script_minify" ''
99 esbuild $file --minify --target=${lib.escapeShellArg minify.script.target} --outfile=$tmp
100 [[ "$(stat -c %s $tmp)" -lt "$(stat -c %s $file)" ]] && mv $tmp $file
102 '' + lib.optionalString minify.style.enable ''
103 find ./public -type f -iname "*.css" -print0 \
104 | xargs -0 -n 1 -P $NIX_BUILD_CORES ${writeShellScript "movim_style_minify" ''
105 export BROWSERLIST="${lib.escapeShellArg minify.style.browserslist}"
108 lightningcss $file --minify --browserslist --output-file=$tmp
109 [[ "$(stat -c %s $tmp)" -lt "$(stat -c %s $file)" ]] && mv $tmp $file
111 '' + lib.optionalString minify.svg.enable ''
112 find ./public -type f -iname "*.svg" -a -not -path "*/emojis/*" -print0 \
113 | xargs -0 -n 1 -P $NIX_BUILD_CORES ${writeShellScript "movim_svg_minify" ''
116 scour -i $file -o $tmp --disable-style-to-xml --enable-comment-stripping --enable-viewboxing --indent=tab
117 [[ "$(stat -c %s $tmp)" -lt "$(stat -c %s $file)" ]] && mv $tmp $file
123 echo "#!${lib.getExe dash}" > $out/bin/movim
124 echo "${lib.getExe finalAttrs.php} $out/share/php/${finalAttrs.pname}/daemon.php \"\$@\"" >> $out/bin/movim
125 chmod +x $out/bin/movim
127 mkdir -p $out/share/{bash-completion/completion,fish/vendor_completions.d,zsh/site-functions}
128 $out/bin/movim completion bash | sed "s/daemon.php/movim/g" > $out/share/bash-completion/completion/movim.bash
129 $out/bin/movim completion fish | sed "s/daemon.php/movim/g" > $out/share/fish/vendor_completions.d/movim.fish
130 $out/bin/movim completion zsh | sed "s/daemon.php/movim/g" > $out/share/zsh/site-functions/_movim
131 chmod +x $out/share/{bash-completion/completion/movim.bash,fish/vendor_completions.d/movim.fish,zsh/site-functions/_movim}
135 tests = { inherit (nixosTests) movim; };
139 description = "Federated blogging & chat platform that acts as a web front end for the XMPP protocol";
140 homepage = "https://movim.eu";
141 license = lib.licenses.agpl3Plus;
142 maintainers = with lib.maintainers; [ toastal ];
143 mainProgram = "movim";