Create NixOS module

This commit is contained in:
2025-01-17 17:21:01 +01:00
parent 3528e65312
commit 65e2c22cba
2 changed files with 108 additions and 1 deletions

View File

@@ -18,5 +18,11 @@
obsidian-tasks-reminder = pkgs.callPackage ./package.nix {};
default = obsidian-tasks-reminder;
};
});
})
// {
nixosModules = rec {
obsidian-tasks-reminder = import ./module.nix self;
default = obsidian-tasks-reminder;
};
};
}

101
module.nix Normal file
View File

@@ -0,0 +1,101 @@
self: {
config,
pkgs,
lib,
system,
...
}: let
cfg = config.services.obsidian-tasks-reminder;
appConfig = (pkgs.formats.yaml {}).generate "obsidian-tasks-reminder.config.yaml" cfg.config;
app = pkgs.writeShellApplication {
name = "obsidian-tasks-reminder";
runtimeInputs = [self.packages.${system}.default];
text = ''
oh-import -c "${appConfig}" "$@";
'';
};
in
with lib; {
options.services.obsidian-tasks-reminder = {
enable = mkEnableOption "obsidian-tasks-reminder";
user = mkOption {
type = types.str;
description = "User which will be used to run the app";
example = "root";
default = "root";
};
scanTimer = mkOption {
type = types.str;
description = "The systemd's timer interval when the app will be performing the scan for new tasks";
example = "*-*-* *:00";
default = "*-*-* *:10";
};
config = mkOption {
type = types.attrs;
description = "The obsidian-tasks-reminder config which will be eventually converted to yaml";
example = {
sources = ["/var/lib/obsidian-data"];
query = "$.priority > MEDIUM && $.status !== 'x'";
mapper = "{ text: $.label, title: 'Task reminder' }";
databaseFile = "/tmp/obsidian-tasks-reminder.json";
backend.ntfy = {
enable = true;
url = "ntfy.sh";
token = "$__file:/etc/tokens/ntfy-sh.key";
topic = "obsidian";
};
};
};
};
config = mkIf cfg.enable {
environment.systemPackages = [app];
systemd.timers.obsidian-tasks-reminder-scanner = {
description = "Scan for new Obsidian tasks";
wantedBy = ["timers.target"];
timerConfig = {
OnCalendar = cfg.scanTimer;
Unit = "obsidian-tasks-reminder-scanner.service";
};
};
systemd.timers.obsidian-tasks-reminder = {
description = "Notify about Obsidian tasks";
wantedBy = ["timers.target"];
timerConfig = {
OnCalendar = "*-*-* *:*:00";
Unit = "obsidian-tasks-reminder.service";
};
};
systemd.services.obsidian-tasks-reminder-scanner = {
description = "Scan for new Obsidian tasks";
serviceConfig = {
Type = "oneshot";
User = cfg.user;
};
script = "${app}/bin/obsidian-tasks-reminder -s";
};
systemd.services.obsidian-tasks-reminder = {
description = "Notify about Obsidian tasks";
serviceConfig = {
Type = "oneshot";
User = cfg.user;
};
script = "${app}/bin/obsidian-tasks-reminder -n";
};
};
}