2025-01-09 18:29:14 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
inherit (lib)
|
2025-01-09 20:09:06 +01:00
|
|
|
types mkEnableOption mkOption mkIf literalExpression;
|
|
|
|
|
|
|
|
|
|
toml = pkgs.formats.toml { };
|
2025-01-09 18:29:14 +01:00
|
|
|
|
|
|
|
|
cfg = config.services.codex;
|
2025-01-09 20:09:06 +01:00
|
|
|
in
|
|
|
|
|
{
|
2025-01-09 18:29:14 +01:00
|
|
|
options = {
|
|
|
|
|
services.codex = {
|
|
|
|
|
enable = mkEnableOption "Codex Node service.";
|
|
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
|
type = types.package;
|
2025-01-09 20:09:06 +01:00
|
|
|
default = pkgs.callPackage ./default.nix { };
|
2025-01-09 18:29:14 +01:00
|
|
|
defaultText = literalExpression "pkgs.codex";
|
|
|
|
|
description = lib.mdDoc "Package to use as Codex node.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
configFile = mkOption {
|
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
|
|
|
|
description = "Path to the Codex configuration file.";
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-09 20:09:06 +01:00
|
|
|
configObject = lib.mkOption {
|
|
|
|
|
default = { };
|
|
|
|
|
type = toml.type;
|
|
|
|
|
description = ''Structured settings object that will be used to generate a TOML config file.'';
|
2025-01-09 18:29:14 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2025-01-09 20:09:06 +01:00
|
|
|
environment.etc = {
|
|
|
|
|
"codex/config.toml".source = toml.generate "config.toml" cfg.configObject;
|
2025-01-09 18:29:14 +01:00
|
|
|
};
|
|
|
|
|
systemd.services.codex = {
|
|
|
|
|
description = "Codex Node";
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
requires = [ "network.target" ];
|
|
|
|
|
serviceConfig = {
|
2025-01-09 20:09:06 +01:00
|
|
|
DynamicUser = true;
|
|
|
|
|
PrivateTmp = true;
|
|
|
|
|
ProtectHome = true;
|
|
|
|
|
ProtectSystem = "full";
|
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
|
PrivateDevices = true;
|
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
|
ExecStart = ''${cfg.package}/bin/codex --config-file=${if cfg.configFile != null then cfg.configFile else "/etc/codex/config.toml"}'';
|
2025-01-09 18:29:14 +01:00
|
|
|
Restart = "on-failure";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|