Skip to content

Commit acfc201

Browse files
committed
git-pages nixos module
Signed-off-by: phanirithvij <phanirithvij2000@gmail.com>
1 parent 1ef50ce commit acfc201

3 files changed

Lines changed: 146 additions & 0 deletions

File tree

‎makemake/configuration.nix‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{
77
imports = [
88
./buildbot.nix
9+
./git-pages.nix
910
./hardware.nix
1011
./sops.nix
1112
./zfs.nix

‎makemake/git-pages-service.nix‎

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# TODO remove once this is merged in nixpkgs and backported to nixos stable
2+
# Module by @dtomvan on github, MIT licensed, https://github.com/dtomvan/puntbestanden/blob/hoofdlijn/modules/services/git-pages.nix
3+
{
4+
config,
5+
lib,
6+
pkgs,
7+
options,
8+
...
9+
}:
10+
let
11+
cfg = config.git-pages;
12+
settingsFormat = pkgs.formats.toml { };
13+
configFile = "git-pages.toml";
14+
configOutPath = config.configData.${configFile}.path;
15+
in
16+
{
17+
_class = "service";
18+
19+
meta.maintainers = with lib.maintainers; [
20+
dtomvan
21+
phanirithvij
22+
];
23+
24+
options.git-pages = {
25+
package = lib.mkOption {
26+
description = "Package to use for git-pages";
27+
defaultText = "The git-pages package that provided this module.";
28+
type = lib.types.package;
29+
};
30+
31+
port = lib.mkOption {
32+
description = "Port to open the main pages server on";
33+
default = 3000;
34+
type = lib.types.port;
35+
};
36+
37+
caddyPort = lib.mkOption {
38+
description = "Port for caddy";
39+
default = 3001;
40+
type = lib.types.nullOr lib.types.port;
41+
};
42+
43+
metricsPort = lib.mkOption {
44+
description = "Port to open a prometheus exporter on";
45+
default = 3002;
46+
type = lib.types.nullOr lib.types.port;
47+
};
48+
49+
secretFile = lib.mkOption {
50+
description = "Path to secrets.toml";
51+
default = null;
52+
type = lib.types.nullOr lib.types.str;
53+
};
54+
55+
settings = lib.mkOption {
56+
type = settingsFormat.type;
57+
description = "Settings to set in git-pages.toml. See https://codeberg.org/git-pages/git-pages";
58+
default = settingsFormat.emptyValue;
59+
};
60+
};
61+
62+
config = {
63+
git-pages.settings.server = {
64+
pages = lib.mkOptionDefault "tcp/0.0.0.0:${toString cfg.port}";
65+
caddy = lib.mkOptionDefault (
66+
if cfg.caddyPort == null then "-" else "tcp/0.0.0.0:${toString cfg.caddyPort}"
67+
);
68+
metrics = lib.mkOptionDefault (
69+
if cfg.metricsPort == null then "-" else "tcp/0.0.0.0:${toString cfg.metricsPort}"
70+
);
71+
};
72+
73+
process.argv = [
74+
(lib.getExe cfg.package)
75+
"-config"
76+
configOutPath
77+
];
78+
79+
configData."${configFile}".source = settingsFormat.generate configFile cfg.settings;
80+
}
81+
// lib.optionalAttrs (options ? systemd) {
82+
systemd.mainExecStart = config.systemd.lib.escapeSystemdExecArgs config.process.argv;
83+
84+
systemd.service = {
85+
description = "Forge-agnostic static site server";
86+
documentation = [ "https://codeberg.org/git-pages/git-pages" ];
87+
88+
after = [ "network.target" ];
89+
wants = [ "network.target" ];
90+
wantedBy = [ "multi-user.target" ];
91+
restartTriggers = [ config.configData."${configFile}".source ];
92+
93+
serviceConfig = {
94+
ExecStartPre = "${lib.getExe' pkgs.coreutils "mkdir"} -p data";
95+
Restart = "always";
96+
97+
StateDirectory = "git-pages";
98+
WorkingDirectory = "/var/lib/git-pages";
99+
BindReadOnlyPaths = [ configOutPath ];
100+
101+
LoadCredential = lib.optional (cfg.secretFile != null) "secrets.toml:${cfg.secretFile}";
102+
103+
# systemd service hardening
104+
DynamicUser = true;
105+
ProtectHome = true;
106+
MemoryDenyWriteExecute = true;
107+
PrivateDevices = true;
108+
PrivateTmp = true;
109+
ProtectSystem = "strict";
110+
ProtectControlGroups = true;
111+
RestrictSUIDSGID = true;
112+
RestrictRealtime = true;
113+
LockPersonality = true;
114+
ProtectKernelLogs = true;
115+
ProtectKernelTunables = true;
116+
ProtectHostname = true;
117+
ProtectKernelModules = true;
118+
PrivateUsers = true;
119+
ProtectClock = true;
120+
SystemCallArchitectures = "native";
121+
SystemCallErrorNumber = "EPERM";
122+
SystemCallFilter = "@system-service";
123+
};
124+
};
125+
};
126+
}

‎makemake/git-pages.nix‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{ pkgs, ... }:
2+
3+
{
4+
system.services.git-pages = {
5+
_module.args.pkgs = pkgs;
6+
imports = [ ./git-pages-service.nix ];
7+
git-pages = {
8+
package = pkgs.git-pages;
9+
port = 4000;
10+
caddyPort = null;
11+
metricsPort = 4002;
12+
# NOTE: git-pages does need a password
13+
# it checks whether the hash computed from
14+
# the password set in the auth header in http requests
15+
# matches the hash in dns challenge txt record
16+
#secretsFile = sops template
17+
};
18+
};
19+
}

0 commit comments

Comments
 (0)