1
1
Fork 0
nixos-configs/inquisitor.nix

99 lines
2.8 KiB
Nix
Raw Normal View History

2020-12-29 11:18:23 +00:00
{pkgs, ...}:
let
2020-12-30 01:32:46 +00:00
# Import the inquisitor package and build it
2020-12-29 18:21:21 +00:00
inquisitorSource = pkgs.fetchFromGitHub {
2020-12-29 11:18:23 +00:00
owner = "Jaculabilis";
repo = "Inquisitor";
2020-12-30 06:07:52 +00:00
rev = "933596d25c183782a8864e0d8c47bc65a64a791d";
sha256 = "0haa67lpm8dm8k2inyvfqdvxi1lzvrkb65vgv8nzq51iwlydygx7";
2020-12-29 11:18:23 +00:00
};
2020-12-29 18:21:21 +00:00
inquisitor = pkgs.callPackage inquisitorSource {};
2020-12-29 11:18:23 +00:00
# Define the inquisitor data directory
inquisiDir = "/var/lib/inquisitor";
2020-12-30 01:32:46 +00:00
# Create the inquisitor config file in the nix store, pointing to /var/lib/
2020-12-29 18:21:21 +00:00
inquisitorConfig = pkgs.writeTextFile {
name = "inquisitor.conf";
text = ''
DataPath = ${inquisiDir}/data/
SourcePath = ${inquisiDir}/sources/
CachePath = ${inquisiDir}/cache/
2020-12-29 18:21:21 +00:00
Verbose = false
LogFile = /var/log/inquisitor.log
'';
};
2020-12-30 01:32:46 +00:00
# Create a run script for the server that sets up all necessary state
2020-12-29 18:21:21 +00:00
inquisitorRun = pkgs.writeShellScriptBin "run.sh" ''
# Ensure inquisitor directories and inquisitor source folder
${pkgs.coreutils}/bin/mkdir -p ${inquisiDir}/data/inquisitor/
${pkgs.coreutils}/bin/mkdir -p ${inquisiDir}/sources/
${pkgs.coreutils}/bin/mkdir -p ${inquisiDir}/cache/
if [ ! -f ${inquisiDir}/data/inquisitor/state ]; then
${pkgs.coreutils}/bin/echo "{}" > ${inquisiDir}/data/inquisitor/state
2020-12-29 18:21:21 +00:00
fi
# Run inquisitor
cd ${inquisiDir}
2020-12-30 01:32:46 +00:00
${inquisitor}/bin/gunicorn \
--bind=localhost:24133 \
--workers=4 \
--env INQUISITOR_CONFIG=${inquisitorConfig} \
--log-level debug \
"inquisitor.app:wsgi()"
2020-12-29 18:21:21 +00:00
'';
# Create a wrapper script to let users call into inquisitor safely
inquisitorWrapper = pkgs.writeShellScriptBin "inq" ''
INQUISITOR_CONFIG=${inquisitorConfig} ${inquisitor}/bin/inquisitor "$@"
2020-12-29 11:18:23 +00:00
'';
in
{
# Create a user for the service
users.users.inquisitor = {
description = "Inquisitor service user";
isSystemUser = true;
home = "${inquisiDir}";
createHome = true;
2020-12-29 11:18:23 +00:00
packages = [ inquisitor ];
};
2020-12-29 18:21:21 +00:00
# Give all users the inq wrapper
environment.systemPackages = [ inquisitorWrapper ];
2020-12-29 11:18:23 +00:00
# Set up the inquisitor service
systemd.services.inquisitor =
{
2020-12-29 11:18:23 +00:00
description = "Inquisitor server";
2020-12-29 18:21:21 +00:00
script = "${inquisitorRun}/bin/run.sh";
2020-12-29 11:18:23 +00:00
serviceConfig = {
User = "inquisitor";
Type = "simple";
};
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
enable = true;
};
2020-12-30 02:09:58 +00:00
# Set up nginx to reverse proxy from the beatific url to the inq server
services.nginx.enable = true;
services.nginx.virtualHosts.inquisitorHost = {
listen = [ { addr = "10.7.3.99"; port = 80; } ];
locations."/".extraConfig = ''
access_log /var/log/nginx/access.inquisitor.log;
proxy_buffering off;
proxy_pass http://localhost:24133/;
'';
};
# Allow nginx through the firewall
networking.firewall = {
allowedTCPPorts = [
80 # http
443 # https
];
};
2020-12-29 11:18:23 +00:00
}