1 { config, lib, options, pkgs, ... }:
6 cfg = config.services.headphones;
7 opt = options.services.headphones;
16 services.headphones = {
17 enable = lib.mkOption {
18 type = lib.types.bool;
20 description = "Whether to enable the headphones server.";
22 dataDir = lib.mkOption {
23 type = lib.types.path;
24 default = "/var/lib/${name}";
25 description = "Path where to store data files.";
27 configFile = lib.mkOption {
28 type = lib.types.path;
29 default = "${cfg.dataDir}/config.ini";
30 defaultText = lib.literalExpression ''"''${config.${opt.dataDir}}/config.ini"'';
31 description = "Path to config file.";
35 default = "localhost";
36 description = "Host to listen on.";
39 type = lib.types.ints.u16;
41 description = "Port to bind to.";
46 description = "User to run the service as";
48 group = lib.mkOption {
51 description = "Group to run the service as";
59 config = lib.mkIf cfg.enable {
61 users.users = lib.optionalAttrs (cfg.user == name) {
63 uid = config.ids.uids.headphones;
65 description = "headphones user";
71 users.groups = lib.optionalAttrs (cfg.group == name) {
72 ${name}.gid = config.ids.gids.headphones;
75 systemd.services.headphones = {
76 description = "Headphones Server";
77 wantedBy = [ "multi-user.target" ];
78 after = [ "network.target" ];
82 ExecStart = "${pkgs.headphones}/bin/headphones --datadir ${cfg.dataDir} --config ${cfg.configFile} --host ${cfg.host} --port ${toString cfg.port}";