nixos-config/services/site-max.nix

83 lines
2.1 KiB
Nix
Raw Normal View History

2018-05-10 19:00:14 +02:00
{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.services.site-max;
in
{
options.services.site-max = {
enable = mkEnableOption "Site Max Spiegel";
port = mkOption {
type = types.int;
example = 54321;
description = "Local listening port";
};
2018-05-17 15:43:35 +02:00
domaine = mkOption {
type = types.str;
example = "example.com";
description = "Domaine à utiliser";
};
2018-05-10 19:00:14 +02:00
};
config = mkIf cfg.enable {
nixpkgs.overlays = [
(import ../overlays/site-max.nix)
];
2018-05-10 19:00:14 +02:00
services.haproxy-acme.services = {
2018-05-17 15:43:35 +02:00
${cfg.domaine} = { ip = "127.0.0.1"; port = cfg.port; auth = false; };
2018-05-10 19:00:14 +02:00
};
2018-09-16 16:29:26 +02:00
services.nginx = {
virtualHosts = {
"max" = {
listen = [ { addr = "127.0.0.1"; port = cfg.port; } ];
locations."/" = {
root = "/run/site-max/result";
};
2018-05-10 19:00:14 +02:00
};
};
};
2018-09-16 16:29:26 +02:00
systemd.services.build-site-max = {
description = "Compilation du site de Max Spiegel";
requires = ["network-online.target"];
path = with pkgs;[ git nix ];
environment = { HOME = "/var/lib/site-max"; NIX_PATH = "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs"; };
serviceConfig = {
DynamicUser = true;
RuntimeDirectory = "site-max";
RuntimeDirectoryPreserve = "yes";
CacheDirectory = "site-max";
Type = "oneshot";
ExecStart = "${pkgs.writeShellScriptBin "build.sh" ''
set -x
set -e
GIT_CLONE_DIR=/var/cache/site-max
if [ ! -d $GIT_CLONE_DIR/.git ]; then
git clone --depth 1 https://github.com/nyanloutre/site-max.git $GIT_CLONE_DIR
else
git -C $GIT_CLONE_DIR pull
fi
nix-build -o /run/site-max/result $GIT_CLONE_DIR
''}/bin/build.sh";
};
};
systemd.timers.build-site-max = {
description = "Timer de compilation du site de Max";
requires = ["network-online.target"];
wantedBy = ["multi-user.target"];
timerConfig = { OnCalendar = "*:0/5"; Unit = "build-site-max.service"; };
};
2018-05-10 19:00:14 +02:00
};
}