1 { config, lib, pkgs, ... }:
4 cfg = config.services.microbin;
7 options.services.microbin = {
8 enable = lib.mkEnableOption "MicroBin is a super tiny, feature rich, configurable paste bin web application";
10 package = lib.mkPackageOption pkgs "microbin" { };
12 settings = lib.mkOption {
13 type = lib.types.submodule { freeformType = with lib.types; attrsOf (oneOf [ bool int str ]); };
17 MICROBIN_HIDE_LOGO = false;
20 Additional configuration for MicroBin, see
21 <https://microbin.eu/docs/installation-and-configuration/configuration/>
24 For secrets use passwordFile option instead.
28 dataDir = lib.mkOption {
30 default = "/var/lib/microbin";
31 description = "Default data folder for MicroBin.";
34 passwordFile = lib.mkOption {
35 type = lib.types.nullOr lib.types.path;
37 example = "/run/secrets/microbin.env";
39 Path to file containing environment variables.
40 Useful for passing down secrets.
41 Variables that can be considered secrets are:
42 - MICROBIN_BASIC_AUTH_USERNAME
43 - MICROBIN_BASIC_AUTH_PASSWORD
44 - MICROBIN_ADMIN_USERNAME
45 - MICROBIN_ADMIN_PASSWORD
46 - MICROBIN_UPLOADER_PASSWORD
51 config = lib.mkIf cfg.enable {
52 services.microbin.settings = with lib; {
53 MICROBIN_BIND = mkDefault "0.0.0.0";
54 MICROBIN_DISABLE_TELEMETRY = mkDefault true;
55 MICROBIN_LIST_SERVER = mkDefault false;
56 MICROBIN_PORT = mkDefault "8080";
59 systemd.services.microbin = {
60 after = [ "network.target" ];
61 wantedBy = [ "multi-user.target" ];
62 environment = lib.mapAttrs (_: v: if lib.isBool v then lib.boolToString v else toString v) cfg.settings;
64 CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
65 DevicePolicy = "closed";
67 EnvironmentFile = lib.optional (cfg.passwordFile != null) cfg.passwordFile;
68 ExecStart = "${cfg.package}/bin/microbin";
69 LockPersonality = true;
70 MemoryDenyWriteExecute = true;
71 PrivateDevices = true;
74 ProtectControlGroups = true;
75 ProtectHostname = true;
76 ProtectKernelLogs = true;
77 ProtectKernelModules = true;
78 ProtectKernelTunables = true;
79 ProtectProc = "invisible";
80 ReadWritePaths = cfg.dataDir;
81 RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
82 RestrictNamespaces = true;
83 RestrictRealtime = true;
84 StateDirectory = "microbin";
85 SystemCallArchitectures = [ "native" ];
86 SystemCallFilter = [ "@system-service" ];
87 WorkingDirectory = cfg.dataDir;
92 meta.maintainers = with lib.maintainers; [ surfaceflinger ];