7 cfg = config.services.silverbullet;
8 defaultUser = "silverbullet";
9 defaultGroup = defaultUser;
10 defaultSpaceDir = "/var/lib/silverbullet";
14 services.silverbullet = {
15 enable = lib.mkEnableOption "Silverbullet, an open-source, self-hosted, offline-capable Personal Knowledge Management (PKM) web application";
17 package = lib.mkPackageOption pkgs "silverbullet" { };
19 openFirewall = lib.mkOption {
20 type = lib.types.bool;
22 description = "Open port in the firewall.";
25 listenPort = lib.mkOption {
28 description = "Port to listen on.";
31 listenAddress = lib.mkOption {
33 default = "127.0.0.1";
34 description = "Address or hostname to listen on. Defaults to 127.0.0.1.";
37 spaceDir = lib.mkOption {
38 type = lib.types.path;
39 default = defaultSpaceDir;
40 example = "/home/yourUser/silverbullet";
42 Folder to store Silverbullet's space/workspace.
43 By default it is located at `${defaultSpaceDir}`.
49 default = defaultUser;
52 The user to run Silverbullet as.
53 By default, a user named `${defaultUser}` will be created whose space
54 directory is [spaceDir](#opt-services.silverbullet.spaceDir).
58 group = lib.mkOption {
60 default = defaultGroup;
61 example = "yourGroup";
63 The group to run Silverbullet under.
64 By default, a group named `${defaultGroup}` will be created.
68 envFile = lib.mkOption {
69 type = lib.types.nullOr lib.types.path;
71 example = "/etc/silverbullet.env";
73 File containing extra environment variables. For example:
77 SB_AUTH_TOKEN=abcdefg12345
82 extraArgs = lib.mkOption {
83 type = lib.types.listOf lib.types.str;
85 example = [ "--db /path/to/silverbullet.db" ];
86 description = "Extra arguments passed to silverbullet.";
91 config = lib.mkIf cfg.enable {
92 systemd.services.silverbullet = {
93 description = "Silverbullet service";
94 after = [ "network.target" ];
95 wantedBy = [ "multi-user.target" ];
97 preStart = lib.mkIf (!lib.hasPrefix "/var/lib/" cfg.spaceDir) "mkdir -p '${cfg.spaceDir}'";
100 User = "${cfg.user}";
101 Group = "${cfg.group}";
102 EnvironmentFile = lib.mkIf (cfg.envFile != null) "${cfg.envFile}";
103 StateDirectory = lib.mkIf (lib.hasPrefix "/var/lib/" cfg.spaceDir) (lib.last (lib.splitString "/" cfg.spaceDir));
104 ExecStart = "${lib.getExe cfg.package} --port ${toString cfg.listenPort} --hostname '${cfg.listenAddress}' '${cfg.spaceDir}' " + lib.concatStringsSep " " cfg.extraArgs;
105 Restart = "on-failure";
109 networking.firewall = lib.mkIf cfg.openFirewall {
110 allowedTCPPorts = [ cfg.listenPort ];
113 users.users.${defaultUser} = lib.mkIf (cfg.user == defaultUser) {
116 description = "Silverbullet daemon user";
119 users.groups.${defaultGroup} = lib.mkIf (cfg.group == defaultGroup) { };
122 meta.maintainers = with lib.maintainers; [ aorith ];