summary refs log tree commit diff
path: root/modules/services/networking/amuled.nix
blob: 658d16af006cf57bb94715adda5dfea4d808c57a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{ config, pkgs, ... }:

with pkgs.lib;

let
  cfg = config.services.amule;
  user = if cfg.user != null then cfg.user else "amule";
in

{

  ###### interface

  options = {

    services.amule = {

      enable = mkOption {
        default = false;
        description = ''
          Whether to run the AMule daemon. You need to manually run "amuled --ec-config" to configure the service for the first time.
        '';
      };

      dataDir = mkOption {
        default = ''/home/${user}/'';
        description = ''
          The directory holding configuration, incoming and temporary files.
        '';
      };

      user = mkOption {
        default = null;
        description = ''
          The user the AMule daemon should run as.
        '';
      };

    };

  };


  ###### implementation

  config = mkIf cfg.enable {

    users.extraUsers = mkIf (cfg.user == null) [
      { name = "amule";
        description = "AMule daemon";
      } ];

    jobs.amuled =
      { description = "AMule daemon";

        startOn = "ip-up";

        preStart = ''
            mkdir -p ${cfg.dataDir}
            chown ${user} ${cfg.dataDir}
        '';

        exec = ''
            ${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} ${user} \
                -c 'HOME="${cfg.dataDir}" ${pkgs.amuleDaemon}/bin/amuled'
        '';
      };

  };

}