-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
85 lines (80 loc) · 2.8 KB
/
flake.nix
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
{
description = "Flake for Archie, a slack bot for stl-tech";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
devenv.url = "github:cachix/devenv";
};
outputs = { self, nixpkgs, devenv, ... }@inputs:
let system = "x86_64-linux";
in {
packages.${system}.default =
let pkgs = import nixpkgs { inherit system; };
in pkgs.callPackage ./. { inherit pkgs; };
devShells.${system} = let pkgs = import nixpkgs { inherit system; };
in {
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [{
# https://devenv.sh/reference/options/
packages = [ pkgs.heroku pkgs.yarn ];
languages.javascript.enable = true;
}];
};
};
nixosModules = {
default = { config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.archie;
description = "archie, a Slack bot for stl-tech";
in {
options.services.archie = {
enable = mkEnableOption description;
acme-email = mkOption {
type = types.str;
description = "Which email to use for Let's Encrypt";
};
domain = mkOption {
type = types.str;
description = "What domain to serve archie from";
};
envFile = mkOption {
type = types.path;
description = "The path for the dotenv file, to load secrets in";
default = /root/archie.env;
};
port = mkOption {
type = types.int;
description = "Which port to serve from. Make sure this matches up with envFile you deploy!";
default = 3000;
};
};
config = mkIf cfg.enable {
networking.firewall.allowedTCPPorts = [ 80 443 ];
security.acme.acceptTerms = true;
security.acme.defaults.email = cfg.acme-email;
services.nginx = {
enable = true;
virtualHosts.${cfg.domain} = {
enableACME = true;
forceSSL = true;
locations."/" = {
proxyPass = "http://localhost:${toString cfg.port}";
};
};
};
systemd.services.archie = {
inherit description;
script = ''
${self.outputs.packages.${system}.default}/bin/archie
'';
serviceConfig = {
EnvironmentFile = cfg.envFile;
};
wantedBy = [ "multi-user.target"];
};
};
};
};
};
}