From 3c0df2a7e43b432b739d8e9d289dcb362a44b308 Mon Sep 17 00:00:00 2001 From: Vonixxx Date: Sun, 21 Apr 2024 13:12:43 +0200 Subject: [PATCH] freetube: add module --- modules/misc/news.nix | 11 ++++ modules/modules.nix | 1 + modules/programs/freetube.nix | 60 +++++++++++++++++++ tests/default.nix | 1 + .../programs/freetube/basic-configuration.db | 8 +++ .../programs/freetube/basic-configuration.nix | 30 ++++++++++ tests/modules/programs/freetube/default.nix | 1 + 7 files changed, 112 insertions(+) create mode 100644 modules/programs/freetube.nix create mode 100644 tests/modules/programs/freetube/basic-configuration.db create mode 100644 tests/modules/programs/freetube/basic-configuration.nix create mode 100644 tests/modules/programs/freetube/default.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index b13a9d33..b189fb00 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1561,6 +1561,17 @@ in { https://github.com/ErikReider/SwayNotificationCenter for more. ''; } + + { + time = "2024-04-30T18:28:28+00:00"; + message = '' + A new module is available: 'programs.freetube'. + + FreeTube is a YouTube client built around using YouTube more + privately. You can enjoy your favorite content and creators without + your habits being tracked. See https://freetubeapp.io/ for more. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index d526c352..e14c26d5 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -92,6 +92,7 @@ let ./programs/firefox.nix ./programs/fish.nix ./programs/foot.nix + ./programs/freetube.nix ./programs/fuzzel.nix ./programs/fzf.nix ./programs/gallery-dl.nix diff --git a/modules/programs/freetube.nix b/modules/programs/freetube.nix new file mode 100644 index 00000000..77700fe5 --- /dev/null +++ b/modules/programs/freetube.nix @@ -0,0 +1,60 @@ +{ lib, pkgs, config, ... }: + +let + inherit (lib) + concatStringsSep mapAttrsToList mkIf mkEnableOption mkPackageOption mkOption + literalExpression; + + cfg = config.programs.freetube; + + settings = settings: + let + convertSetting = name: value: + builtins.toJSON { + "_id" = name; + "value" = value; + }; + in concatStringsSep "\n" (mapAttrsToList convertSetting settings) + "\n"; +in { + meta.maintainers = with lib.maintainers; [ vonixxx ]; + + options.programs.freetube = { + enable = mkEnableOption "FreeTube, a YT client for Windows, Mac, and Linux"; + + package = mkPackageOption pkgs "freetube" { }; + + settings = mkOption { + type = lib.types.attrs; + default = { }; + example = literalExpression '' + { + allowDashAv1Formats = true; + checkForUpdates = false; + defaultQuality = "1080"; + baseTheme = "catppuccinMocha"; + } + ''; + description = '' + Configuration settings for FreeTube. + + All configurable options can be deduced by enabling them through the + GUI and observing the changes in {file}`settings.db`. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile."FreeTube/hm_settings.db" = { + source = pkgs.writeText "hm_settings.db" (settings cfg.settings); + + onChange = let + hmSettingsDb = "${config.xdg.configHome}/FreeTube/hm_settings.db"; + settingsDb = "${config.xdg.configHome}/FreeTube/settings.db"; + in '' + run install -Dm644 $VERBOSE_ARG '${hmSettingsDb}' '${settingsDb}' + ''; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 15a54f08..7f92c2bd 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -190,6 +190,7 @@ in import nmtSrc { ./modules/programs/boxxy ./modules/programs/firefox ./modules/programs/foot + ./modules/programs/freetube ./modules/programs/fuzzel ./modules/programs/getmail ./modules/programs/gnome-terminal diff --git a/tests/modules/programs/freetube/basic-configuration.db b/tests/modules/programs/freetube/basic-configuration.db new file mode 100644 index 00000000..50d43a11 --- /dev/null +++ b/tests/modules/programs/freetube/basic-configuration.db @@ -0,0 +1,8 @@ +{"_id":"allowDashAv1Formats","value":true} +{"_id":"checkForBlogPosts","value":false} +{"_id":"checkForUpdates","value":false} +{"_id":"commentAutoLoadEnabled","value":true} +{"_id":"defaultQuality","value":"1080"} +{"_id":"hideHeaderLogo","value":true} +{"_id":"listType","value":"list"} +{"_id":"useRssFeeds","value":true} diff --git a/tests/modules/programs/freetube/basic-configuration.nix b/tests/modules/programs/freetube/basic-configuration.nix new file mode 100644 index 00000000..a30d3bed --- /dev/null +++ b/tests/modules/programs/freetube/basic-configuration.nix @@ -0,0 +1,30 @@ +{ config, pkgs, ... }: + +{ + programs.freetube = { + enable = true; + settings = { + useRssFeeds = true; + hideHeaderLogo = true; + allowDashAv1Formats = true; + commentAutoLoadEnabled = true; + + checkForUpdates = false; + checkForBlogPosts = false; + + listType = "list"; + defaultQuality = "1080"; + }; + }; + + test.stubs.freetube = { }; + + nmt.script = '' + assertFileExists home-files/.config/FreeTube/hm_settings.db + assertFileContent home-files/.config/FreeTube/hm_settings.db \ + ${./basic-configuration.db} + + assertFileContains activate \ + "install -Dm644 \$VERBOSE_ARG '/home/hm-user/.config/FreeTube/hm_settings.db' '/home/hm-user/.config/FreeTube/settings.db'" + ''; +} diff --git a/tests/modules/programs/freetube/default.nix b/tests/modules/programs/freetube/default.nix new file mode 100644 index 00000000..cb6fd4d2 --- /dev/null +++ b/tests/modules/programs/freetube/default.nix @@ -0,0 +1 @@ +{ freetube-basic-configuration = ./basic-configuration.nix; }