2023-10-02 13:11:30 +02:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{
|
2023-11-28 15:21:03 +01:00
|
|
|
imports = [
|
|
|
|
./syncthing.nix
|
|
|
|
];
|
2023-11-20 14:09:10 +01:00
|
|
|
|
2023-11-05 17:15:01 +01:00
|
|
|
# Update and start Jinja-Compose project
|
|
|
|
# during boot and after every 30 minutes.
|
|
|
|
# To view the log, run
|
2023-10-02 13:11:30 +02:00
|
|
|
# journalctl -b -u Jinja-Compose -f
|
|
|
|
#
|
2023-11-05 17:15:01 +01:00
|
|
|
systemd.timers."Jinja-Compose" = {
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
partOf = [ "Jinja-Compose.service" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnBootSec = "0m";
|
|
|
|
OnUnitInactiveSec = "30m";
|
|
|
|
|
|
|
|
AccuracySec = "1m";
|
|
|
|
RandomizedDelaySec = "1m";
|
|
|
|
};
|
|
|
|
};
|
2024-01-08 18:40:18 +01:00
|
|
|
# TODO: Add shutdown script (./docker-compose down).
|
2023-10-02 13:11:30 +02:00
|
|
|
systemd.services."Jinja-Compose" = {
|
2023-11-05 17:15:01 +01:00
|
|
|
description = "Update and start Jinja-Compose project";
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
PrivateTmp = true;
|
|
|
|
User = "root";
|
|
|
|
};
|
2023-10-02 13:11:30 +02:00
|
|
|
path = with pkgs; [
|
|
|
|
# The `docker-compose` helper script is written in `bash` (!)
|
|
|
|
bash
|
|
|
|
docker
|
|
|
|
];
|
|
|
|
script = ''
|
2023-10-08 15:38:44 +02:00
|
|
|
set -eu -o pipefail
|
2024-08-31 12:07:00 +02:00
|
|
|
|
2024-09-10 12:17:42 +02:00
|
|
|
# We use one of the following
|
|
|
|
# some-command 2> >(sed 's/^/<3> /' >&2)
|
|
|
|
# some-command 2>&1 | sed 's/^/<3> /' 1>&2
|
|
|
|
# to prefix each line of stdout and stderr from some-command with
|
2024-08-31 12:07:00 +02:00
|
|
|
# "<3> "
|
|
|
|
# Source: https://superuser.com/a/882025/919675
|
|
|
|
#
|
|
|
|
# With this prefix, the stderr output is treated as error messages by systemd.
|
|
|
|
# See https://www.freedesktop.org/software/systemd/man/latest/sd-daemon.html
|
|
|
|
# They can be viewed with
|
|
|
|
# journalctl -b -u Jinja-Compose.service
|
|
|
|
|
2024-09-10 12:17:42 +02:00
|
|
|
/jc-config/docker-compose pull 2>&1 | sed 's/^/<3> /'
|
|
|
|
/jc-config/docker-compose up -d --wait 2>&1 | sed 's/^/<3> /'
|
2023-10-02 13:11:30 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|