feat: monolith

This commit is contained in:
2026-03-28 15:07:00 +01:00
parent 5e6abe53f2
commit cf289c8c48
6 changed files with 332 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
{
# https://github.com/NixOS/nixpkgs/issues/126590#issuecomment-3194531220
flake.nixosModules.plasma-fix = {
pkgs,
lib,
...
}: {
nixpkgs.overlays = lib.singleton (final: prev: {
kdePackages =
prev.kdePackages
// {
plasma-workspace = let
# the package we want to override
basePkg = prev.kdePackages.plasma-workspace;
# a helper package that merges all the XDG_DATA_DIRS into a single directory
xdgdataPkg = pkgs.stdenv.mkDerivation {
name = "${basePkg.name}-xdgdata";
buildInputs = [basePkg];
dontUnpack = true;
dontFixup = true;
dontWrapQtApps = true;
installPhase = ''
mkdir -p $out/share
( IFS=:
for DIR in $XDG_DATA_DIRS; do
if [[ -d "$DIR" ]]; then
cp -r $DIR/. $out/share/
chmod -R u+w $out/share
fi
done
)
'';
};
# undo the XDG_DATA_DIRS injection that is usually done in the qt wrapper
# script and instead inject the path of the above helper package
derivedPkg = basePkg.overrideAttrs {
preFixup = ''
for index in "''${!qtWrapperArgs[@]}"; do
if [[ ''${qtWrapperArgs[$((index+0))]} == "--prefix" ]] && [[ ''${qtWrapperArgs[$((index+1))]} == "XDG_DATA_DIRS" ]]; then
unset -v "qtWrapperArgs[$((index+0))]"
unset -v "qtWrapperArgs[$((index+1))]"
unset -v "qtWrapperArgs[$((index+2))]"
unset -v "qtWrapperArgs[$((index+3))]"
fi
done
qtWrapperArgs=("''${qtWrapperArgs[@]}")
qtWrapperArgs+=(--prefix XDG_DATA_DIRS : "${xdgdataPkg}/share")
qtWrapperArgs+=(--prefix XDG_DATA_DIRS : "$out/share")
'';
};
in
derivedPkg;
};
});
};
}

155
modules/programs/gotify.nix Normal file
View File

@@ -0,0 +1,155 @@
{
flake.homeModules.gotify = {
config,
lib,
pkgs,
...
}: let
cfg = config.hive.gotify;
cli-config = {
token = config.sops.placeholder.${cfg.cli.tokenSopsKey};
inherit (cfg.cli) url defaultPriority;
};
daemon-config = {
gotify =
{
inherit (cfg.daemon) url;
token = config.sops.placeholder.${cfg.daemon.tokenSopsKey};
auto_delete = cfg.daemon.autoDelete;
min_priority = cfg.daemon.minPriority;
}
// lib.optionalAttrs (cfg.daemon.onMsgCommand != null) {
on_msg_command = cfg.daemon.onMsgCommand;
};
};
valueToString = val:
if (builtins.typeOf val == "string")
then "\"${val}\""
else
(
if (builtins.typeOf val == "int")
then "${toString val}"
else
(
if (builtins.typeOf val == "bool")
then
(
if val
then "true"
else "false"
)
else (abort "Expected string int or bool, got ${builtins.typeOf val} with value ${toString val}")
)
);
toTOML = attrs:
lib.concatStrings (
lib.attrValues (
lib.mapAttrs (
name: config: ''
[${name}]
${lib.concatStringsSep "\n" (lib.attrValues (lib.mapAttrs (k: v: "${k} = ${valueToString v}") config))}
''
)
attrs
)
);
in {
options.hive.gotify = {
cli = {
enable = lib.mkEnableOption "Enable Gotify cli tool";
url = lib.mkOption {
type = lib.types.singleLineStr;
default = "https://${cfg.host}:${toString cfg.port}";
example = "http://gotify.example.com";
description = "The http url of the gotify server (for the cli tool)";
};
tokenSopsKey = lib.mkOption {
type = lib.types.singleLineStr;
description = "The sops key of the token secret";
};
defaultPriority = lib.mkOption {
type = lib.types.int;
default = 0;
example = 3;
description = "The default priority of the dispatched messages";
};
};
daemon = {
enable = lib.mkEnableOption "Enable the Gotify desktop notification daemon";
url = lib.mkOption {
type = lib.types.singleLineStr;
default = "wss://${cfg.host}:${toString cfg.port}";
example = "ws://gotify.example.com";
description = "The websocket url of the gotify server (for the desktop tool)";
};
tokenSopsKey = lib.mkOption {
type = lib.types.singleLineStr;
description = "The sops key of the token secret";
};
autoDelete = lib.mkOption {
type = lib.types.bool;
default = false;
example = true;
description = "Delete messages that have been handled";
};
minPriority = lib.mkOption {
type = lib.types.int;
default = 0;
example = 1;
description = "Ignore messages with priority lower than given value";
};
onMsgCommand = lib.mkOption {
type = lib.types.nullOr lib.types.singleLineStr;
default = null;
example = "/usr/bin/beep";
description = '' A command to tun for each message with env vars
GOTIFY_MSG_PRIORITY, GOTIFY_MSG_TITLE and GOTIFY_MSG_TEXTs
If unset use the standard desktop notification passing
'';
};
};
host = lib.mkOption {
type = lib.types.singleLineStr;
example = "example.com";
description = "The hostname of the gotify server";
};
port = lib.mkOption {
type = lib.types.int;
default = 443;
example = 443;
description = "The port of the gotify server";
};
};
config = let
cli = lib.mkIf cfg.cli.enable {
home.packages = [pkgs.gotify-cli];
sops.templates."gotify-cli-json" = {
content = lib.generators.toJSON {} cli-config;
path = "${config.xdg.configHome}/gotify/cli.json";
};
};
daemon = lib.mkIf cfg.daemon.enable {
systemd.user.services.gotify-desktop = {
Unit = {
Description = "Gotify Desktop notification service";
After = ["sops-nix.service"]; # After the secrets have been rendered
};
Service = {
ExecStart = "${pkgs.gotify-desktop}/bin/gotify-desktop";
};
Install = {
WantedBy = ["multi-user.target"];
};
};
sops.templates."gotify-daemon-toml" = {
content = toTOML daemon-config;
path = "${config.xdg.configHome}/gotify-desktop/config.toml";
};
};
in
lib.mkMerge [cli daemon];
};
}