nixos/lasuite-docs: add systemd service to create postgresql unaccent

function

It is unsafe for a non-superadmin user to create a C functin
in postgresql, so we need to create the function via the
superadmin postgres user. This function (immutable unaccent) is
needed by lasuite-docs since 4.2.0 and is used to search for keys
without accents.

https://github.com/suitenumerique/docs/releases/tag/v4.2.0
https://github.com/suitenumerique/docs/compare/v4.1.0...v4.2.0
This commit is contained in:
soyouzpanda 2025-12-23 19:50:04 +01:00
parent ac57c05e28
commit cdfc90c4e5
No known key found for this signature in database

View file

@ -346,6 +346,56 @@ in
};
config = mkIf cfg.enable {
systemd.services.lasuite-docs-postgresql-setup = mkIf cfg.postgresql.createLocally {
wantedBy = [ "lasuite-docs.target" ];
requiredBy = [ "lasuite-docs.service" ];
before = [ "lasuite-docs.service" ];
after = [ "postgresql-setup.service" ];
serviceConfig = {
Slice = "system-lasuite-docs.slice";
Type = "oneshot";
User = "postgres";
# lasuite-docs user cannot create a C function as it is unsafe.
ExecStart = ''
${lib.getExe' config.services.postgresql.package "psql"} --port=${toString config.services.postgresql.settings.port} -d lasuite-docs -c "CREATE OR REPLACE FUNCTION public.immutable_unaccent(regdictionary, text) RETURNS text LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS '$libdir/unaccent', 'unaccent_dict';"
'';
# hardening
AmbientCapabilities = "";
CapabilityBoundingSet = [ "" ];
DevicePolicy = "closed";
LockPersonality = true;
NoNewPrivileges = true;
PrivateDevices = true;
PrivateTmp = true;
PrivateUsers = true;
ProcSubset = "pid";
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectProc = "invisible";
ProtectSystem = "strict";
RemoveIPC = true;
RestrictAddressFamilies = [
"AF_INET"
"AF_INET6"
"AF_UNIX"
];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
UMask = "0077";
};
};
systemd.services.lasuite-docs = {
description = "Docs from SuiteNumérique";
after = [