2023-06-05 21:52:51 +00:00
|
|
|
flake: { config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
2023-06-06 01:07:31 +00:00
|
|
|
inherit (lib) mapAttrsToList mkEnableOption mkMerge mkOption types;
|
|
|
|
intakeCfg = config.services.intake;
|
2023-06-05 21:52:51 +00:00
|
|
|
in {
|
|
|
|
options = {
|
2023-06-06 01:07:31 +00:00
|
|
|
services.intake = {
|
|
|
|
listen.addr = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0.0.0.0";
|
|
|
|
description = "Listen address for the nginx entry point.";
|
|
|
|
};
|
|
|
|
|
|
|
|
listen.port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 80;
|
|
|
|
description = "Listen port for the nginx entry point.";
|
|
|
|
};
|
|
|
|
|
|
|
|
users = mkOption {
|
|
|
|
description = "User intake service definitions.";
|
|
|
|
default = {};
|
|
|
|
type = types.attrsOf (types.submodule {
|
|
|
|
options = {
|
|
|
|
enable = mkEnableOption "intake, a personal feed aggregator.";
|
|
|
|
|
|
|
|
packages = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [];
|
|
|
|
description = "Additional packages available to the intake service.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
2023-06-05 21:52:51 +00:00
|
|
|
};
|
|
|
|
|
2023-06-06 01:07:31 +00:00
|
|
|
config =
|
|
|
|
let
|
|
|
|
# Define the intake package and a python environment to run it from
|
|
|
|
intake = flake.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
|
|
|
pythonEnv = pkgs.python38.withPackages (pypkgs: [ intake ]);
|
|
|
|
in {
|
|
|
|
systemd.services =
|
|
|
|
let
|
|
|
|
runScript = userName: pkgs.writeShellScript "intake-run.sh" ''
|
|
|
|
${pythonEnv}/bin/intake run -d /home/${userName}/.local/share/intake
|
|
|
|
'';
|
|
|
|
# systemd service definition for a single user, given `services.intake.users.userName` = `userCfg`
|
|
|
|
userServiceConfig = userName: userCfg: {
|
|
|
|
"intake@${userName}" = {
|
|
|
|
description = "Intake service for user ${userName}";
|
|
|
|
script = "${runScript userName}";
|
|
|
|
path = userCfg.packages;
|
|
|
|
serviceConfig = {
|
|
|
|
User = userName;
|
|
|
|
Type = "simple";
|
|
|
|
};
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
enable = userCfg.enable;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in mkMerge (mapAttrsToList userServiceConfig intakeCfg.users);
|
2023-06-05 21:52:51 +00:00
|
|
|
};
|
2023-06-06 01:07:31 +00:00
|
|
|
}
|