I have NixOS 22.11 set up as on a local workstation. I'm looking for a way to create a customizable and flexible local environment for Wordpress development using Nix. I want the solution to be "ephemeral" (just drop-in config to any directory & run) and not modify my main system configuration (it uses flakes). I'm aware of tool like: arion, but it uses docker-compose
under the hood.
I need a solution that is equivalent to docker-compose
in terms of easy setup of multiple, local Wordpress sites. However, it must use native NixOS configuration and Nix language to setup the needed services. It should be independent on docker
or podman
, but it should work with local treafik
subdomains.
Currently, I'm using traefik
routing with local subdomains. It is configured with dnsmasq
and locally-trusted certificates using mkcert
, as described in this article
Here is my docker-compose.yaml
version: '3'
services:
mariadb:
image: bitnami/mariadb:latest
volumes:
- 'mariadb_data:/bitnami/mariadb'
restart: always
environment:
- MARIADB_ROOT_PASSWORD=wordpress
- MARIADB_DATABASE=wordpress
- MARIADB_USER=wordpress
- MARIADB_PASSWORD=wordpress
networks:
- web
healthcheck:
test: [ 'CMD', '/opt/bitnami/scripts/mariadb/healthcheck.sh' ]
interval: 15s
timeout: 5s
retries: 6
wordpress:
image: wordpress:latest
# command: -H unix:///var/run/docker.sock
ports:
- 8080:80
expose:
- 8080
security_opt:
- no-new-privileges:true
networks:
- web
depends_on:
- mariadb
restart: always
environment:
- WORDPRESS_DB_HOST=mariadb
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpress
- WORDPRESS_DB_NAME=wordpress
labels:
- traefik.enable=true
- traefik.docker.network=web
- traefik.http.routers.wp-http.entrypoints=web
- traefik.http.routers.wp-http.rule=Host(`wp.docker.localdev`)
- traefik.http.routers.wp-http.middlewares=wp-https
- traefik.http.middlewares.wp-https.redirectscheme.scheme=https
- traefik.http.routers.wp-https.entrypoints=websecure
- traefik.http.routers.wp-https.rule=Host(`wp.docker.localdev`)
- traefik.http.routers.wp-https.tls=true
# - traefik.http.services.wp.loadbalancer.server.port=8080
volumes:
- ./wp-content:/var/www/html/wp-content
volumes:
db_data:
mariadb_data:
driver: local
networks:
web:
external: true
Is it possible and how can I achieve this? I'm looking for more for a guidance: something like a code skeleton or even general tips are welcome.
I found the solution that meets my needs. The below config works for me, but it requires some fine-tuning.
I used extra-container, which can run declarative NixOS containers like imperative containers, without system rebuilds, from any folder.
The services used:
.docker.localdev
might be misleading, I don't use docker here. I just had this name pre-configured in my system.wp.nix
I run it with the command: