2018-01-29 22:37:25 +01:00
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
cfg = config.services.ofborg;
|
|
|
|
|
user = config.users.users.ofborg;
|
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
options = {
|
|
|
|
|
services.ofborg.enable = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
2024-04-14 23:02:32 +02:00
|
|
|
|
description = "Whether to enable the ofborg builder service.";
|
2018-01-29 22:37:25 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.ofborg.package = mkOption {
|
|
|
|
|
type = types.package;
|
2021-10-23 15:05:52 +02:00
|
|
|
|
example = literalExpression "pkgs.ofborg";
|
2024-04-14 23:02:32 +02:00
|
|
|
|
description = ''
|
2018-01-29 22:37:25 +01:00
|
|
|
|
This option specifies the ofborg package to use. eg.
|
|
|
|
|
|
2019-05-04 14:43:11 +02:00
|
|
|
|
(import <ofborg> {}).ofborg.rs
|
2018-01-29 22:37:25 +01:00
|
|
|
|
|
|
|
|
|
$ nix-channel --add https://github.com/NixOS/ofborg/archive/released.tar.gz ofborg
|
|
|
|
|
$ nix-channel --update
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.ofborg.configFile = mkOption {
|
|
|
|
|
type = types.path;
|
2024-04-14 23:02:32 +02:00
|
|
|
|
description = ''
|
2018-01-29 22:37:25 +01:00
|
|
|
|
Configuration file to use for ofborg.
|
|
|
|
|
|
|
|
|
|
WARNING Don't use a path literal or derivation for this,
|
|
|
|
|
that would expose credentials in the store making them world readable.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.ofborg.logFile = mkOption {
|
|
|
|
|
type = types.path;
|
|
|
|
|
default = "/var/log/ofborg.log";
|
2024-04-14 23:02:32 +02:00
|
|
|
|
description = "The logfile to use for the ofborg service.";
|
2018-01-29 22:37:25 +01:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
|
|
assertions = [
|
|
|
|
|
{ assertion = elem "ofborg" config.users.knownGroups; message = "set users.knownGroups to enable ofborg group"; }
|
|
|
|
|
{ assertion = elem "ofborg" config.users.knownUsers; message = "set users.knownUsers to enable ofborg user"; }
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
warnings = mkIf (isDerivation cfg.configFile) [
|
|
|
|
|
"services.ofborg.configFile is a derivation, credentials will be world readable"
|
|
|
|
|
];
|
|
|
|
|
|
2019-05-04 14:43:11 +02:00
|
|
|
|
services.ofborg.configFile = mkDefault "${user.home}/config.json";
|
|
|
|
|
|
2018-01-29 22:37:25 +01:00
|
|
|
|
launchd.daemons.ofborg = {
|
|
|
|
|
script = ''
|
|
|
|
|
git config --global user.email "ofborg@example.com"
|
|
|
|
|
git config --global user.name "OfBorg"
|
|
|
|
|
|
|
|
|
|
exec ${cfg.package}/bin/builder "${cfg.configFile}"
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
path = [ config.nix.package pkgs.bash pkgs.coreutils pkgs.curl pkgs.git ];
|
|
|
|
|
environment =
|
|
|
|
|
{ RUST_BACKTRACE = "1";
|
2019-05-17 10:22:22 +07:00
|
|
|
|
NIX_SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
|
2018-01-29 22:37:25 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
serviceConfig.KeepAlive = true;
|
|
|
|
|
serviceConfig.StandardErrorPath = cfg.logFile;
|
|
|
|
|
serviceConfig.StandardOutPath = cfg.logFile;
|
|
|
|
|
|
|
|
|
|
serviceConfig.GroupName = "ofborg";
|
|
|
|
|
serviceConfig.UserName = "ofborg";
|
|
|
|
|
serviceConfig.WorkingDirectory = user.home;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
users.users.ofborg.uid = mkDefault 531;
|
|
|
|
|
users.users.ofborg.gid = mkDefault config.users.groups.ofborg.gid;
|
|
|
|
|
users.users.ofborg.home = mkDefault "/var/lib/ofborg";
|
|
|
|
|
users.users.ofborg.shell = "/bin/bash";
|
|
|
|
|
users.users.ofborg.description = "OfBorg service user";
|
|
|
|
|
|
|
|
|
|
users.groups.ofborg.gid = mkDefault 531;
|
|
|
|
|
users.groups.ofborg.description = "Nix group for OfBorg service";
|
|
|
|
|
|
|
|
|
|
# FIXME: create logfiles automatically if defined.
|
|
|
|
|
system.activationScripts.preActivation.text = ''
|
2018-03-05 23:00:50 +01:00
|
|
|
|
mkdir -p '${user.home}'
|
|
|
|
|
touch '${cfg.logFile}'
|
|
|
|
|
chown ${toString user.uid}:${toString user.gid} '${user.home}' '${cfg.logFile}'
|
2018-01-29 22:37:25 +01:00
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
system.activationScripts.postActivation.text = ''
|
2018-03-05 23:00:50 +01:00
|
|
|
|
if ! test -f '${cfg.configFile}'; then
|
2018-01-29 22:37:25 +01:00
|
|
|
|
echo >&2 "[1;31mwarning: ofborg config \"${cfg.configFile}\" does not exist[0m"
|
|
|
|
|
fi
|
|
|
|
|
|
2018-03-05 23:00:50 +01:00
|
|
|
|
chmod 600 '${cfg.configFile}'
|
|
|
|
|
chown ${toString user.uid}:${toString user.gid} '${cfg.configFile}'
|
2018-01-29 22:37:25 +01:00
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|