-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflake.nix
More file actions
203 lines (201 loc) · 6.56 KB
/
flake.nix
File metadata and controls
203 lines (201 loc) · 6.56 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
devshell = {
url = "github:numtide/devshell";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
};
outputs = {
self,
nixpkgs,
flake-utils,
devshell,
...
} @ inputs:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
# config = import ./go.nix;
overlays = [ devshell.overlays.default ];
};
in rec {
defaultPackage = pkgs.buildGoModule {
name = "website";
pname = "server";
src = ./.;
vendorHash = "sha256-r6oleJa2iw7Bp8EDqONw/tcawrny7DIT09zf/awrszk=";
ldFlages = [
"-S" "-W"
];
subPackages = [];
};
devShells = rec {
default = website;
website = pkgs.devshell.mkShell {
name = "website";
packages = with pkgs; [
go_1_24
nix
git
gotools
go-tools
gotestsum
gofumpt
golangci-lint
nfpm
goreleaser
nodejs
deno
];
commands = [
{
name = "website:build:bin";
command = ''
make clean
make build
'';
}
{
name = "website:build:nix";
command = ''
nix build
'';
}
{
name = "website:package";
command = ''
make package
'';
}
];
};
};
nixosModules.website = { config, lib, pkgs, ...}:
with lib;
let
cfg = config.services.fbegyn.website;
in {
options.services.fbegyn.website = {
enable = mkEnableOption "enables fbegyn's personal website server";
domain = mkOption {
type = types.str;
default = "francis.begyn.be";
example = "francis.begyn.be";
description = "The domain NGINX should use.";
};
useACMEHost = mkOption {
type = types.str;
default = "francis.begyn.be";
example = "francis.begyn.be";
description = "The ACME host that should be used by NGINX";
};
home = mkOption {
type = types.str;
default = "/srv/fbegyn/website";
example = "/var/lib/website";
description = "Working directory of the website";
};
aliases = mkOption {
type = types.listOf types.str;
default = [];
example = [ "francis.begyn.eu" ];
description = "The aliases NGINX should use.";
};
port = mkOption {
type = types.int;
default = 3114;
example = 3114;
description = "The port number for the website server";
};
multiplex = {
enable = mkEnableOption "enables the multiplex server on this host under multiplex-server.service";
location = mkOption {
type = types.str;
default = "/socket.io";
example = "/multiplex/socket";
description = "nginx location to run the multiplex server on";
};
proxyPass = mkOption {
type = types.str;
default = "http://127.0.0.1:${toString cfg.multiplex.port}/";
example = "http://127.0.0.1:3000/";
description = "nginx location to run the multiplex server on";
};
command = mkOption {
type = types.str;
description = "command to execute under de multiplex server systemd unit";
};
port = mkOption {
type = types.int;
default = 8000;
example = 8000;
description = "The port number for the multiplex server";
};
home = mkOption {
type = types.str;
default = "/srv/fbegyn/multiplex-server";
example = "/var/lib/website";
description = "Working directory of the website";
};
};
};
config = mkIf cfg.enable {
users.users.fbegyn = {
createHome = true;
isSystemUser = true;
group = "fbegyn";
home = "${cfg.home}";
description = "francis.begyn.be";
};
users.groups.fbegyn.members = [ "francis" ];
systemd.services.website = {
serviceConfig = {
Environment = "SERVER_PORT=${toString cfg.port}";
EnvironmentFile = "${cfg.home}/.env";
User = "fbegyn";
Group = "fbegyn";
WorkingDirectory = "${cfg.home}";
ExecStart = "${defaultPackage}/bin/server serve";
};
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
};
systemd.services.multiplex-server = mkIf cfg.multiplex.enable {
serviceConfig = {
EnvironmentFile = "${cfg.multiplex.home}/.env";
User = "fbegyn";
Group = "fbegyn";
WorkingDirectory = "${cfg.multiplex.home}";
ExecStart = "${cfg.multiplex.command}";
};
after = [ "network.target" ];
};
# francis.begyn.be website/blog
services.nginx.virtualHosts.francis = {
forceSSL = true;
serverName = "${cfg.domain}";
serverAliases = cfg.aliases;
useACMEHost = "${cfg.useACMEHost}";
root = "/var/www/${cfg.domain}";
locations."/" = {
proxyPass = "http://127.0.0.1:${toString cfg.port}";
extraConfig = ''
add_header Permissions-Policy interest-cohort=();
'';
};
locations."${cfg.multiplex.location}" = mkIf cfg.multiplex.enable {
proxyPass = "${cfg.multiplex.proxyPass}";
proxyWebsockets = true;
extraConfig = ''
add_header Permissions-Policy interest-cohort=();
'';
};
};
};
};
});
}