From e298262966c5cb9b5f5df1dbb42a3a6a92db9413 Mon Sep 17 00:00:00 2001 From: h7x4 <h7x4@nani.wtf> Date: Mon, 24 Mar 2025 15:38:58 +0100 Subject: [PATCH] home/modules: move newsboat automation to module --- flake.nix | 1 + home/home.nix | 1 + home/modules/programs/newsboat/default.nix | 6 ++ .../programs/newsboat/fetch-articles.nix | 53 ++++++++++++ home/modules/programs/newsboat/vacuum.nix | 51 ++++++++++++ home/programs/newsboat/default.nix | 82 +++---------------- 6 files changed, 122 insertions(+), 72 deletions(-) create mode 100644 home/modules/programs/newsboat/default.nix create mode 100644 home/modules/programs/newsboat/fetch-articles.nix create mode 100644 home/modules/programs/newsboat/vacuum.nix diff --git a/flake.nix b/flake.nix index c68879d..167e54c 100644 --- a/flake.nix +++ b/flake.nix @@ -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 = { diff --git a/home/home.nix b/home/home.nix index 65caadd..e05cf1f 100644 --- a/home/home.nix +++ b/home/home.nix @@ -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 diff --git a/home/modules/programs/newsboat/default.nix b/home/modules/programs/newsboat/default.nix new file mode 100644 index 0000000..4464321 --- /dev/null +++ b/home/modules/programs/newsboat/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./vacuum.nix + ./fetch-articles.nix + ]; +} diff --git a/home/modules/programs/newsboat/fetch-articles.nix b/home/modules/programs/newsboat/fetch-articles.nix new file mode 100644 index 0000000..3546493 --- /dev/null +++ b/home/modules/programs/newsboat/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" ]; + }; + }; + }; +} diff --git a/home/modules/programs/newsboat/vacuum.nix b/home/modules/programs/newsboat/vacuum.nix new file mode 100644 index 0000000..1bc9ffe --- /dev/null +++ b/home/modules/programs/newsboat/vacuum.nix @@ -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" ]; + }; + }; + }; +} diff --git a/home/programs/newsboat/default.nix b/home/programs/newsboat/default.nix index ca23ab2..78f3949 100644 --- a/home/programs/newsboat/default.nix +++ b/home/programs/newsboat/default.nix @@ -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)" ]; + # }; + # }; }