2018-09-16 19:47:47 +00:00
|
|
|
{ config, lib, options, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
name = "headphones";
|
|
|
|
|
|
|
|
cfg = config.services.headphones;
|
|
|
|
opt = options.services.headphones;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.headphones = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Whether to enable the headphones server.";
|
2018-09-16 19:47:47 +00:00
|
|
|
};
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/${name}";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Path where to store data files.";
|
2018-09-16 19:47:47 +00:00
|
|
|
};
|
|
|
|
configFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "${cfg.dataDir}/config.ini";
|
|
|
|
defaultText = literalExpression ''"''${config.${opt.dataDir}}/config.ini"'';
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Path to config file.";
|
2018-09-16 19:47:47 +00:00
|
|
|
};
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Host to listen on.";
|
2018-09-16 19:47:47 +00:00
|
|
|
};
|
|
|
|
port = mkOption {
|
|
|
|
type = types.ints.u16;
|
|
|
|
default = 8181;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Port to bind to.";
|
2018-09-16 19:47:47 +00:00
|
|
|
};
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = name;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "User to run the service as";
|
2018-09-16 19:47:47 +00:00
|
|
|
};
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = name;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Group to run the service as";
|
2018-09-16 19:47:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2019-09-14 17:51:29 +00: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 19:47:47 +00:00
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.groups = optionalAttrs (cfg.group == name) {
|
|
|
|
${name}.gid = config.ids.gids.headphones;
|
|
|
|
};
|
2018-09-16 19:47:47 +00: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}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|