Hagia
log in
morj / hagia
overview
files
history
wiki
Viewing at
{ config, lib, pkgs, ... }:

let
cfg = config.services.hagia;
hagia = import /home/morj/projects/hagia/default.nix {inherit pkgs;};
in {
options.services.hagia = {
enable = lib.mkEnableOption "hagia";

port = lib.mkOption {
type = lib.types.port;
default = 8050;
description = lib.mdDoc ''
TCP port to listen on
'';
};

host = lib.mkOption {
type = lib.types.str;
default = "localhost";
example = "0.0.0.0";
description = lib.mdDoc ''
Address to bind to
'';
};

baseUrl = lib.mkOption {
type = lib.types.str;
example = "https://example.org";
description = lib.mdDoc ''
The base URL from which Hagia is accessed.
'';
};

user = lib.mkOption {
type = lib.types.str;
default = "hagia";
example = "yourUser";
description = lib.mdDoc ''
The user to service as. By default, a user named 'hagia' will be created.
'';
};

group = lib.mkOption {
type = lib.types.str;
default = "hagia";
example = "yourGroup";
description = lib.mdDoc ''
The group to service as. By default, a group named 'hagia' will be created.
'';
};

logLevel = lib.mkOption {
type = lib.types.enum [ "trace" "debug" "info" "warning" "error" "fatal" ];
default = "info";
description = lib.mdDoc ''
Log level of service
'';
};

projectsRootPath = lib.mkOption {
type = lib.types.path;
example = "/srv/hagia";
description = lib.mdDoc ''
Location to store git repositories in
'';
};

databasePath = lib.mkOption {
type = lib.types.path;
default = "/local/share/hagia/database.sqlite3";
description = lib.mdDoc ''
Location to create database at
'';
};
};

config = lib.mkIf cfg.enable {
users.users = lib.mkIf (cfg.user == "hagia") {
hagia = {
group = cfg.group;
createHome = false;
description = "Hagia daemon user";
isNormalUser = false;
isSystemUser = true;
};
};
users.groups = lib.mkIf (cfg.group == "hagia") {
hagia = {
};
};

systemd.packages = [hagia];

systemd.services.hagia = {
description = "Hagia git server";
after = [ "network-online.target" ];

environment = {
HAGIA_LOGLEVEL = cfg.logLevel;
};

serviceConfig = {
User = cfg.user;
Group = cfg.group;
ExecStart = ''${hagia}/bin/hagia-server \
"--port=${toString cfg.port}" \
"--host=${cfg.host}" \
"--base-url=${cfg.baseUrl}" \
"--projects-path=${cfg.projectsRootPath}" \
"--database=${cfg.databasePath}" \
"--git-executable=${pkgs.git}/bin/git"
'';

Restart = "on-failure";
StandardOutput = "journal";
StandardError = "journal";
};
};
};
}