My Nix Configuration

[marvin.services] planka: use native instead of docker

Changed files
+97 -32
hosts
marvin
services
+97 -32
hosts/marvin/services/planka.nix
···
{
+
lib,
config,
self,
+
self',
+
pkgs,
...
}:
let
-
dataDir = "/var/lib/planka";
d = self.lib.data.services.planka;
+
+
commonServiceConfig = {
+
EnvironmentFile = config.age.secrets.planka-env.path;
+
StateDirectory = "planka";
+
WorkingDirectory = "/var/lib/planka";
+
User = "planka";
+
Group = "planka";
+
+
# Hardening
+
LockPersonality = true;
+
NoNewPrivileges = true;
+
PrivateDevices = true;
+
PrivateMounts = true;
+
PrivateTmp = true;
+
PrivateUsers = true;
+
ProtectClock = true;
+
ProtectControlGroups = true;
+
ProtectHome = true;
+
ProtectHostname = true;
+
ProtectKernelLogs = true;
+
ProtectKernelModules = true;
+
ProtectKernelTunables = true;
+
ProtectProc = "invisible";
+
RemoveIPC = true;
+
RestrictRealtime = true;
+
RestrictSUIDSGID = true;
+
UMask = "0660";
+
RestrictAddressFamilies = [
+
"AF_UNIX"
+
"AF_INET"
+
"AF_INET6"
+
];
+
};
in
{
-
virtualisation.oci-containers.containers = {
-
planka-server = {
-
image = "ghcr.io/plankanban/planka:2.0.0-rc.4";
-
ports = [ "${toString d.port}:1337" ];
-
environment = {
-
BASE_URL = "https://${d.extUrl}";
-
DATABASE_URL = "postgresql://planka@planka-db/planka";
-
# Default Admin
-
DEFAULT_ADMIN_EMAIL = "pyrox@pyrox.dev";
-
DEFAULT_ADMIN_USERNAME = "pyrox";
-
TRUST_PROXY = "true";
-
DEFAULT_LANGUAGE = "en-US";
+
systemd = {
+
tmpfiles.settings = {
+
"10-planka"."/var/lib/planka".d = {
+
group = "planka";
+
user = "planka";
+
mode = "0755";
};
-
environmentFiles = [ config.age.secrets.planka-env.path ];
-
volumes = [
-
"${dataDir}/user-avatars:/app/public/user-avatars"
-
"${dataDir}/project-background-images:/app/public/project-background-images"
-
"${dataDir}/attachments:/app/private/attachments"
-
"${dataDir}/favicons:/app/public/favicons"
-
"${dataDir}/background-images:/app/public/background-images"
-
];
-
extraOptions = [ "--network=planka" ];
};
-
planka-db = {
-
image = "postgres:16-alpine";
-
volumes = [ "${dataDir}/db:/var/lib/postgresql/data" ];
-
environment = {
-
POSTGRES_USER = "planka";
-
POSTGRES_DB = "planka";
-
POSTGRES_HOST_AUTH_METHOD = "trust";
+
services = {
+
planka-init-db = {
+
wantedBy = [ "multi-user.target" ];
+
after = [ "postgres.target" ];
+
description = "Planka Kanban Database Init Script";
+
path = [
+
pkgs.nodejs
+
];
+
script = ''
+
if [ ! -f /var/lib/planka/db-init-ran ]; then
+
node run ${self'.packages.planka}/lib/node_modules/planka/db/init.js && \
+
touch /var/lib/planka/db-init-ran
+
fi
+
'';
+
serviceConfig = commonServiceConfig // {
+
Type = "oneshot";
+
SyslogIdentifier = "planka-init-db";
+
};
};
-
extraOptions = [ "--network=planka" ];
+
planka-server = {
+
after = [ "planka-init-db.service" ];
+
wantedBy = [ "multi-user.target" ];
+
description = "Planka Kanban Server";
+
documentation = [ "https://docs.planka.cloud" ];
+
environment = {
+
DATABASE_URL = "postgresql://%2Frun%2Fpostgresql/planka";
+
DEFAULT_ADMIN_EMAIL = "pyrox@pyrox.dev";
+
DEFAULT_ADMIN_USERNAME = "pyrox";
+
TRUST_PROXY = "true";
+
DEFAULT_LANGUAGE = "en-US";
+
BASE_URL = "https://${d.extUrl}";
+
NODE_ENV = "production";
+
};
+
serviceConfig = commonServiceConfig // {
+
Type = "simple";
+
ExecStart = "${lib.getExe self'.packages.planka} --port ${toString d.port}";
+
SyslogIdentifier = "planka";
+
};
+
};
};
};
+
users.users.planka = {
+
isSystemUser = true;
+
group = "planka";
+
};
+
users.groups.planka = { };
+
services.postgresql = {
+
ensureUsers = [
+
{
+
name = "planka";
+
ensureDBOwnership = true;
+
ensureClauses.login = true;
+
}
+
];
+
ensureDatabases = [ "planka" ];
+
};
age.secrets.planka-env = {
file = ./secrets/planka-env.age;
-
owner = "thehedgehog";
-
group = "misc";
+
owner = "planka";
+
group = "planka";
};
services.anubis.instances.planka = {
settings = {