mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
Merge pull request #292477 from nu-nu-ko/nixos-komga-hardening
nixos/komga: add service hardening and misc format changes.
This commit is contained in:
commit
119099506c
1 changed files with 80 additions and 57 deletions
|
@ -1,99 +1,122 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{
|
||||||
|
config,
|
||||||
with lib;
|
pkgs,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.komga;
|
cfg = config.services.komga;
|
||||||
|
inherit (lib) mkOption mkEnableOption maintainers;
|
||||||
in {
|
inherit (lib.types) port str bool;
|
||||||
|
in
|
||||||
|
{
|
||||||
options = {
|
options = {
|
||||||
services.komga = {
|
services.komga = {
|
||||||
enable = mkEnableOption (lib.mdDoc "Komga, a free and open source comics/mangas media server");
|
enable = mkEnableOption "Komga, a free and open source comics/mangas media server";
|
||||||
|
|
||||||
port = mkOption {
|
port = mkOption {
|
||||||
type = types.port;
|
type = port;
|
||||||
default = 8080;
|
default = 8080;
|
||||||
description = lib.mdDoc ''
|
description = "The port that Komga will listen on.";
|
||||||
The port that Komga will listen on.
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
user = mkOption {
|
user = mkOption {
|
||||||
type = types.str;
|
type = str;
|
||||||
default = "komga";
|
default = "komga";
|
||||||
description = lib.mdDoc ''
|
description = "User account under which Komga runs.";
|
||||||
User account under which Komga runs.
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
group = mkOption {
|
group = mkOption {
|
||||||
type = types.str;
|
type = str;
|
||||||
default = "komga";
|
default = "komga";
|
||||||
description = lib.mdDoc ''
|
description = "Group under which Komga runs.";
|
||||||
Group under which Komga runs.
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
stateDir = mkOption {
|
stateDir = mkOption {
|
||||||
type = types.str;
|
type = str;
|
||||||
default = "/var/lib/komga";
|
default = "/var/lib/komga";
|
||||||
description = lib.mdDoc ''
|
description = "State and configuration directory Komga will use.";
|
||||||
State and configuration directory Komga will use.
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
openFirewall = mkOption {
|
openFirewall = mkOption {
|
||||||
type = types.bool;
|
type = bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = lib.mdDoc ''
|
description = "Whether to open the firewall for the port in {option}`services.komga.port`.";
|
||||||
Whether to open the firewall for the port in {option}`services.komga.port`.
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config =
|
||||||
|
let
|
||||||
|
inherit (lib) mkIf getExe;
|
||||||
|
in
|
||||||
|
mkIf cfg.enable {
|
||||||
|
|
||||||
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
|
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
|
||||||
|
|
||||||
users.groups = mkIf (cfg.group == "komga") {
|
users.groups = mkIf (cfg.group == "komga") { komga = { }; };
|
||||||
komga = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
users.users = mkIf (cfg.user == "komga") {
|
users.users = mkIf (cfg.user == "komga") {
|
||||||
komga = {
|
komga = {
|
||||||
group = cfg.group;
|
group = cfg.group;
|
||||||
home = cfg.stateDir;
|
home = cfg.stateDir;
|
||||||
description = "Komga Daemon user";
|
description = "Komga Daemon user";
|
||||||
isSystemUser = true;
|
isSystemUser = true;
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
systemd.services.komga = {
|
|
||||||
environment = {
|
|
||||||
SERVER_PORT = builtins.toString cfg.port;
|
|
||||||
KOMGA_CONFIGDIR = cfg.stateDir;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
description = "Komga is a free and open source comics/mangas media server";
|
systemd.services.komga = {
|
||||||
|
environment = {
|
||||||
|
SERVER_PORT = builtins.toString cfg.port;
|
||||||
|
KOMGA_CONFIGDIR = cfg.stateDir;
|
||||||
|
};
|
||||||
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
description = "Komga is a free and open source comics/mangas media server";
|
||||||
wants = [ "network-online.target" ];
|
|
||||||
after = [ "network-online.target" ];
|
|
||||||
|
|
||||||
serviceConfig = {
|
wantedBy = [ "multi-user.target" ];
|
||||||
User = cfg.user;
|
wants = [ "network-online.target" ];
|
||||||
Group = cfg.group;
|
after = [ "network-online.target" ];
|
||||||
|
|
||||||
Type = "simple";
|
serviceConfig = {
|
||||||
Restart = "on-failure";
|
User = cfg.user;
|
||||||
ExecStart = "${pkgs.komga}/bin/komga";
|
Group = cfg.group;
|
||||||
|
|
||||||
StateDirectory = mkIf (cfg.stateDir == "/var/lib/komga") "komga";
|
Type = "simple";
|
||||||
|
Restart = "on-failure";
|
||||||
|
ExecStart = getExe pkgs.komga;
|
||||||
|
|
||||||
|
StateDirectory = mkIf (cfg.stateDir == "/var/lib/komga") "komga";
|
||||||
|
|
||||||
|
RemoveIPC = true;
|
||||||
|
NoNewPrivileges = true;
|
||||||
|
CapabilityBoundingSet = "";
|
||||||
|
SystemCallFilter = [ "@system-service" ];
|
||||||
|
ProtectSystem = "full";
|
||||||
|
PrivateTmp = true;
|
||||||
|
ProtectProc = "invisible";
|
||||||
|
ProtectClock = true;
|
||||||
|
ProcSubset = "pid";
|
||||||
|
PrivateUsers = true;
|
||||||
|
PrivateDevices = true;
|
||||||
|
ProtectHostname = true;
|
||||||
|
ProtectKernelTunables = true;
|
||||||
|
RestrictAddressFamilies = [
|
||||||
|
"AF_INET"
|
||||||
|
"AF_INET6"
|
||||||
|
"AF_NETLINK"
|
||||||
|
];
|
||||||
|
LockPersonality = true;
|
||||||
|
RestrictNamespaces = true;
|
||||||
|
ProtectKernelLogs = true;
|
||||||
|
ProtectControlGroups = true;
|
||||||
|
ProtectKernelModules = true;
|
||||||
|
SystemCallArchitectures = "native";
|
||||||
|
RestrictSUIDSGID = true;
|
||||||
|
RestrictRealtime = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
meta.maintainers = with maintainers; [ govanify ];
|
meta.maintainers = with maintainers; [ govanify ];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue