2023-05-13 05:49:47 -07:00
|
|
|
{ self, config, lib, pkgs, ... }:
|
2023-05-11 06:03:33 -07:00
|
|
|
|
|
|
|
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-15 07:18:50 -07:00
|
|
|
ExecStart = "${pkgs.unstable.microbin}/bin/microbin --public-path https://${cfg.hostname}/ --qr --enable-burn-after --private";
|
2023-05-13 05:49:47 -07:00
|
|
|
Environment = [
|
|
|
|
"MICROBIN_EDITABLE=true"
|
|
|
|
"MICROBIN_HIDE_FOOTER=true"
|
|
|
|
"MICROBIN_HIGHLIGHTSYNTAX=true"
|
|
|
|
"MICROBIN_PORT=${builtins.toString cfg.port}"
|
|
|
|
"MICROBIN_TITLE=SealightBin"
|
|
|
|
];
|
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 = { };
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|