{ makise-next, }: { config, lib, pkgs, ... }: let types = lib.types; cfg = config.services.makise-next; toml = pkgs.formats.toml {}; configs = let generated = (if cfg.config != null then [(toml.generate "config.toml" cfg.config)] else []); all = generated ++ cfg.configFiles; in builtins.map (x: "--config ${x}") all; configParameters = lib.strings.concatStringsSep " " configs; in { options.services.viendesu-maid = { autoStart = lib.mkOption { description = "start Maid with the system"; type = types.bool; default = false; }; user = lib.mkOption { description = "user under which Maid will run"; type = types.str; }; enable = lib.mkEnableOption "viendesu-maid"; config = lib.mkOption { description = "configuration for the Maid"; type = types.nullOr types.attrs; default = null; }; configFiles = lib.mkOption { description = "list of configuration files for Maid"; type = types.listOf types.str; default = []; }; environment = lib.mkOption { description = "list of environment variables"; type = types.attrs; default = {}; }; environmentFiles = lib.mkOption { description = "environment variables files"; type = types.listOf types.str; default = []; }; }; config = { systemd.services.viendesu-maid = lib.mkIf cfg.enable { wantedBy = lib.mkIf cfg.autoStart [ "multi-user.target" ]; after = [ "network.target" ]; description = "VienDesu! Maid bot"; serviceConfig = { Type = "simple"; User = cfg.user; ExecStart = "${makise-next} ${configParameters}"; EnvironmentFile = cfg.environmentFiles; Environment = builtins.map ({ name, value }: "${name}=${value}") (lib.attrsets.attrsToList cfg.environment); }; }; }; }