markoburcul 08d7fbdd2e
nix: simplified codex service definition
configObject option is used to define the configuration which is then
dumped to a toml file and is used as input to codex
binary(conditionally).

Signed-off-by: markoburcul <marko@status.im>
2025-01-09 20:09:06 +01:00

59 lines
1.6 KiB
Nix

{ config, lib, pkgs, ... }:
let
inherit (lib)
types mkEnableOption mkOption mkIf literalExpression;
toml = pkgs.formats.toml { };
cfg = config.services.codex;
in
{
options = {
services.codex = {
enable = mkEnableOption "Codex Node service.";
package = mkOption {
type = types.package;
default = pkgs.callPackage ./default.nix { };
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.";
};
configObject = lib.mkOption {
default = { };
type = toml.type;
description = ''Structured settings object that will be used to generate a TOML config file.'';
};
};
};
config = mkIf cfg.enable {
environment.etc = {
"codex/config.toml".source = toml.generate "config.toml" cfg.configObject;
};
systemd.services.codex = {
description = "Codex Node";
wantedBy = [ "multi-user.target" ];
requires = [ "network.target" ];
serviceConfig = {
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"}'';
Restart = "on-failure";
};
};
};
}