-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordpress.nix
152 lines (129 loc) · 3.42 KB
/
wordpress.nix
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
{ pkgs, php, imageName }:
let
customPhp = (php.override {
# Sapi flags
cgiSupport = false;
cliSupport = true;
fpmSupport = false;
pearSupport = false;
pharSupport = true;
phpdbgSupport = false;
# Misc flags
apxs2Support = false;
argon2Support = true;
cgotoSupport = false;
embedSupport = true;
ipv6Support = true;
staticSupport = false;
systemdSupport = false;
valgrindSupport = false;
zendMaxExecutionTimersSupport = true;
zendSignalsSupport = false;
ztsSupport = true;
}).overrideAttrs (oldAttrs: rec {
# Use Clang instead of GCC
stdenv = pkgs.clangStdenv;
# optimizations
extraConfig = ''
CC = "${pkgs.llvmPackages_19.clang}/bin/clang";
CXX = "${pkgs.llvmPackages_19.clang}/bin/clang++";
CFLAGS="$CFLAGS -march=x86-64-v3 -mtune=x86-64-v3 -O3 -ffast-math -flto"
CXXFLAGS="$CXXFLAGS -march=x86-64-v3 -mtune=x86-64-v3 -O3 -ffast-math -flto"
LDFLAGS="$LDFLAGS -flto"
'';
# Explicitly enable XML support (required by FrankenPHP)
configureFlags = (oldAttrs.configureFlags or [ ]) ++ [
"--enable-xml"
"--with-libxml"
];
buildInputs = (oldAttrs.buildInputs or [ ]) ++ [
pkgs.libxml2.dev
];
});
phpWithExtensions = customPhp.withExtensions ({ all, ... }: with all; [
# Required extensions
mysqli
# Highly recommended extensions
ctype
curl
dom
exif
fileinfo
filter
igbinary
# imagick
intl
mbstring
openssl
pdo
pdo_mysql
session
simplexml
tokenizer
xmlwriter
zip
zlib
# Recommended for caching
opcache
# Optional extensions for improved functionality
gd
iconv
sodium
# Development extensions (uncomment if needed in production)
# xdebug
]);
phpBuild = phpWithExtensions.buildEnv {
extraConfig = builtins.readFile ./conf/php.ini;
};
wp-cli = (pkgs.wp-cli.override {
php = phpBuild;
});
frankenphp = (pkgs.frankenphp.override {
php = phpBuild;
}).overrideAttrs (oldAttrs: {
phpEmbedWithZts = phpBuild;
phpUnwrapped = phpBuild.unwrapped;
phpConfig = "${phpBuild.unwrapped.dev}/bin/php-config";
});
caddyfile = pkgs.writeText "Caddyfile" (builtins.readFile ./conf/Caddyfile);
docker-entrypoint = pkgs.writeScriptBin "docker-entrypoint" (builtins.readFile ./docker-entrypoint.sh);
in
pkgs.dockerTools.buildLayeredImage {
name = imageName;
tag = "latest";
contents = [
phpBuild
pkgs.busybox
pkgs.cacert
# pkgs.ghostscript
# pkgs.imagemagick
pkgs.mysql.client
# pkgs.vips
pkgs.zip
wp-cli
];
config = {
Entrypoint = [ "${pkgs.busybox}/bin/sh" "${pkgs.lib.getExe docker-entrypoint}" ];
Cmd = [ "${pkgs.lib.getExe frankenphp}" "run" "--config" "${caddyfile}" "--adapter" "caddyfile" ];
ExposedPorts = {
"80/tcp" = { };
};
};
extraCommands = ''
# set up /tmp
mkdir -p tmp
chmod 1777 tmp
# Copy WordPress files
mkdir -p var/www/html
cp ${./conf/wp-config.php} wp-config.php
# copy must-use plugins
mkdir mu-plugins
cp -r ${./mu-plugins}/. mu-plugins/
# Symlink CA certificates
ln -s ${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt etc/ssl/certs/ca-certificates.crt
# Symlink busybox for bash and env (required by wp-cli)
mkdir -p usr/bin
ln -s ${pkgs.busybox}/bin/busybox usr/bin/bash
ln -s ${pkgs.busybox}/bin/busybox usr/bin/env
'';
}