summary refs log tree commit diff stats
path: root/modules/shopping-list.nix
blob: c6d1158e57f7ab3d6e250c0eb0d6e7331e87b83a (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
{ config, pkgs, lib, ... }:

let
  shopping-list = pkgs.buildGoModule rec {
    pname = "shopping-list";
    version = "0.1";

    src = pkgs.fetchFromGitHub {
      owner = "ckrinitsin";
      repo = "shopping-list";
      rev = "26d70f0ea7b8dc84b2451b3965d9e81d7b25a9a8";
      hash = "sha256-HQqzia1KEWLu5y726HIbMH6YtcRBXxwSgURci/xY6x4=";
    };

    vendorHash = "sha256-++/WB1HChwnbwJcfghoGNCUzmfmbtqH/7MJTAyj31Rc=";
  };

  port = 10000;
  base_path = "/shopping/";
in
{
  environment.systemPackages = [
    shopping-list
  ];

  systemd.services.shopping-list = {
    description = "shopping-list";
    wantedBy = [ "multi-user.target" ];
    environment = {
      GIN_MODE = "release";
      PORT = "${toString port}";
      BASE_PATH = "${base_path}";
    };

    serviceConfig = {
      ExecStart = "${shopping-list}/bin/shopping-list";
      WorkingDirectory = "/var/lib/shopping-list/";
      Restart = "always";
      User = "shopping-list";
      EnvironmentFile = "/secret/shopping_list.env";
    };

  };

  # Create the system user for the service
  users.users.shopping-list = {
    isSystemUser = true;
    group = "shopping-list";
  };
  users.groups.shopping-list = {};

  services.nginx = {
    virtualHosts = {
      "krinitsin.com" = {
	locations.${base_path} = {
	  proxyPass = "http://localhost:${toString port}/";
	  recommendedProxySettings = true;
	};
      };
    };
  };
}