-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: enable escaping special Nix chars in template
Fix an issue where special characters were not properly escaped in template, leading to Nix parsing errors. Tests have been checked and pass. Test data has been written from the real world problem I faced using Dovecot's labels containing shell scripts.
- Loading branch information
Showing
9 changed files
with
247 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: "dovecot" | ||
services: | ||
dovecot: | ||
container_name: dovecot | ||
image: dovecot | ||
labels: | ||
ofelia.enabled: "true" | ||
ofelia.job-exec.dovecot_imapsync_runner.schedule: "@every 1m" | ||
ofelia.job-exec.dovecot_imapsync_runner.no-overlap: "true" | ||
ofelia.job-exec.dovecot_imapsync_runner.command: "/bin/bash -c \"[[ $${MASTER} == y ]] && /usr/local/bin/gosu nobody /usr/local/bin/imapsync_runner.pl || exit 0\"" | ||
ofelia.job-exec.dovecot_trim_logs.schedule: "@every 1m" | ||
ofelia.job-exec.dovecot_trim_logs.command: "/bin/bash -c \"[[ $${MASTER} == y ]] && /usr/local/bin/gosu vmail /usr/local/bin/trim_logs.sh || exit 0\"" | ||
networks: | ||
- abc | ||
volumes: | ||
- def:/path/to/path | ||
|
||
networks: | ||
abc: | ||
labels: | ||
my-label: "\"some quoted string\"" | ||
|
||
volumes: | ||
def: | ||
labels: | ||
other-label: "\"another quota string\"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{ pkgs, lib, ... }: | ||
|
||
{ | ||
# Runtime | ||
virtualisation.docker = { | ||
enable = true; | ||
autoPrune.enable = true; | ||
}; | ||
virtualisation.oci-containers.backend = "docker"; | ||
|
||
# Containers | ||
virtualisation.oci-containers.containers."dovecot" = { | ||
image = "dovecot"; | ||
volumes = [ | ||
"dovecot_def:/path/to/path:rw" | ||
]; | ||
labels = { | ||
"ofelia.enabled" = "true"; | ||
"ofelia.job-exec.dovecot_imapsync_runner.command" = "/bin/bash -c \"[[ \${MASTER} == y ]] && /usr/local/bin/gosu nobody /usr/local/bin/imapsync_runner.pl || exit 0\""; | ||
"ofelia.job-exec.dovecot_imapsync_runner.no-overlap" = "true"; | ||
"ofelia.job-exec.dovecot_imapsync_runner.schedule" = "@every 1m"; | ||
"ofelia.job-exec.dovecot_trim_logs.command" = "/bin/bash -c \"[[ \${MASTER} == y ]] && /usr/local/bin/gosu vmail /usr/local/bin/trim_logs.sh || exit 0\""; | ||
"ofelia.job-exec.dovecot_trim_logs.schedule" = "@every 1m"; | ||
}; | ||
log-driver = "journald"; | ||
autoStart = false; | ||
extraOptions = [ | ||
"--network-alias=dovecot" | ||
"--network=dovecot_abc" | ||
]; | ||
}; | ||
systemd.services."docker-dovecot" = { | ||
serviceConfig = { | ||
Restart = lib.mkOverride 500 "no"; | ||
}; | ||
after = [ | ||
"docker-network-dovecot_abc.service" | ||
"docker-volume-dovecot_def.service" | ||
]; | ||
requires = [ | ||
"docker-network-dovecot_abc.service" | ||
"docker-volume-dovecot_def.service" | ||
]; | ||
partOf = [ | ||
"docker-compose-dovecot-root.target" | ||
]; | ||
wantedBy = [ | ||
"docker-compose-dovecot-root.target" | ||
]; | ||
}; | ||
|
||
# Networks | ||
systemd.services."docker-network-dovecot_abc" = { | ||
path = [ pkgs.docker ]; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
RemainAfterExit = true; | ||
ExecStop = "docker network rm -f dovecot_abc"; | ||
}; | ||
script = '' | ||
docker network inspect dovecot_abc || docker network create dovecot_abc --label=my-label="some quoted string" | ||
''; | ||
partOf = [ "docker-compose-dovecot-root.target" ]; | ||
wantedBy = [ "docker-compose-dovecot-root.target" ]; | ||
}; | ||
|
||
# Volumes | ||
systemd.services."docker-volume-dovecot_def" = { | ||
path = [ pkgs.docker ]; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
RemainAfterExit = true; | ||
}; | ||
script = '' | ||
docker volume inspect dovecot_def || docker volume create dovecot_def --label=other-label="another quota string" | ||
''; | ||
partOf = [ "docker-compose-dovecot-root.target" ]; | ||
wantedBy = [ "docker-compose-dovecot-root.target" ]; | ||
}; | ||
|
||
# Root service | ||
# When started, this will automatically create all resources and start | ||
# the containers. When stopped, this will teardown all resources. | ||
systemd.targets."docker-compose-dovecot-root" = { | ||
unitConfig = { | ||
Description = "Root target generated by compose2nix."; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
{ pkgs, lib, ... }: | ||
|
||
{ | ||
# Runtime | ||
virtualisation.podman = { | ||
enable = true; | ||
autoPrune.enable = true; | ||
dockerCompat = true; | ||
defaultNetwork.settings = { | ||
# Required for container networking to be able to use names. | ||
dns_enabled = true; | ||
}; | ||
}; | ||
virtualisation.oci-containers.backend = "podman"; | ||
|
||
# Containers | ||
virtualisation.oci-containers.containers."dovecot" = { | ||
image = "dovecot"; | ||
volumes = [ | ||
"dovecot_def:/path/to/path:rw" | ||
]; | ||
labels = { | ||
"ofelia.enabled" = "true"; | ||
"ofelia.job-exec.dovecot_imapsync_runner.command" = "/bin/bash -c \"[[ \${MASTER} == y ]] && /usr/local/bin/gosu nobody /usr/local/bin/imapsync_runner.pl || exit 0\""; | ||
"ofelia.job-exec.dovecot_imapsync_runner.no-overlap" = "true"; | ||
"ofelia.job-exec.dovecot_imapsync_runner.schedule" = "@every 1m"; | ||
"ofelia.job-exec.dovecot_trim_logs.command" = "/bin/bash -c \"[[ \${MASTER} == y ]] && /usr/local/bin/gosu vmail /usr/local/bin/trim_logs.sh || exit 0\""; | ||
"ofelia.job-exec.dovecot_trim_logs.schedule" = "@every 1m"; | ||
}; | ||
log-driver = "journald"; | ||
autoStart = false; | ||
extraOptions = [ | ||
"--network-alias=dovecot" | ||
"--network=dovecot_abc" | ||
]; | ||
}; | ||
systemd.services."podman-dovecot" = { | ||
serviceConfig = { | ||
Restart = lib.mkOverride 500 "no"; | ||
}; | ||
after = [ | ||
"podman-network-dovecot_abc.service" | ||
"podman-volume-dovecot_def.service" | ||
]; | ||
requires = [ | ||
"podman-network-dovecot_abc.service" | ||
"podman-volume-dovecot_def.service" | ||
]; | ||
partOf = [ | ||
"podman-compose-dovecot-root.target" | ||
]; | ||
wantedBy = [ | ||
"podman-compose-dovecot-root.target" | ||
]; | ||
}; | ||
|
||
# Networks | ||
systemd.services."podman-network-dovecot_abc" = { | ||
path = [ pkgs.podman ]; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
RemainAfterExit = true; | ||
ExecStop = "podman network rm -f dovecot_abc"; | ||
}; | ||
script = '' | ||
podman network inspect dovecot_abc || podman network create dovecot_abc --label=my-label="some quoted string" | ||
''; | ||
partOf = [ "podman-compose-dovecot-root.target" ]; | ||
wantedBy = [ "podman-compose-dovecot-root.target" ]; | ||
}; | ||
|
||
# Volumes | ||
systemd.services."podman-volume-dovecot_def" = { | ||
path = [ pkgs.podman ]; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
RemainAfterExit = true; | ||
}; | ||
script = '' | ||
podman volume inspect dovecot_def || podman volume create dovecot_def --label=other-label="another quota string" | ||
''; | ||
partOf = [ "podman-compose-dovecot-root.target" ]; | ||
wantedBy = [ "podman-compose-dovecot-root.target" ]; | ||
}; | ||
|
||
# Root service | ||
# When started, this will automatically create all resources and start | ||
# the containers. When stopped, this will teardown all resources. | ||
systemd.targets."podman-compose-dovecot-root" = { | ||
unitConfig = { | ||
Description = "Root target generated by compose2nix."; | ||
}; | ||
}; | ||
} |