aboutsummaryrefslogtreecommitdiff
path: root/modules/apps/juandelacosa.nix
blob: d417727e1b457ba475c581e8e75c6d64457f6c03 (plain)
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
{ config, pkgs, lib, ... }:

let
  inherit (builtins) toString;
  inherit (lib) types mkOption mkEnableOption mkIf hasPrefix
                concatStrings optionalString;
  inherit (types) str path int nullOr;

  cfg = config.nixsap.apps.juandelacosa;

  ExecStart = concatStrings [
    "${pkgs.juandelacosa}/bin/juandelacosa"
    (optionalString (cfg.myFile != null) " -f '${cfg.myFile}'")
    (optionalString (cfg.myGroup != null) " -g ${cfg.myGroup}")
    (if (cfg.port != null)
      then " -p ${toString cfg.port}"
      else " -s '${cfg.socket}'")
  ];

in {
  options.nixsap.apps.juandelacosa = {
    enable = mkEnableOption "Juan de la Cosa";
    user = mkOption {
      description = "User to run as";
      default = "juandelacosa";
      type = str;
    };
    port = mkOption {
      description = "TCP port to listen on";
      default = null;
      type = nullOr int;
    };
    socket = mkOption {
      description = "UNIX socket to listen on. Ignored when TCP port is set";
      default = "/tmp/juandelacosa.sock";
      type = path;
    };
    myFile = mkOption {
      description = "MySQL client configuration file";
      default = null;
      type = nullOr path;
    };
    myGroup = mkOption {
      description = "Options group in the MySQL client configuration file";
      default = null;
      type = nullOr str;
    };
  };

  config = mkIf cfg.enable {
    nixsap.system.users.daemons = [ cfg.user ];
    nixsap.deployment.keyrings.${cfg.user} = [ cfg.myFile ];
    systemd.services.juandelacosa = {
      description = "captain of the MariaDB";
      wantedBy = [ "multi-user.target" ];
      wants = [ "keys.target" ];
      after = [ "keys.target" "network.target" "local-fs.target" ];
      serviceConfig = {
        inherit ExecStart;
        User = cfg.user;
        Restart = "on-failure";
      };
    };
  };
}