72 lines
1.9 KiB
Nix
72 lines
1.9 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
with lib;
|
|
let
|
|
rootCfg = config.selfhosted;
|
|
common = rootCfg.common;
|
|
moduleCfg = rootCfg.pocket-id;
|
|
cfg = moduleCfg.server;
|
|
hostDataPath = "${common.dataDir}/pocket-id";
|
|
ready = pkgs.writeShellScript "pocket-id-ready" ''
|
|
set -euo pipefail
|
|
url="http://127.0.0.1:${toString cfg.hostHttpPort}/.well-known/openid-configuration"
|
|
for i in $(seq 1 90); do
|
|
if ${lib.getExe pkgs.curl} -fsS -o /dev/null --max-time 2 "$url"; then
|
|
exit 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
echo "Pocket ID did not serve $url" >&2
|
|
exit 1
|
|
'';
|
|
in
|
|
{
|
|
imports = [ ./config.nix ];
|
|
|
|
options.selfhosted.pocket-id.server = {
|
|
name = mkOption {
|
|
type = types.str;
|
|
};
|
|
hostHttpPort = mkOption {
|
|
type = types.port;
|
|
};
|
|
};
|
|
|
|
config = mkIf moduleCfg.enable {
|
|
virtualisation.oci-containers.containers.${cfg.name} = {
|
|
image = "ghcr.io/pocket-id/pocket-id:v2.14.0";
|
|
ports = [
|
|
"0.0.0.0:${toString cfg.hostHttpPort}:1411"
|
|
];
|
|
user = "${common.user.uid}:${common.group.gid}";
|
|
environmentFiles = [ config.sops.templates."pocket-id.env".path ];
|
|
volumes = [
|
|
"${hostDataPath}/data:/app/data"
|
|
];
|
|
log-driver = "journald";
|
|
extraOptions = [
|
|
"--network=${common.network.name}"
|
|
];
|
|
};
|
|
|
|
systemd.services."${common.backend}-${cfg.name}" = {
|
|
serviceConfig = {
|
|
Restart = lib.mkOverride 90 "always";
|
|
ExecStartPost = ready;
|
|
};
|
|
before = [ "${common.backend}-${moduleCfg.targetName}.target" ];
|
|
wantedBy = [ "${common.backend}-${moduleCfg.targetName}.target" ];
|
|
partOf = [ "${common.backend}-${moduleCfg.targetName}.target" ];
|
|
preStart = ''
|
|
mkdir -p ${hostDataPath}/letsencrypt
|
|
chown -R ${common.user.uid}:${common.group.gid} ${hostDataPath}
|
|
chmod -R 0775 ${hostDataPath}
|
|
'';
|
|
};
|
|
};
|
|
}
|