From 0869ab985da020738b7ce986033d653137f78bbe Mon Sep 17 00:00:00 2001 From: Jonas Rabenstein Date: Sat, 25 Jan 2025 00:37:37 +0100 Subject: [PATCH] flake: update systemd options --- flake.nix | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/flake.nix b/flake.nix index 04afba0..9579519 100644 --- a/flake.nix +++ b/flake.nix @@ -2,27 +2,46 @@ description = "boddle, in Anlehnung an bottle"; outputs = { self, nixpkgs }: let - module = { pkgs, lib, config, ... }: { + module = { pkgs, lib, config, ... }: let + cfg = config.services.boddle; + in { options.services.boddle = { enable = lib.mkEnableOption "enable"; # TODO: configurability + server = lib.mkOption { + type = lib.types.strMatching ".+:[1-9][0-9]*"; + default = "irc.ircnet.com:6667"; + }; + nick = lib.mkOption { + type = lib.types.strMatching "[^ ]+"; + default = "boddle"; + }; + database = lib.mkOption { + type = lib.types.strMatching "/.+"; + default = "/var/lib/boddle/${cfg.nick}.db"; + }; + channels = lib.mkOption { + type = lib.types.coercedTo lib.types.nonEmptyStr (lib.strings.splitString " ") (lib.types.nonEmptyListOf (lib.types.strMatching "[^ ]+")); + }; }; config.nixpkgs.overlays = [ self.overlay ]; config.systemd.services.boddle = lib.mkIf config.services.boddle.enable { confinement.enable = true; - unitConfig.ConditionPathExists = [ - "%S/boddle/boddle.toml" - "%S/boddle/boddle.db" - ]; - serviceConfig.ExecStart = lib.getExe pkgs.boddle; + unitConfig.ConditionPathExists = [ cfg.database ]; + serviceConfig.ExecStart = let + args = lib.lists.foldl (acc: channel: acc ++ [ "--channel" channel ]) [ + (lib.getExe pkgs.boddle) + "--server" cfg.server + "--nick" cfg.nick + "--database" "./${cfg.nick}.db" + ] cfg.channels; + in lib.strings.escapeShellArgs args; serviceConfig.WorkingDirectory = "%S/boddle"; serviceConfig.StateDirectory = "boddle"; serviceConfig.DynamicUser = true; - serviceConfig.BindPaths = [ - "%S/boddle" - ]; + serviceConfig.BindPaths = [ "${cfg.database}:%S/boddle/${cfg.nick}.db" ]; }; }; @@ -37,10 +56,10 @@ }; pname = "boddle"; version = "v0.0.1"; - vendorHash = "sha256-dlQ1+skfEiPVm+IWxfwPsW8jkifo4ufZlfESbf36fFY="; + vendorHash = "sha256-XH/u+lcVsLoWDoMPp5/rwWytTpM17mXmoLKJUnJ9BRI="; src = pkgs.fetchgit { url = "https://git.fbs42.ddnss.de/forgejo/fbs42/boddle"; - hash = "sha256-Y9WYhqcoJFTY+DuHj9YIuMryapwb/T+ZGZyCAh0kfY8="; + hash = "sha256-6zK+oAGJz1UCo2eZZAlSH6VqMGba9g2hKnzG1kN0gYI="; }; };