blob: f5a91222b9f98ee126452ecfdae25ef96aaead40 (
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
|
{ config, pkgs, ... }:
let
envsubstConfiguration = {
TLD = "$TLD";
nextcloudTLD = "$NEXTCLOUD_TLD";
gitTLD = "$GIT_TLD";
bonecoTLD = "$BONECO_TLD";
letsencryptEmail = "$LETSENCRYPT_EMAIL";
authorizedKey = "$AUTHORIZED_KEY";
userPassword = "$USER_PASSWORD";
userName = "$USER_NAME";
nextcloudDatabaseUser = "$NEXTCLOUD_DATABASE_USER";
nextcloudDatabasePassword = "$NEXTCLOUD_DATABASE_PASSWORD";
nextcloudAdminUser = "$NEXTCLOUD_ADMIN_USER";
nextcloudAdminPassword = "$NEXTCLOUD_ADMIN_PASSWORD";
nextcloudTablePrefix = "$NEXTCLOUD_TABLE_PREFIX";
gitRoot = "$GIT_ROOT";
gitPort = "$GIT_PORT";
systemStateVersion = "$SYSTEM_STATE_VERSION";
};
boneco = pkgs.stdenv.mkDerivation {
name = "boneco";
src =
fetchTarball "https://git.sr.ht/~euandreh/boneco/archive/master.tar.gz";
phases = "unpackPhase buildPhase";
buildPhase = ''
mkdir ${DOLLAR}out
cp index.html ${DOLLAR}out
cp favicon.ico ${DOLLAR}out
'';
};
in {
imports = [ ./hardware-configuration.nix ];
boot.loader.grub = {
enable = true;
version = 2;
device = "/dev/vda";
};
networking = {
useDHCP = false;
interfaces.ens3.useDHCP = true;
};
environment.systemPackages = with pkgs; [ vim git ];
networking.firewall.allowedTCPPorts = [
# SSH: OpenSSH
22
# HTTP and HTPPS: NGINX
80
443
];
security.acme = {
acceptTerms = true;
email = envsubstConfiguration.letsencryptEmail;
};
services = {
openssh = {
enable = true;
permitRootLogin = "no";
passwordAuthentication = false;
};
nginx = {
enable = true;
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
virtualHosts = {
"${envsubstConfiguration.nextcloudTLD}" = {
forceSSL = true;
enableACME = true;
};
"${envsubstConfiguration.gitTLD}" = {
forceSSL = true;
enableACME = true;
locations."/" = {
proxyPass = "http://localhost:${envsubstConfiguration.gitPort}";
};
};
"${envsubstConfiguration.bonecoTLD}" = {
forceSSL = true;
enableACME = true;
root = boneco;
};
};
};
postgresql = {
enable = true;
ensureDatabases = [ "nextcloud" ];
package = pkgs.postgresql_11;
ensureUsers = [{
name = "nextcloud";
ensurePermissions."DATABASE nextcloud" = "ALL PRIVILEGES";
}];
};
nextcloud = {
enable = true;
package = pkgs.nextcloud19;
nginx.enable = true;
hostName = envsubstConfiguration.nextcloudTLD;
https = true;
maxUploadSize = "4G";
autoUpdateApps.enable = true;
config = {
overwriteProtocol = "https";
dbtype = "pgsql";
dbhost = "/run/postgresql";
dbuser = envsubstConfiguration.nextcloudDatabaseUser;
dbpass = envsubstConfiguration.nextcloudDatabasePassword;
dbtableprefix = envsubstConfiguration.nextcloudTablePrefix;
adminuser = envsubstConfiguration.nextcloudAdminUser;
adminpass = envsubstConfiguration.nextcloudAdminPassword;
};
};
lighttpd = {
enable = true;
port = pkgs.lib.toInt envsubstConfiguration.gitPort;
cgit = {
enable = true;
subdir = "";
configText = ''
source-filter=${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py
about-filter=${pkgs.cgit}/lib/cgit/filters/about-formatting.sh
scan-path=${envsubstConfiguration.gitRoot}
'';
};
};
};
systemd.services = {
"nextcloud-setup" = {
requires = [ "postgresql.service" ];
after = [ "postgresql.service" ];
};
"lighttpd-cgit-install" = {
enable = true;
description = "Setup folders and permissions for lighttpd and cgit";
wantedBy = [ "multi-user.target" ];
script = ''
mkdir -p ${envsubstConfiguration.gitRoot}
chown -R ${envsubstConfiguration.userName}:lighttpd ${envsubstConfiguration.gitRoot}
chmod -R 770 ${envsubstConfiguration.gitRoot}
'';
serviceConfig = { Type = "oneshot"; };
};
};
users.extraUsers."${envsubstConfiguration.userName}" = {
uid = 1000;
isNormalUser = true;
extraGroups = [ "wheel" ];
password = envsubstConfiguration.userPassword;
openssh.authorizedKeys.keys = [ envsubstConfiguration.authorizedKey ];
};
system.stateVersion = envsubstConfiguration.systemStateVersion;
}
|