Integrate previously external templates into this repository #12

Manually merged
tlater merged 8 commits from tlater/integrated-templates into master 2022-10-05 12:39:33 +01:00
2 changed files with 80 additions and 0 deletions
Showing only changes of commit b76e61a55a - Show all commits

View file

@ -37,6 +37,8 @@
'');
};
nixosModules.default = import ./nix/module.nix {inherit self system;};
devShells.${system} = {
templates = flakeOutputs.templates.devShells.${system}.default.overrideAttrs (old: {
buildInputs = with nixpkgs.legacyPackages.${system};

78
nix/module.nix Normal file
View file

@ -0,0 +1,78 @@
{
self,
system,
}: {
config,
lib,
...
}: let
inherit (lib) mkEnableOption mkIf mkOption;
inherit (lib.types) submodule str int;
inherit (lib.strings) escapeShellArgs;
inherit (self.packages.${system}) server templates;
cfg = config.services.tlaternet-webserver;
in {
options = {
services.tlaternet-webserver = {
enable = mkEnableOption "tlaternet web server";
listen = mkOption {
type = submodule {
options = {
addr = mkOption {
type = str;
description = "IP address.";
default = "127.0.0.1";
};
port = mkOption {
type = int;
description = "Port number.";
default = 8000;
};
};
};
};
};
};
config = mkIf cfg.enable {
systemd.services.tlaternet-webserver = {
description = "tlaternet webserver";
wantedBy = ["multi-user.target"];
after = ["network.target"];
script = escapeShellArgs [
"${server}/bin/tlaternet-webserver"
"--template-directory"
templates
"--address"
"${cfg.listen.addr}:${toString cfg.listen.port}"
];
serviceConfig = {
Restart = "always";
DynamicUser = true;
ProtectHome = true; # Override the default (read-only)
PrivateDevices = true;
PrivateIPC = true;
PrivateUsers = true;
ProtectHostname = true;
ProtectClock = true;
ProtectKernelTunables = true;
ProtectKernelModules = true;
ProtectKernelLogs = true;
ProtectControlGroups = true;
RestrictAddressFamilies = ["AF_UNIX" "AF_INET" "AF_INET6"];
RestrictNamespaces = true;
LockPersonality = true;
MemoryDenyWriteExecute = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
SystemCallFilter = ["@system-service" "~@privileged @resources @setuid @keyring"];
};
};
};
}