2021-12-05 21:28:49 +01:00
|
|
|
{ config, lib, options, pkgs, ... }:
|
2018-09-16 21:47:47 +02:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
name = "headphones";
|
|
|
|
|
|
|
|
cfg = config.services.headphones;
|
2021-12-05 21:28:49 +01:00
|
|
|
opt = options.services.headphones;
|
2018-09-16 21:47:47 +02:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.headphones = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the headphones server.";
|
|
|
|
};
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/${name}";
|
|
|
|
description = "Path where to store data files.";
|
|
|
|
};
|
|
|
|
configFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "${cfg.dataDir}/config.ini";
|
2021-12-05 21:28:49 +01:00
|
|
|
defaultText = literalExpression ''"''${config.${opt.dataDir}}/config.ini"'';
|
2018-09-16 21:47:47 +02:00
|
|
|
description = "Path to config file.";
|
|
|
|
};
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
|
|
|
description = "Host to listen on.";
|
|
|
|
};
|
|
|
|
port = mkOption {
|
|
|
|
type = types.ints.u16;
|
|
|
|
default = 8181;
|
|
|
|
description = "Port to bind to.";
|
|
|
|
};
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = name;
|
|
|
|
description = "User to run the service as";
|
|
|
|
};
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = name;
|
|
|
|
description = "Group to run the service as";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.users = optionalAttrs (cfg.user == name) {
|
|
|
|
${name} = {
|
|
|
|
uid = config.ids.uids.headphones;
|
|
|
|
group = cfg.group;
|
|
|
|
description = "headphones user";
|
|
|
|
home = cfg.dataDir;
|
|
|
|
createHome = true;
|
|
|
|
};
|
|
|
|
};
|
2018-09-16 21:47:47 +02:00
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.groups = optionalAttrs (cfg.group == name) {
|
|
|
|
${name}.gid = config.ids.gids.headphones;
|
|
|
|
};
|
2018-09-16 21:47:47 +02:00
|
|
|
|
|
|
|
systemd.services.headphones = {
|
|
|
|
description = "Headphones Server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
ExecStart = "${pkgs.headphones}/bin/headphones --datadir ${cfg.dataDir} --config ${cfg.configFile} --host ${cfg.host} --port ${toString cfg.port}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|