config/modules/services/immich/default.nix

87 lines
2.7 KiB
Nix
Raw Normal View History

2024-09-27 15:03:43 +03:00
{
config,
lib,
pkgs,
myData,
nixpkgs-unstable,
...
}:
let
cfg = config.mj.services.immich;
2024-09-27 23:20:15 +03:00
immich-package = pkgs.pkgs-unstable.immich;
2024-09-29 22:33:46 +03:00
immich-user = config.services.immich.user;
immich-group = config.services.immich.group;
startScript = pkgs.writeShellApplication {
name = "immich-mj";
runtimeInputs = with pkgs; [ bindfs ];
text = ''
set -x
${lib.concatLines (
map (name: ''
mkdir /data/${name}
bindfs -u ${cfg.bindAsUser} /var/cache/immich/bind-paths/${name} /data/${name}
'') (lib.attrNames cfg.bindPaths)
)}
exec ${config.security.wrapperDir}/doas -u ${immich-user} ${lib.getExe immich-package}
'';
};
2024-09-27 15:03:43 +03:00
in
{
options.mj.services.immich = with lib.types; {
enable = lib.mkEnableOption "enable immich";
2024-09-27 20:04:41 +03:00
bindPaths = lib.mkOption { type = attrsOf str; };
bindAsUser = lib.mkOption { type = str; };
2024-09-27 15:03:43 +03:00
};
imports = [ "${nixpkgs-unstable}/nixos/modules/services/web-apps/immich.nix" ];
config = lib.mkIf cfg.enable {
2024-09-29 22:33:46 +03:00
security.doas.enable = true;
2024-09-27 15:03:43 +03:00
services.immich = {
2024-09-27 23:20:15 +03:00
package = immich-package;
2024-09-27 15:03:43 +03:00
enable = true;
2024-09-27 15:11:54 +03:00
port = myData.ports.immich-server;
2024-09-27 15:03:43 +03:00
};
2024-09-27 15:56:20 +03:00
services.caddy.virtualHosts."photos2.jakstys.lt:80".extraConfig = ''
2024-09-27 15:46:44 +03:00
@denied not remote_ip ${myData.subnets.tailscale.cidr}
2024-09-27 16:01:47 +03:00
reverse_proxy localhost:${toString myData.ports.immich-server}
2024-09-27 15:46:44 +03:00
'';
2024-09-27 15:03:43 +03:00
2024-09-27 20:04:41 +03:00
systemd = {
2024-09-29 22:33:46 +03:00
tmpfiles.rules = [
"d /data 0755 root root -"
"d /var/cache/immich/bind-paths 0755 ${immich-user} ${immich-group} -"
];
2024-09-27 20:04:41 +03:00
services.immich-server.serviceConfig = {
2024-09-29 22:33:46 +03:00
RuntimeDirectory = "immich";
2024-09-27 23:20:15 +03:00
TemporaryFileSystem = "/data";
2024-09-29 22:33:46 +03:00
BindPaths = lib.mapAttrsToList (
name: srcpath: "${srcpath}:/var/cache/immich/bind-paths/${name}"
) cfg.bindPaths;
2024-09-27 23:20:15 +03:00
PrivateDevices = lib.mkForce false; # /dev/fuse
2024-09-29 19:47:40 +03:00
ProtectHome = lib.mkForce false; # binding /home/motiejus
2024-09-29 22:33:46 +03:00
CapabilityBoundingSet = lib.mkForce "CAP_SYS_ADMIN | CAP_SETUID | CAP_SETGID";
2024-09-29 19:47:40 +03:00
# testing
2024-09-29 22:33:46 +03:00
ExecStart = lib.mkForce ("!" + (lib.getExe startScript));
NoNewPrivileges = lib.mkForce false;
PrivateUsers = lib.mkForce false;
PrivateTmp = lib.mkForce false;
2024-09-29 19:47:40 +03:00
PrivateMounts = lib.mkForce false;
2024-09-29 22:33:46 +03:00
ProtectClock = lib.mkForce false;
ProtectControlGroups = lib.mkForce false;
ProtectHostname = lib.mkForce false;
ProtectKernelLogs = lib.mkForce false;
ProtectKernelModules = lib.mkForce false;
ProtectKernelTunables = lib.mkForce false;
RestrictNamespaces = lib.mkForce false;
RestrictRealtime = lib.mkForce false;
RestrictSUIDSGID = lib.mkForce false;
2024-09-27 20:04:41 +03:00
};
};
2024-09-27 15:03:43 +03:00
};
}