1
0
Fork 0

refactor to move all hardcoded values to the same file

This commit is contained in:
ibizaman 2022-06-07 11:55:56 -07:00
parent c4a8c66ce6
commit 5ef87e4c9a
4 changed files with 63 additions and 17 deletions

View file

@ -2,13 +2,18 @@
, pkgs , pkgs
, lib , lib
}: }:
{ documentRoot { document_root
, name ? "ttrss" , name ? "ttrss"
, user ? "http" , user ? "http"
, group ? "http" , group ? "http"
, lock_directory ? "/run/${name}/lock" , lock_directory
, cache_dir ? "/run/${name}/cache" , cache_directory
, icons_dir ? "${documentRoot}/feed-icons" , feed_icons_directory
, db_host
, db_port
, db_username
, db_database
, db_password
}: }:
{ TtrssPostgresDB { TtrssPostgresDB
}: }:
@ -23,11 +28,11 @@ let
config = self_url_path: { config = self_url_path: {
db_type = "pgsql"; db_type = "pgsql";
db_host = TtrssPostgresDB.target.properties.hostname; db_host = db_host {inherit TtrssPostgresDB;};
db_user = TtrssPostgresDB.postgresUsername; db_port = builtins.toString db_port;
db_name = TtrssPostgresDB.postgresDatabase; db_user = db_username;
db_pass = TtrssPostgresDB.postgresPassword; db_name = db_database;
db_port = builtins.toString TtrssPostgresDB.postgresPort; db_pass = db_password;
self_url_path = self_url_path; self_url_path = self_url_path;
single_user_mode = "true"; single_user_mode = "true";
@ -35,8 +40,8 @@ let
php_executable = "${pkgs.php}/bin/php"; php_executable = "${pkgs.php}/bin/php";
lock_directory = "${lock_directory}"; lock_directory = "${lock_directory}";
cache_dir = "${cache_dir}"; cache_dir = "${cache_directory}";
icons_dir = "${icons_dir}"; icons_dir = "${feed_icons_directory}";
icons_url = "feed-icons"; icons_url = "feed-icons";
auth_auto_create = "true"; auth_auto_create = "true";
@ -68,18 +73,19 @@ stdenv.mkDerivation rec {
buildCommand = buildCommand =
let let
configFile = pkgs.writeText "config.php" (asTtrssConfig (config "https://${name}.tiserbox.com/")); configFile = pkgs.writeText "config.php" (asTtrssConfig (config "https://${name}.tiserbox.com/"));
dr = dirOf document_root;
in in
'' ''
mkdir -p $out/${name} mkdir -p $out/${name}
cp -ra $src/* $out/${name} cp -ra $src/* $out/${name}
cp ${configFile} $out/${name}/config.php cp ${configFile} $out/${name}/config.php
echo "${documentRoot}" > $out/.dysnomia-targetdir echo "${dr}" > $out/.dysnomia-targetdir
echo "${user}:${group}" > $out/.dysnomia-filesetowner echo "${user}:${group}" > $out/.dysnomia-filesetowner
cat > $out/.dysnomia-fileset <<FILESET cat > $out/.dysnomia-fileset <<FILESET
symlink $out/${name} symlink $out/${name}
target ${documentRoot} target ${dr}
FILESET FILESET
''; '';
} }

37
Ttrss/environment.nix Normal file
View file

@ -0,0 +1,37 @@
{}:
{
name ? "ttrss",
document_root ? "/usr/share/webapps/${name}",
systemd_run ? "/run/${name}",
persistent_dir ? "/var/lib/${name}"
}:
rec {
inherit name document_root systemd_run persistent_dir;
lock_directory = "${systemd_run}/lock";
cache_directory = "${systemd_run}/cache";
feed_icons_directory = "${persistent_dir}/feed-icons";
ro_directories = [];
rw_directories = [
lock_directory
cache_directory
feed_icons_directory
];
directories_modes = {
"${systemd_run}" = "0555";
"${lock_directory}" = "0755";
"${cache_directory}" = "0755";
"${cache_directory}/upload" = "0755";
"${cache_directory}/images" = "0755";
"${cache_directory}/export" = "0755";
"${persistent_dir}/feed-icons" = "0755";
};
postgresql = {
username = name;
password = "ttrsspw";
database = name;
};
}

View file

@ -3,8 +3,10 @@
, lib , lib
, utils , utils
}: }:
{ readOnlyPaths ? [] { document_root
, readOnlyPaths ? []
, readWritePaths ? [] , readWritePaths ? []
, postgresServiceName
}: }:
{ TtrssService { TtrssService
, TtrssPostgresDB , TtrssPostgresDB
@ -20,15 +22,15 @@
# - LOCK_DIRECTORY should be writable. # - LOCK_DIRECTORY should be writable.
let let
fullPath = "${TtrssService.documentRoot}/${TtrssService.documentName}"; fullPath = "${document_root}";
roPaths = [fullPath] ++ readOnlyPaths; roPaths = [fullPath] ++ readOnlyPaths;
in in
utils.systemd-service-derivation rec { utils.systemd.mkService rec {
name = "ttrss-update"; name = "ttrss-update";
content = '' content = ''
[Unit] [Unit]
Description=${name} Description=${name}
After=network.target ${TtrssPostgresDB.postgresServiceName} After=network.target ${postgresServiceName}
[Service] [Service]
User=${TtrssService.user} User=${TtrssService.user}

View file

@ -11,6 +11,7 @@ let
self = { self = {
PostgresDB = callPackage ./PostgresDB {}; PostgresDB = callPackage ./PostgresDB {};
TtrssEnvironment = callPackage ./Ttrss/environment.nix {};
TtrssService = callPackage ./Ttrss {}; TtrssService = callPackage ./Ttrss {};
TtrssUpdateService = callPackage ./Ttrss/update.nix {inherit utils;}; TtrssUpdateService = callPackage ./Ttrss/update.nix {inherit utils;};
TtrssUpgradeDBService = callPackage ./Ttrss/dbupgrade.nix {}; TtrssUpgradeDBService = callPackage ./Ttrss/dbupgrade.nix {};