summary refs log tree commit diff
path: root/nixos/modules/services/backup/almir.nix
blob: d5bc932c6b964e14dc1a2282e4207514e8523f09 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
{ config, pkgs, ... }:

with pkgs.lib;

let
  cfg = config.services.almir;

  bconsoleconf = pkgs.writeText "bconsole.conf"
    ''
      Director {
        Name = ${cfg.director_name}
        DIRport = ${toString cfg.director_port}
        address = ${cfg.director_address}
        Password = "${cfg.director_password}"
      }
    '';

  productionini = pkgs.writeText "production.ini"
    ''
[app:main]
use = egg:almir

pyramid.reload_templates = false
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.debug_templates = false
pyramid.default_locale_name = en
pyramid.includes =
    pyramid_exclog
exclog.extra_info = true

sqlalchemy.url = ${cfg.sqlalchemy_engine_url}
timezone = ${cfg.timezone}
bconsole_config = ${bconsoleconf}

[server:main]
use = egg:waitress#main
host = 127.0.0.1
port = ${toString cfg.port}


# Begin logging configuration

[loggers]
keys = root, almir, sqlalchemy, exc_logger

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console

[logger_almir]
level = WARN
handlers =
qualname = almir

[logger_exc_logger]
level = ERROR
handlers =
qualname = exc_logger

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
# "level = WARN" logs neither.  (Recommended for production systems.)

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
    '';
in {
  options = {
    services.almir = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Enable Almir web server. Also configures postgresql database and installs bacula.
        '';
      };

      port = mkOption {
        default = 35000;
        type = types.uniq types.int;
        description = ''
          Port for Almir web server to listen on.
        '';
      };

      timezone = mkOption {
	description = ''
         Timezone as specified in https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
        '';
        example = "Europe/Ljubljana";
      };

      sqlalchemy_engine_url = mkOption {
        example = ''
          postgresql://bacula:bacula@localhost:5432/bacula
          mysql+mysqlconnector://<user>:<password>@<hostname>/<database>'
          sqlite:////var/lib/bacula/bacula.db'
        '';
	description = ''
         Define SQL database connection to bacula catalog as specified in http://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls
        '';
      };

      director_name = mkOption {
        description = ''
          Name of the Director to connect with bconsole.
        '';
      };

      director_password = mkOption {
        description = ''
          Password for Director to connect with bconsole.
        '';
      };

      director_port = mkOption {
        default = 9101;
        type = types.int;
        description = ''
          Port for Director to connect with bconsole.
        '';
      };

      director_address = mkOption {
        default = "127.0.0.1";
        description = ''
          IP/Hostname for Director to connect with bconsole.
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.services.almir = {
      after = [ "network.target" "postgresql.service" ];
      description = "Almir web app";
      wantedBy = [ "multi-user.target" ];
      path = [ pkgs.pythonPackages.almir ];
      serviceConfig.ExecStart = "${pkgs.pythonPackages.almir}/bin/pserve ${productionini}";
    };

    environment.systemPackages = [ pkgs.pythonPackages.almir ];

    users.extraUsers.almir = {
      group = "almir";
      uid = config.ids.uids.almir;
      createHome = true;
      shell = "${pkgs.bash}/bin/bash";
    };

    users.extraGroups.almir.gid = config.ids.gids.almir;
  };
}