2023-05-11 06:03:33 -07:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.microbin;
|
|
|
|
configFile = "/etc/microbin/config";
|
|
|
|
dataFolder = "/var/lib/microbin";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.microbin = {
|
|
|
|
enable = mkEnableOption "A super tiny pasta";
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "microbin";
|
|
|
|
description = "User account under which microbin runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "microbin";
|
|
|
|
description = "Group account under which microbin runs.";
|
|
|
|
};
|
|
|
|
|
2023-05-12 03:51:28 -07:00
|
|
|
hostname = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Hostname of your microbin service";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8080;
|
|
|
|
description = "Port on which to run the serice";
|
|
|
|
};
|
|
|
|
|
2023-05-11 06:03:33 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.microbin = {
|
|
|
|
description = "Microbin A Super Tiny Pasta";
|
|
|
|
after = [ "remote-fs.target" "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
2023-05-12 04:23:45 -07:00
|
|
|
ExecStart = "${pkgs.microbin}/bin/microbin -- --port ${builtins.toString cfg.port} --public-path ${cfg.hostname} --editable --enable-burn-after --private --qr --title=sealight --highlightsyntax";
|
2023-05-11 06:03:33 -07:00
|
|
|
WorkingDirectory = dataFolder;
|
|
|
|
TimeoutStopSec = " 20 ";
|
|
|
|
KillMode = " process ";
|
|
|
|
RestartSec = " 10 ";
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
DevicePolicy = " closed ";
|
|
|
|
NoNewPrivileges = " yes ";
|
|
|
|
PrivateTmp = " yes ";
|
|
|
|
PrivateUsers = " yes ";
|
|
|
|
ProtectControlGroups = " yes ";
|
|
|
|
ProtectKernelModules = " yes ";
|
|
|
|
ProtectKernelTunables = " yes ";
|
|
|
|
RestrictAddressFamilies = "
|
|
|
|
AF_UNIX
|
|
|
|
AF_INET
|
|
|
|
AF_INET6 ";
|
|
|
|
RestrictNamespaces = " yes ";
|
|
|
|
RestrictRealtime = " yes ";
|
|
|
|
SystemCallFilter = "~@clock @debug @module @mount @obsolete @privileged @reboot @setuid @swap";
|
|
|
|
ReadWritePaths = dataFolder;
|
|
|
|
StateDirectory = baseNameOf dataFolder;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users = optionalAttrs (cfg.user == "microbin") ({
|
|
|
|
microbin = {
|
|
|
|
description = "microbin service user";
|
|
|
|
name = cfg.user;
|
|
|
|
group = cfg.group;
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
users.groups = optionalAttrs (cfg.group == "microbin") ({
|
|
|
|
microbin = { };
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|