summaryrefslogtreecommitdiffstats
path: root/krebs/2configs/shack/muellshack.nix
blob: 3a8d1cd88f0a4a23ee8406eadabc72bbc05b647e (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
{ config, lib, pkgs, ... }:

let
  pkg = pkgs.callPackage (
    pkgs.fetchgit {
      url = "https://git.shackspace.de/rz/muellshack";
      rev = "d8a5e2d4c0a22804838675ac42b468299dcd9a76";
      sha256 = "0ff6q64dgdxmpszp94z100fdic175b1vvxn4crg8p0jcabzxsv0m";
    }) {};
    home = "/var/lib/muellshack";
    port = "8081";
in {
  users.users.muellshack = {
    inherit home;
    createHome = true;
  };
  services.nginx.virtualHosts."muell.shack" = {
    locations."/" = {
      proxyPass = "http://localhost:${port}/muellshack/";
    };
  };
  services.nginx.virtualHosts."openhab.shack" = {
    locations."/muellshack".proxyPass = "http://localhost:${port}";
  };
  systemd.services.muellshack = {
    description = "muellshack";
    wantedBy = [ "multi-user.target" ];
    environment.PORT = port;
    serviceConfig = {
      User = "muellshack";
      # do not override the current storage fil
      ExecStartPre = pkgs.writeDash "call-muell-pre" ''
        cp -vf ${pkg}/share/static_muelldata.json ${home}
        cp -vn  ${pkg}/share/storage.json ${home}
      '';
      WorkingDirectory = home;
      ExecStart = "${pkg}/bin/muellshack";
      Restart = "always";
      PrivateTmp = true;
    };
  };
}