home/modules: move newsboat automation to module

This commit is contained in:
Oystein Kristoffer Tveit 2025-03-24 15:38:58 +01:00
parent 3269834e3f
commit e298262966
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
6 changed files with 122 additions and 72 deletions
flake.nix
home
home.nix
modules/programs/newsboat
programs/newsboat

@ -148,6 +148,7 @@
neovim-auto-clean-swapfiles = ./home/modules/programs/neovim/auto-clean-swapfiles.nix;
nix-index-auto-update-database = ./home/modules/programs/nix-index/auto-update-database.nix;
direnv-auto-prune = ./home/modules/programs/direnv/auto-prune.nix;
newsboat = ./home/modules/programs/newsboat;
};
homeConfigurations = {

@ -53,6 +53,7 @@ in {
./modules/programs/neovim/auto-clean-swapfiles.nix
./modules/programs/nix-index/auto-update-database.nix
./modules/programs/direnv/auto-prune.nix
./modules/programs/newsboat
] ++ (optionals graphics [
./config/gtk.nix

@ -0,0 +1,6 @@
{
imports = [
./vacuum.nix
./fetch-articles.nix
];
}

@ -0,0 +1,53 @@
{ config, pkgs, lib, ... }:
let
cfg = config.programs.newsboat;
package = pkgs.newsboat;
in
{
options.programs.newsboat.fetch-articles = {
enable = lib.mkEnableOption "automatic article fetcher for newsboat";
onCalendar = lib.mkOption {
type = lib.types.str;
default = "daily";
example = "weekly";
# TODO: link to systemd manpage for format.
description = "How often to fetch new articles.";
};
};
config = lib.mkIf cfg.fetch-articles.enable {
# TODO: wait for internet
systemd.user.services.newsboat-fetch-articles = {
Unit = {
Description = "Automatically fetch new articles for newsboat";
Documentation = [ "man:newsboat(1)" ];
};
Service = {
Type = "oneshot";
CPUSchedulingPolicy = "idle";
IOSchedulingClass = "idle";
ExecStart = "${lib.getExe pkgs.flock} %t/newsboat.lock ${lib.getExe package} --execute=reload";
};
};
systemd.user.timers.newsboat-fetch-articles = {
Unit = {
Description = "Automatically fetch new articles for newsboat";
Documentation = [ "man:newsboat(1)" ];
After = [ "network.target" ];
};
Timer = {
Unit = "newsboat-fetch-articles.service";
OnCalendar = cfg.fetch-articles.onCalendar;
Persistent = true;
};
Install = {
WantedBy = [ "timers.target" ];
};
};
};
}

@ -0,0 +1,51 @@
{ config, pkgs, lib, ... }:
let
cfg = config.programs.newsboat;
package = pkgs.newsboat;
in
{
options.programs.newsboat.vacuum = {
enable = lib.mkEnableOption "automatic cleaning of the newsboat cache";
onCalendar = lib.mkOption {
type = lib.types.str;
default = "weekly";
example = "monthly";
# TODO: link to systemd manpage for format.
description = "How often to run the cleaning.";
};
};
config = lib.mkIf cfg.vacuum.enable {
systemd.user.services.newsboat-vacuum = {
Unit = {
Description = "Automatically clean newsboat cache";
Documentation = [ "man:newsboat(1)" ];
};
Service = {
Type = "oneshot";
CPUSchedulingPolicy = "idle";
IOSchedulingClass = "idle";
ExecStart = "${lib.getExe pkgs.flock} %t/newsboat.lock ${lib.getExe package} --vacuum";
};
};
systemd.user.timers.newsboat-vacuum = {
Unit = {
Description = "Automatically clean newsboat cache";
Documentation = [ "man:newsboat(1)" ];
};
Timer = {
Unit = "newsboat-vacuum.service";
OnCalendar = cfg.vacuum.onCalendar;
Persistent = true;
};
Install = {
WantedBy = [ "timers.target" ];
};
};
};
}

@ -12,6 +12,10 @@ in {
programs.newsboat = {
enable = true;
fetch-articles.enable = true;
vacuum.enable = true;
autoReload = true;
maxItems = 50;
browser = ''"${defaultBrowser}"'';
@ -71,76 +75,10 @@ in {
];
};
systemd.user.slices.app-newsboat = {
Unit = {
Description = "Newsboat automation";
Documentation = [ "man:newsboat(1)" ];
};
};
# TODO: wait for internet
systemd.user.services.newsboat-fetch-articles = {
Unit = {
Description = "Automatically fetch new articles for newsboat";
Documentation = [ "man:newsboat(1)" ];
};
Service = {
Type = "oneshot";
Slice = "app-newsboat.slice";
CPUSchedulingPolicy = "idle";
IOSchedulingClass = "idle";
ExecStart = "${lib.getExe pkgs.flock} %t/newsboat.lock ${lib.getExe package} --execute=reload";
};
};
systemd.user.timers.newsboat-fetch-articles = {
Unit = {
Description = "Automatically fetch new articles for newsboat";
Documentation = [ "man:newsboat(1)" ];
After = [ "network.target" ];
};
Timer = {
Unit = "newsboat-fetch-articles.service";
OnCalendar = lib.mkDefault "daily";
Persistent = true;
};
Install = {
WantedBy = [ "timers.target" ];
};
};
systemd.user.services.newsboat-vacuum = {
Unit = {
Description = "Automatically clean newsboat cache";
Documentation = [ "man:newsboat(1)" ];
};
Service = {
Type = "oneshot";
Slice = "app-newsboat.slice";
CPUSchedulingPolicy = "idle";
IOSchedulingClass = "idle";
ExecStart = "${lib.getExe pkgs.flock} %t/newsboat.lock ${lib.getExe package} --vacuum";
};
};
systemd.user.timers.newsboat-vacuum = {
Unit = {
Description = "Automatically clean newsboat cache";
Documentation = [ "man:newsboat(1)" ];
};
Timer = {
Unit = "newsboat-vacuum.service";
OnCalendar = lib.mkDefault "weekly";
Persistent = true;
};
Install = {
WantedBy = [ "timers.target" ];
};
};
# systemd.user.slices.app-newsboat = {
# Unit = {
# Description = "Newsboat automation";
# Documentation = [ "man:newsboat(1)" ];
# };
# };
}