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
, lib
}:
{ documentRoot
{ document_root
, name ? "ttrss"
, user ? "http"
, group ? "http"
, lock_directory ? "/run/${name}/lock"
, cache_dir ? "/run/${name}/cache"
, icons_dir ? "${documentRoot}/feed-icons"
, lock_directory
, cache_directory
, feed_icons_directory
, db_host
, db_port
, db_username
, db_database
, db_password
}:
{ TtrssPostgresDB
}:
@ -23,11 +28,11 @@ let
config = self_url_path: {
db_type = "pgsql";
db_host = TtrssPostgresDB.target.properties.hostname;
db_user = TtrssPostgresDB.postgresUsername;
db_name = TtrssPostgresDB.postgresDatabase;
db_pass = TtrssPostgresDB.postgresPassword;
db_port = builtins.toString TtrssPostgresDB.postgresPort;
db_host = db_host {inherit TtrssPostgresDB;};
db_port = builtins.toString db_port;
db_user = db_username;
db_name = db_database;
db_pass = db_password;
self_url_path = self_url_path;
single_user_mode = "true";
@ -35,8 +40,8 @@ let
php_executable = "${pkgs.php}/bin/php";
lock_directory = "${lock_directory}";
cache_dir = "${cache_dir}";
icons_dir = "${icons_dir}";
cache_dir = "${cache_directory}";
icons_dir = "${feed_icons_directory}";
icons_url = "feed-icons";
auth_auto_create = "true";
@ -68,18 +73,19 @@ stdenv.mkDerivation rec {
buildCommand =
let
configFile = pkgs.writeText "config.php" (asTtrssConfig (config "https://${name}.tiserbox.com/"));
dr = dirOf document_root;
in
''
mkdir -p $out/${name}
cp -ra $src/* $out/${name}
cp ${configFile} $out/${name}/config.php
echo "${documentRoot}" > $out/.dysnomia-targetdir
echo "${dr}" > $out/.dysnomia-targetdir
echo "${user}:${group}" > $out/.dysnomia-filesetowner
cat > $out/.dysnomia-fileset <<FILESET
symlink $out/${name}
target ${documentRoot}
target ${dr}
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
, utils
}:
{ readOnlyPaths ? []
{ document_root
, readOnlyPaths ? []
, readWritePaths ? []
, postgresServiceName
}:
{ TtrssService
, TtrssPostgresDB
@ -20,15 +22,15 @@
# - LOCK_DIRECTORY should be writable.
let
fullPath = "${TtrssService.documentRoot}/${TtrssService.documentName}";
fullPath = "${document_root}";
roPaths = [fullPath] ++ readOnlyPaths;
in
utils.systemd-service-derivation rec {
utils.systemd.mkService rec {
name = "ttrss-update";
content = ''
[Unit]
Description=${name}
After=network.target ${TtrssPostgresDB.postgresServiceName}
After=network.target ${postgresServiceName}
[Service]
User=${TtrssService.user}

View file

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