boddle/flake.nix

101 lines
2.9 KiB
Nix

{
description = "boddle, in Anlehnung an bottle";
outputs = { self, nixpkgs }: let
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 = [ 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 = [ "${cfg.database}:%S/boddle/${cfg.nick}.db" ];
};
};
per-system = fn: builtins.mapAttrs (_: fn) nixpkgs.legacyPackages;
package = pkgs: pkgs.buildGoModule {
meta = {
description = "boddle, in Anlehnung an bottle";
homepage = "https://git.fbs42.ddnss.de/forgejo/fbs42/boddle";
name = "boddle";
mainProgram = "boddle";
};
pname = "boddle";
version = "v0.0.1";
vendorHash = "sha256-XH/u+lcVsLoWDoMPp5/rwWytTpM17mXmoLKJUnJ9BRI=";
src = pkgs.fetchgit {
url = "https://git.fbs42.ddnss.de/forgejo/fbs42/boddle";
hash = "sha256-6zK+oAGJz1UCo2eZZAlSH6VqMGba9g2hKnzG1kN0gYI=";
};
};
devshell = pkgs: pkgs.mkShell {
nativeBuildInputs = with pkgs.buildPackages; [
go
];
};
app = pkgs: {
type = "app";
program = nixpkgs.lib.getExe (package pkgs);
};
in {
nixosModules = {
default = self.nixosModules.boddle;
boddle = module;
};
overlay = final: prev: {
boddle = package final;
};
packages = per-system (pkgs: {
default = package pkgs;
boddle = package pkgs;
});
apps = per-system (pkgs: {
default = app pkgs;
boddle = app pkgs;
});
devShells = per-system (pkgs: {
default = devshell pkgs;
});
};
}