1
0
Fork 0

homu: prepare nixos integration

gitea issue #10
This commit is contained in:
Astro 2019-04-30 22:38:58 +02:00
parent 78764bab8e
commit f684ad7f55
3 changed files with 105 additions and 1 deletions

View File

@ -8,6 +8,7 @@
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
./homu/nixos-module.nix
];
# Use the systemd-boot EFI boot loader.
@ -243,6 +244,17 @@ ACTION=="add", SUBSYSTEM=="tty", \
};
};
# services.homu = {
# enable = true;
# # See https://github.com/servo/homu/blob/master/cfg.sample.toml
# config = {
# max_priority = 9001;
# github = {
# access_token = "...";
# };
# };
# };
# This value determines the NixOS release with which your system is to be
# compatible, in order to avoid breaking some software such as database
# servers. You should change this only after NixOS release notes say you

View File

@ -0,0 +1,92 @@
{ config, pkgs, lib, ... }:
with lib;
let
homu = pkgs.callPackage ./pkg.nix {};
toToml = key: value:
let valueString =
if builtins.isString value
then "\"" + (builtins.replaceStrings ["\"" "\\"] ["\\\"" "\\\\"] value) + "\""
else toString value;
in "${key} = ${valueString}\n";
defaultConfig = {
db = {
file = "/var/db/homu/main.db";
};
};
cfg = config.services.homu;
homuConfig = defaultConfig // cfg.config;
configFilter = f:
filterAttrs (key: value: f value) homuConfig;
topLevelConfig =
configFilter (value: ! builtins.isAttrs value);
configSections =
configFilter (value: builtins.isAttrs value);
configFile = builtins.toFile "config.toml" (
builtins.concatStringsSep "" (
(attrsets.mapAttrsToList toToml topLevelConfig) ++
(builtins.concatLists (attrsets.mapAttrsToList
(sectionName: sectionConfig:
[ "[${sectionName}]\n" ] ++
(attrsets.mapAttrsToList toToml sectionConfig)
) configSections)
))
);
dbFile = homuConfig.db.file;
in
{
options.services.homu = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable the bot";
};
user = mkOption {
type = types.str;
default = "nobody";
};
group = mkOption {
type = types.str;
default = "nogroup";
};
config = mkOption {
description = "Structured data for config.toml";
type = with types; attrsOf unspecified;
};
};
config = mkIf cfg.enable {
systemd.services.homu-dbdir = {
description = "Homu bot database directory";
serviceConfig = {
Type = "oneshot";
ExecStart = [
"${pkgs.coreutils}/bin/mkdir -p ${dirOf dbFile}"
"${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} ${dirOf dbFile}"
];
};
};
systemd.services.homu = {
description = "Homu bot";
wantedBy = [ "multi-user.target" ];
requires = [ "homu-dbdir.service" ];
after = [ "network.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${homu}/bin/homu -c ${configFile}";
Restart = "always";
RestartSec = "5sec";
User = cfg.user;
Group = cfg.group;
};
};
};
}

View File

@ -27,6 +27,6 @@ in
rev = "2ea53e76ebac3e5fa11bc39054b3cd4c42eff607";
sha256 = "1ih7s8zfbpq0qb9vqbxzr0r4s9ff52l4ipr916kwbck3ygliq3r9";
};
buildInputs = [ github3_py_0_9_6 ] ++ (with python3Packages; [ toml jinja2 requests bottle waitress retrying ]);
propagatedBuildInputs = [ github3_py_0_9_6 ] ++ (with python3Packages; [ toml jinja2 requests bottle waitress retrying ]);
checkPhase = "python -m unittest discover tests -v";
}