add news2kintle module and service
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
./programs/installed.nix
|
./programs/installed.nix
|
||||||
./services/enabled.nix
|
./services/enabled.nix
|
||||||
./users.nix
|
./users.nix
|
||||||
|
./module/news2kindle/news2kindle.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
nixpkgs.config.allowUnfree = true;
|
nixpkgs.config.allowUnfree = true;
|
||||||
|
|||||||
185
module/news2kindle/news2kindle.nix
Normal file
185
module/news2kindle/news2kindle.nix
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
cfg = config.services.news2kindle;
|
||||||
|
|
||||||
|
portString = toString cfg.smtp.port;
|
||||||
|
|
||||||
|
convertScript = pkgs.writeText "convertScript.sh" ''#!/bin/bash
|
||||||
|
NAME=$1
|
||||||
|
RECIPEPATH=$2
|
||||||
|
MOBIPATH=$3
|
||||||
|
FROMADDR=$4
|
||||||
|
TOADDR=$5
|
||||||
|
if [ ! -f mobi/$NAME.mobi ]; then
|
||||||
|
ebook-convert $RECIPEPATH/$NAME.recipe $MOBIPATH/$NAME.mobi --output-profile kindle -v
|
||||||
|
fi
|
||||||
|
|
||||||
|
mailsend -smtp ${cfg.smtp.address} -port ${portString} -from $FROMADDR -to $TOADDR -sub "New news from $NAME" -attach $MOBIPATH/$NAME.mobi
|
||||||
|
sleep 60
|
||||||
|
'';
|
||||||
|
|
||||||
|
callConvertScripts =
|
||||||
|
let
|
||||||
|
makeCallLine = recipient:
|
||||||
|
map (makeCallLineRecipe recipient.mail) recipient.recipes;
|
||||||
|
makeCallLineRecipe = recipientMail: recipe:
|
||||||
|
if isNull recipe.content then
|
||||||
|
"bash ${convertScript} ${recipe.name} ${calibreWithRecipes}/var/news2kindle/recipes ${cfg.mobiPath} ${cfg.fromMail} ${recipientMail}\n"
|
||||||
|
else
|
||||||
|
''
|
||||||
|
mkdir -p /tmp/news2kindle/recipes
|
||||||
|
echo "${recipe.content}" > /tmp/news2kindle/recipes/${recipe.name}.recipe
|
||||||
|
bash ${convertScript} ${recipe.name} /tmp/news2kindle/recipes/ ${cfg.mobiPath} ${cfg.fromMail} ${recipientMail}
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
concatMap makeCallLine cfg.recipients;
|
||||||
|
|
||||||
|
dailyUpdateScript = pkgs.writeText "dailyUpdates.sh" ''#!/bin/bash
|
||||||
|
rm -f ${cfg.mobiPath}/*.mobi
|
||||||
|
mkdir -p ${cfg.mobiPath}
|
||||||
|
${concatStrings callConvertScripts}
|
||||||
|
'';
|
||||||
|
|
||||||
|
calibreWithRecipes = pkgs.calibre.overrideAttrs (oldAttrs: rec {
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/var/news2kindle/recipes
|
||||||
|
cp -ravf recipes $out/var/news2kindle
|
||||||
|
''+ oldAttrs.installPhase ;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
###### interface
|
||||||
|
|
||||||
|
options = {
|
||||||
|
|
||||||
|
services.news2kindle = {
|
||||||
|
|
||||||
|
enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether to enable news2kindle service.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
recipePath = mkOption {
|
||||||
|
example = "/var/news2kindle/recipes";
|
||||||
|
default = "/var/news2kindle/recipes";
|
||||||
|
type = types.str;
|
||||||
|
description = ''
|
||||||
|
Path where the recipes should be saved
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
mobiPath = mkOption {
|
||||||
|
example = "/tmp/news2kindle/mobi";
|
||||||
|
default = "/tmp/news2kindle/mobi";
|
||||||
|
type = types.str;
|
||||||
|
description = ''
|
||||||
|
Path where the mobi files should be saved
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
fromMail = mkOption {
|
||||||
|
example = "news@stubbe.rocks";
|
||||||
|
default = "news@stubbe.rocks";
|
||||||
|
type = types.str;
|
||||||
|
description = ''
|
||||||
|
Adrees of the sender, please allow this mail in your kindle doc service
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
recipients = mkOption {
|
||||||
|
type = with types; listOf (submodule {
|
||||||
|
options = {
|
||||||
|
mail = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
name of recipe
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
recipes = mkOption {
|
||||||
|
type = with types; listOf (submodule {
|
||||||
|
options = {
|
||||||
|
name = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
name of recipe
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
content = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
content of the recipe file, when its null the use the builtins recipes
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
default = [];
|
||||||
|
example = [ { name = "heise";} { name = "Postillon"; port = ''
|
||||||
|
class BasicUserRecipe1414943033(AutomaticNewsRecipe):
|
||||||
|
title = u'Postillon'
|
||||||
|
oldest_article = 7
|
||||||
|
max_articles_per_feed = 100
|
||||||
|
auto_cleanup = True
|
||||||
|
feeds= [(u'Postilion', u'http://feeds.feedburner.com/blogspot/rkEL')] ''; } ];
|
||||||
|
description = ''
|
||||||
|
List of recipes wich the user wants fetch. If recipe content is not specified the fetcher uses builtins recipes
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
default = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
smtp = {
|
||||||
|
|
||||||
|
address = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "localhost";
|
||||||
|
description = "Address of the SMTP server for news2kindle.";
|
||||||
|
};
|
||||||
|
|
||||||
|
port = mkOption {
|
||||||
|
type = types.int;
|
||||||
|
default = 25;
|
||||||
|
description = "Port of the SMTP server for news2kindle.";
|
||||||
|
};
|
||||||
|
|
||||||
|
username = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
description = "Username of the SMTP server for news2kindle.";
|
||||||
|
};
|
||||||
|
|
||||||
|
password = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
description = "Password of the SMTP server for news2kindle.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
###### implementation
|
||||||
|
|
||||||
|
config = mkIf cfg.enable{
|
||||||
|
environment.systemPackages = [pkgs.python27Packages.pyqt5 pkgs.python36Packages.pyqt5 pkgs.mailsend calibreWithRecipes];
|
||||||
|
services.cron.enable = true;
|
||||||
|
services.cron.systemCronJobs = [ "0 5 * * * root bash ${dailyUpdateScript}"];
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -8,5 +8,6 @@
|
|||||||
./nginx.nix
|
./nginx.nix
|
||||||
./gitlab.nix
|
./gitlab.nix
|
||||||
./nextcloud.nix
|
./nextcloud.nix
|
||||||
|
./news2kindle.nix
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
40
services/news2kindle.nix
Normal file
40
services/news2kindle.nix
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
services.postfix.enable = true;
|
||||||
|
services.postfix.extraConfig = "message_size_limit=52428800";
|
||||||
|
services.news2kindle = {
|
||||||
|
enable = true;
|
||||||
|
recipients = [
|
||||||
|
{
|
||||||
|
mail = "stubbfel@kindle.com";
|
||||||
|
recipes = [
|
||||||
|
{ name = "heise"; }
|
||||||
|
{ name = "netzpolitik"; }
|
||||||
|
{ name = "zeitde"; }
|
||||||
|
{ name = "spiegelde"; }
|
||||||
|
{ name = "Postillon";
|
||||||
|
content = ''
|
||||||
|
class BasicUserRecipe1414943033(AutomaticNewsRecipe):
|
||||||
|
title = u'Der Postillon'
|
||||||
|
oldest_article = 7
|
||||||
|
max_articles_per_feed = 100
|
||||||
|
auto_cleanup = True
|
||||||
|
feeds = [(u'Postilion',
|
||||||
|
u'http://feeds.feedburner.com/blogspot/rkEL')]
|
||||||
|
'';}
|
||||||
|
{ name = "Störungsmelder";
|
||||||
|
content = ''
|
||||||
|
class BasicUserRecipe1397125629(AutomaticNewsRecipe):
|
||||||
|
title = u'st\xf6rungsmelder'
|
||||||
|
oldest_article = 7
|
||||||
|
max_articles_per_feed = 100
|
||||||
|
auto_cleanup = True
|
||||||
|
feeds = [(u'st\xf6rungsmelder',
|
||||||
|
u'http://blog.zeit.de/stoerungsmelder/feed')]
|
||||||
|
'';}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -12,7 +12,6 @@ in
|
|||||||
users = {
|
users = {
|
||||||
defaultUserShell = pkgs.zsh;
|
defaultUserShell = pkgs.zsh;
|
||||||
extraUsers.sshuser = myPublicSshKeys // { isNormalUser = true; home = "/home/sshuser";};
|
extraUsers.sshuser = myPublicSshKeys // { isNormalUser = true; home = "/home/sshuser";};
|
||||||
extraUsers.calibre = myPublicSshKeys // { isNormalUser = true; home = "/home/calibre"; packages = [pkgs.xvfb_run pkgs.calibre]};
|
|
||||||
extraUsers.nextcloud = myPublicSshKeys // { isNormalUser = true; home = "/home/nextcloud"; group = "nextcloud";};
|
extraUsers.nextcloud = myPublicSshKeys // { isNormalUser = true; home = "/home/nextcloud"; group = "nextcloud";};
|
||||||
extraGroups.nexdcloud.name = "nextcloud";
|
extraGroups.nexdcloud.name = "nextcloud";
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user