photoncloud-monorepo/nix/modules/iam.nix
centra baa3e038f9 Add NixOS service modules to git tracking
The nix/modules directory was untracked, causing flake evaluation to fail
when referencing ./nix/modules. This adds 9 service module definitions
created during T024 NixOS packaging.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-09 17:34:41 +09:00

76 lines
1.8 KiB
Nix

{ config, lib, pkgs, ... }:
let
cfg = config.services.iam;
in
{
options.services.iam = {
enable = lib.mkEnableOption "iam service";
port = lib.mkOption {
type = lib.types.port;
default = 3000;
description = "Port for iam API";
};
dataDir = lib.mkOption {
type = lib.types.path;
default = "/var/lib/iam";
description = "Data directory for iam";
};
settings = lib.mkOption {
type = lib.types.attrs;
default = {};
description = "Additional configuration settings";
};
package = lib.mkOption {
type = lib.types.package;
default = pkgs.iam-server or (throw "iam-server package not found");
description = "Package to use for iam";
};
};
config = lib.mkIf cfg.enable {
# Create system user
users.users.iam = {
isSystemUser = true;
group = "iam";
description = "IAM service user";
home = cfg.dataDir;
};
users.groups.iam = {};
# Create systemd service
systemd.services.iam = {
description = "IAM Identity and Access Management Service";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" "flaredb.service" ];
requires = [ "flaredb.service" ];
serviceConfig = {
Type = "simple";
User = "iam";
Group = "iam";
Restart = "on-failure";
RestartSec = "10s";
# State directory management
StateDirectory = "iam";
StateDirectoryMode = "0750";
# Security hardening
NoNewPrivileges = true;
PrivateTmp = true;
ProtectSystem = "strict";
ProtectHome = true;
ReadWritePaths = [ cfg.dataDir ];
# Start command
ExecStart = "${cfg.package}/bin/iam-server --port ${toString cfg.port} --data-dir ${cfg.dataDir}";
};
};
};
}