nixos/services.nitter: remove with lib;

This commit is contained in:
Felix Buehler
2024-08-24 22:05:50 +02:00
parent 36eaab4720
commit f3212dfec4

View File

@@ -1,16 +1,13 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with lib;
let let
cfg = config.services.nitter; cfg = config.services.nitter;
configFile = pkgs.writeText "nitter.conf" '' configFile = pkgs.writeText "nitter.conf" ''
${generators.toINI { ${lib.generators.toINI {
# String values need to be quoted # String values need to be quoted
mkKeyValue = generators.mkKeyValueDefault { mkKeyValue = lib.generators.mkKeyValueDefault {
mkValueString = v: mkValueString = v:
if isString v then "\"" + (strings.escape ["\""] (toString v)) + "\"" if lib.isString v then "\"" + (lib.escape ["\""] (toString v)) + "\""
else generators.mkValueStringDefault {} v; else lib.generators.mkValueStringDefault {} v;
} " = "; } " = ";
} (lib.recursiveUpdate { } (lib.recursiveUpdate {
Server = cfg.server; Server = cfg.server;
@@ -47,57 +44,57 @@ in
{ {
imports = [ imports = [
# https://github.com/zedeus/nitter/pull/772 # https://github.com/zedeus/nitter/pull/772
(mkRemovedOptionModule [ "services" "nitter" "replaceInstagram" ] "Nitter no longer supports this option as Bibliogram has been discontinued.") (lib.mkRemovedOptionModule [ "services" "nitter" "replaceInstagram" ] "Nitter no longer supports this option as Bibliogram has been discontinued.")
]; ];
options = { options = {
services.nitter = { services.nitter = {
enable = mkEnableOption "Nitter, an alternative Twitter front-end"; enable = lib.mkEnableOption "Nitter, an alternative Twitter front-end";
package = mkPackageOption pkgs "nitter" { }; package = lib.mkPackageOption pkgs "nitter" { };
server = { server = {
address = mkOption { address = lib.mkOption {
type = types.str; type = lib.types.str;
default = "0.0.0.0"; default = "0.0.0.0";
example = "127.0.0.1"; example = "127.0.0.1";
description = "The address to listen on."; description = "The address to listen on.";
}; };
port = mkOption { port = lib.mkOption {
type = types.port; type = lib.types.port;
default = 8080; default = 8080;
example = 8000; example = 8000;
description = "The port to listen on."; description = "The port to listen on.";
}; };
https = mkOption { https = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Set secure attribute on cookies. Keep it disabled to enable cookies when not using HTTPS."; description = "Set secure attribute on cookies. Keep it disabled to enable cookies when not using HTTPS.";
}; };
httpMaxConnections = mkOption { httpMaxConnections = lib.mkOption {
type = types.int; type = lib.types.int;
default = 100; default = 100;
description = "Maximum number of HTTP connections."; description = "Maximum number of HTTP connections.";
}; };
staticDir = mkOption { staticDir = lib.mkOption {
type = types.path; type = lib.types.path;
default = "${cfg.package}/share/nitter/public"; default = "${cfg.package}/share/nitter/public";
defaultText = literalExpression ''"''${config.services.nitter.package}/share/nitter/public"''; defaultText = lib.literalExpression ''"''${config.services.nitter.package}/share/nitter/public"'';
description = "Path to the static files directory."; description = "Path to the static files directory.";
}; };
title = mkOption { title = lib.mkOption {
type = types.str; type = lib.types.str;
default = "nitter"; default = "nitter";
description = "Title of the instance."; description = "Title of the instance.";
}; };
hostname = mkOption { hostname = lib.mkOption {
type = types.str; type = lib.types.str;
default = "localhost"; default = "localhost";
example = "nitter.net"; example = "nitter.net";
description = "Hostname of the instance."; description = "Hostname of the instance.";
@@ -105,38 +102,38 @@ in
}; };
cache = { cache = {
listMinutes = mkOption { listMinutes = lib.mkOption {
type = types.int; type = lib.types.int;
default = 240; default = 240;
description = "How long to cache list info (not the tweets, so keep it high)."; description = "How long to cache list info (not the tweets, so keep it high).";
}; };
rssMinutes = mkOption { rssMinutes = lib.mkOption {
type = types.int; type = lib.types.int;
default = 10; default = 10;
description = "How long to cache RSS queries."; description = "How long to cache RSS queries.";
}; };
redisHost = mkOption { redisHost = lib.mkOption {
type = types.str; type = lib.types.str;
default = "localhost"; default = "localhost";
description = "Redis host."; description = "Redis host.";
}; };
redisPort = mkOption { redisPort = lib.mkOption {
type = types.port; type = lib.types.port;
default = 6379; default = 6379;
description = "Redis port."; description = "Redis port.";
}; };
redisConnections = mkOption { redisConnections = lib.mkOption {
type = types.int; type = lib.types.int;
default = 20; default = 20;
description = "Redis connection pool size."; description = "Redis connection pool size.";
}; };
redisMaxConnections = mkOption { redisMaxConnections = lib.mkOption {
type = types.int; type = lib.types.int;
default = 30; default = 30;
description = '' description = ''
Maximum number of connections to Redis. Maximum number of connections to Redis.
@@ -149,30 +146,30 @@ in
}; };
config = { config = {
base64Media = mkOption { base64Media = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Use base64 encoding for proxied media URLs."; description = "Use base64 encoding for proxied media URLs.";
}; };
enableRSS = mkEnableOption "RSS feeds" // { default = true; }; enableRSS = lib.mkEnableOption "RSS feeds" // { default = true; };
enableDebug = mkEnableOption "request logs and debug endpoints"; enableDebug = lib.mkEnableOption "request logs and debug endpoints";
proxy = mkOption { proxy = lib.mkOption {
type = types.str; type = lib.types.str;
default = ""; default = "";
description = "URL to a HTTP/HTTPS proxy."; description = "URL to a HTTP/HTTPS proxy.";
}; };
proxyAuth = mkOption { proxyAuth = lib.mkOption {
type = types.str; type = lib.types.str;
default = ""; default = "";
description = "Credentials for proxy."; description = "Credentials for proxy.";
}; };
tokenCount = mkOption { tokenCount = lib.mkOption {
type = types.int; type = lib.types.int;
default = 10; default = 10;
description = '' description = ''
Minimum amount of usable tokens. Minimum amount of usable tokens.
@@ -187,114 +184,114 @@ in
}; };
preferences = { preferences = {
replaceTwitter = mkOption { replaceTwitter = lib.mkOption {
type = types.str; type = lib.types.str;
default = ""; default = "";
example = "nitter.net"; example = "nitter.net";
description = "Replace Twitter links with links to this instance (blank to disable)."; description = "Replace Twitter links with links to this instance (blank to disable).";
}; };
replaceYouTube = mkOption { replaceYouTube = lib.mkOption {
type = types.str; type = lib.types.str;
default = ""; default = "";
example = "piped.kavin.rocks"; example = "piped.kavin.rocks";
description = "Replace YouTube links with links to this instance (blank to disable)."; description = "Replace YouTube links with links to this instance (blank to disable).";
}; };
replaceReddit = mkOption { replaceReddit = lib.mkOption {
type = types.str; type = lib.types.str;
default = ""; default = "";
example = "teddit.net"; example = "teddit.net";
description = "Replace Reddit links with links to this instance (blank to disable)."; description = "Replace Reddit links with links to this instance (blank to disable).";
}; };
mp4Playback = mkOption { mp4Playback = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = "Enable MP4 video playback."; description = "Enable MP4 video playback.";
}; };
hlsPlayback = mkOption { hlsPlayback = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Enable HLS video streaming (requires JavaScript)."; description = "Enable HLS video streaming (requires JavaScript).";
}; };
proxyVideos = mkOption { proxyVideos = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = "Proxy video streaming through the server (might be slow)."; description = "Proxy video streaming through the server (might be slow).";
}; };
muteVideos = mkOption { muteVideos = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Mute videos by default."; description = "Mute videos by default.";
}; };
autoplayGifs = mkOption { autoplayGifs = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = "Autoplay GIFs."; description = "Autoplay GIFs.";
}; };
theme = mkOption { theme = lib.mkOption {
type = types.str; type = lib.types.str;
default = "Nitter"; default = "Nitter";
description = "Instance theme."; description = "Instance theme.";
}; };
infiniteScroll = mkOption { infiniteScroll = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Infinite scrolling (requires JavaScript, experimental!)."; description = "Infinite scrolling (requires JavaScript, experimental!).";
}; };
stickyProfile = mkOption { stickyProfile = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = "Make profile sidebar stick to top."; description = "Make profile sidebar stick to top.";
}; };
bidiSupport = mkOption { bidiSupport = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Support bidirectional text (makes clicking on tweets harder)."; description = "Support bidirectional text (makes clicking on tweets harder).";
}; };
hideTweetStats = mkOption { hideTweetStats = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Hide tweet stats (replies, retweets, likes)."; description = "Hide tweet stats (replies, retweets, likes).";
}; };
hideBanner = mkOption { hideBanner = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Hide profile banner."; description = "Hide profile banner.";
}; };
hidePins = mkOption { hidePins = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Hide pinned tweets."; description = "Hide pinned tweets.";
}; };
hideReplies = mkOption { hideReplies = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Hide tweet replies."; description = "Hide tweet replies.";
}; };
squareAvatars = mkOption { squareAvatars = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Square profile pictures."; description = "Square profile pictures.";
}; };
}; };
settings = mkOption { settings = lib.mkOption {
type = types.attrs; type = lib.types.attrs;
default = {}; default = {};
description = '' description = ''
Add settings here to override NixOS module generated settings. Add settings here to override NixOS module generated settings.
@@ -304,8 +301,8 @@ in
''; '';
}; };
guestAccounts = mkOption { guestAccounts = lib.mkOption {
type = types.path; type = lib.types.path;
default = "/var/lib/nitter/guest_accounts.jsonl"; default = "/var/lib/nitter/guest_accounts.jsonl";
description = '' description = ''
Path to the guest accounts file. Path to the guest accounts file.
@@ -321,21 +318,21 @@ in
''; '';
}; };
redisCreateLocally = mkOption { redisCreateLocally = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = "Configure local Redis server for Nitter."; description = "Configure local Redis server for Nitter.";
}; };
openFirewall = mkOption { openFirewall = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Open ports in the firewall for Nitter web interface."; description = "Open ports in the firewall for Nitter web interface.";
}; };
}; };
}; };
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
assertions = [ assertions = [
{ {
assertion = !cfg.redisCreateLocally || (cfg.cache.redisHost == "localhost" && cfg.cache.redisPort == 6379); assertion = !cfg.redisCreateLocally || (cfg.cache.redisHost == "localhost" && cfg.cache.redisPort == 6379);
@@ -397,7 +394,7 @@ in
port = cfg.cache.redisPort; port = cfg.cache.redisPort;
}; };
networking.firewall = mkIf cfg.openFirewall { networking.firewall = lib.mkIf cfg.openFirewall {
allowedTCPPorts = [ cfg.server.port ]; allowedTCPPorts = [ cfg.server.port ];
}; };
}; };