|
1 | 1 | { config, lib, pkgs, ... }: |
2 | | - |
3 | | -with pkgs; |
4 | | -with lib; |
5 | | - |
6 | 2 | let |
7 | 3 | uid = config.ids.uids.mopidy; |
8 | 4 | gid = config.ids.gids.mopidy; |
9 | 5 | cfg = config.services.mopidy; |
10 | 6 |
|
11 | | - mopidyConf = writeText "mopidy.conf" cfg.configuration; |
| 7 | + mopidyConf = pkgs.writeText "mopidy.conf" cfg.configuration; |
12 | 8 |
|
13 | | - mopidyEnv = buildEnv { |
14 | | - name = "mopidy-with-extensions-${mopidy.version}"; |
| 9 | + mopidyEnv = pkgs.buildEnv { |
| 10 | + name = "mopidy-with-extensions-${pkgs.mopidy.version}"; |
15 | 11 | ignoreCollisions = true; |
16 | | - paths = closePropagation cfg.extensionPackages; |
17 | | - pathsToLink = [ "/${mopidyPackages.python.sitePackages}" ]; |
18 | | - nativeBuildInputs = [ makeWrapper ]; |
| 12 | + paths = lib.closePropagation cfg.extensionPackages; |
| 13 | + pathsToLink = [ "/${pkgs.mopidyPackages.python.sitePackages}" ]; |
| 14 | + nativeBuildInputs = [ pkgs.makeWrapper ]; |
19 | 15 | postBuild = '' |
20 | | - makeWrapper ${mopidy}/bin/mopidy $out/bin/mopidy \ |
21 | | - --prefix PYTHONPATH : $out/${mopidyPackages.python.sitePackages} |
| 16 | + makeWrapper ${lib.getExe pkgs.mopidy} $out/bin/mopidy \ |
| 17 | + --prefix PYTHONPATH : $out/${pkgs.mopidyPackages.python.sitePackages} |
22 | 18 | ''; |
23 | 19 | }; |
24 | 20 | in { |
|
27 | 23 |
|
28 | 24 | services.mopidy = { |
29 | 25 |
|
30 | | - enable = mkEnableOption "Mopidy, a music player daemon"; |
| 26 | + enable = lib.mkEnableOption "Mopidy, a music player daemon"; |
31 | 27 |
|
32 | | - dataDir = mkOption { |
| 28 | + dataDir = lib.mkOption { |
33 | 29 | default = "/var/lib/mopidy"; |
34 | | - type = types.str; |
| 30 | + type = lib.types.str; |
35 | 31 | description = '' |
36 | 32 | The directory where Mopidy stores its state. |
37 | 33 | ''; |
38 | 34 | }; |
39 | 35 |
|
40 | | - extensionPackages = mkOption { |
| 36 | + extensionPackages = lib.mkOption { |
41 | 37 | default = []; |
42 | | - type = types.listOf types.package; |
43 | | - example = literalExpression "[ pkgs.mopidy-spotify ]"; |
| 38 | + type = lib.types.listOf lib.types.package; |
| 39 | + example = lib.literalExpression "[ pkgs.mopidy-spotify ]"; |
44 | 40 | description = '' |
45 | 41 | Mopidy extensions that should be loaded by the service. |
46 | 42 | ''; |
47 | 43 | }; |
48 | 44 |
|
49 | | - configuration = mkOption { |
| 45 | + configuration = lib.mkOption { |
50 | 46 | default = ""; |
51 | | - type = types.lines; |
| 47 | + type = lib.types.lines; |
52 | 48 | description = '' |
53 | 49 | The configuration that Mopidy should use. |
54 | 50 | ''; |
55 | 51 | }; |
56 | 52 |
|
57 | | - extraConfigFiles = mkOption { |
| 53 | + extraConfigFiles = lib.mkOption { |
58 | 54 | default = []; |
59 | | - type = types.listOf types.str; |
| 55 | + type = lib.types.listOf lib.types.str; |
60 | 56 | description = '' |
61 | 57 | Extra config file read by Mopidy when the service starts. |
62 | 58 | Later files in the list overrides earlier configuration. |
63 | 59 | ''; |
64 | 60 | }; |
65 | | - |
66 | 61 | }; |
67 | | - |
68 | 62 | }; |
69 | 63 |
|
70 | 64 | ###### implementation |
71 | 65 |
|
72 | | - config = mkIf cfg.enable { |
| 66 | + config = lib.mkIf cfg.enable { |
73 | 67 |
|
74 | 68 | systemd.tmpfiles.settings."10-mopidy".${cfg.dataDir}.d = { |
75 | 69 | user = "mopidy"; |
|
82 | 76 | wants = [ "network-online.target" ]; |
83 | 77 | description = "mopidy music player daemon"; |
84 | 78 | serviceConfig = { |
85 | | - ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)}"; |
| 79 | + ExecStart = "${mopidyEnv}/bin/mopidy --config ${lib.concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)}"; |
86 | 80 | User = "mopidy"; |
87 | 81 | }; |
88 | 82 | }; |
89 | 83 |
|
90 | 84 | systemd.services.mopidy-scan = { |
91 | 85 | description = "mopidy local files scanner"; |
92 | 86 | serviceConfig = { |
93 | | - ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)} local scan"; |
| 87 | + ExecStart = "${mopidyEnv}/bin/mopidy --config ${lib.concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)} local scan"; |
94 | 88 | User = "mopidy"; |
95 | 89 | Type = "oneshot"; |
96 | 90 | }; |
|
105 | 99 | }; |
106 | 100 |
|
107 | 101 | users.groups.mopidy.gid = gid; |
108 | | - |
109 | 102 | }; |
110 | | - |
111 | 103 | } |
0 commit comments