change seafile.conf to be generated by from an attribute set
This commit is contained in:
parent
00458bf734
commit
86a300eaec
2 changed files with 55 additions and 52 deletions
|
@ -2,6 +2,8 @@
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
cfg = config.services.seafile-server;
|
cfg = config.services.seafile-server;
|
||||||
|
seafileConfigFile = pkgs.writeText "seafile.conf"
|
||||||
|
(generators.toINI {} cfg.seafileSettings);
|
||||||
# fix permissions at start
|
# fix permissions at start
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
@ -12,6 +14,13 @@ in
|
||||||
default = "/srv/seafile";
|
default = "/srv/seafile";
|
||||||
description = "where to store uploaded file data";
|
description = "where to store uploaded file data";
|
||||||
};
|
};
|
||||||
|
seafileSettings = mkOption {
|
||||||
|
type = with types; attrsOf (attrsOf (oneOf [ bool int str ]));
|
||||||
|
default = {};
|
||||||
|
description = ''
|
||||||
|
all possible seafile.conf settings
|
||||||
|
'';
|
||||||
|
};
|
||||||
autorun = mkOption {
|
autorun = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
|
@ -33,20 +42,12 @@ in
|
||||||
default = "seafile";
|
default = "seafile";
|
||||||
description = "Database name. Not required for sqlite.";
|
description = "Database name. Not required for sqlite.";
|
||||||
};
|
};
|
||||||
password = mkOption {
|
passwordFile = mkOption {
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Database password. Use <literal>passwordFile</literal> to avoid this
|
|
||||||
being world-readable in the <literal>/nix/store</literal>.
|
|
||||||
|
|
||||||
Not required for sqlite.'';
|
|
||||||
};
|
|
||||||
passwordFile = mkOption {
|
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
default = null;
|
default = null;
|
||||||
description = ''
|
description = ''
|
||||||
The full path to a file that contains the database password.
|
The full path to a file that contains the database password.
|
||||||
|
Not required for sqlite.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
host = mkOption {
|
host = mkOption {
|
||||||
|
@ -172,6 +173,39 @@ in
|
||||||
directoriesToManage = [ cfg.storagePath ];
|
directoriesToManage = [ cfg.storagePath ];
|
||||||
in
|
in
|
||||||
mkIf cfg.enable {
|
mkIf cfg.enable {
|
||||||
|
services.seafile-server.seafileSettings = {
|
||||||
|
library_trash.expire_days = cfg.trashExpirationTime;
|
||||||
|
fileserver = {
|
||||||
|
host = cfg.fileserverBindAddress;
|
||||||
|
port = cfg.fileserverPort;
|
||||||
|
worker_threads = cfg.fileserverWorkers;
|
||||||
|
max_indexing_threads = cfg.fileserverIndexers;
|
||||||
|
fixed_block_size = cfg.fileserverBlockSize;
|
||||||
|
};
|
||||||
|
quota = mkIf (! isNull cfg.defaultQuota) {
|
||||||
|
default = cfg.defaultQuota;
|
||||||
|
};
|
||||||
|
history = mkIf (! isNull cfg.fileRevisionHistoryDays) {
|
||||||
|
keep_days = cfg.fileRevisionHistoryDays;
|
||||||
|
};
|
||||||
|
database = mkMerge [
|
||||||
|
{
|
||||||
|
type = cfg.db.type;
|
||||||
|
}
|
||||||
|
# while just using the cfg.db set directly might be possible and
|
||||||
|
# save lines of code, I prefer hand-picking options
|
||||||
|
(mkIf (cfg.db.type == "mysql") {
|
||||||
|
host = cfg.db.host;
|
||||||
|
port = cfg.db.port;
|
||||||
|
user = cfg.db.user;
|
||||||
|
connection_charset = "utf8";
|
||||||
|
db_name = cfg.db.dbname;
|
||||||
|
max_connections = 100;
|
||||||
|
password = "#dbpass#";
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
systemd = {
|
systemd = {
|
||||||
# state directory permissions managed by systemd
|
# state directory permissions managed by systemd
|
||||||
tmpfiles.rules = [
|
tmpfiles.rules = [
|
||||||
|
@ -209,47 +243,16 @@ in
|
||||||
|
|
||||||
# seafile.conf generation
|
# seafile.conf generation
|
||||||
|
|
||||||
echo '[library_trash]
|
# move seafile.conf template from nix store
|
||||||
expire_days ${toString cfg.trashExpirationTime}
|
cp ${seafileConfigFile} ./conf/seafile.conf
|
||||||
|
# replace placeholder secrets with real secret read from file
|
||||||
|
${if (isNull cfg.db.passwordFile) then ''
|
||||||
|
DBPASS="$(head -n1 ${toString cfg.db.passwordFile})"
|
||||||
|
sed -e "s,#dbpass#,$DBPASS,g" -i ./conf/seafile.conf
|
||||||
|
''
|
||||||
|
else ""
|
||||||
|
}
|
||||||
|
|
||||||
[fileserver]
|
|
||||||
host = ${cfg.fileserverBindAddress}
|
|
||||||
port = ${toString cfg.fileserverPort}
|
|
||||||
worker_threads = ${toString cfg.fileserverWorkers}
|
|
||||||
max_indexing_threads = ${toString cfg.fileserverIndexers}
|
|
||||||
fixed_block_size = ${toString cfg.fileserverIndexers}' > ./conf/seafile.conf
|
|
||||||
|
|
||||||
if [ ${toString (! isNull cfg.defaultQuota)} ]; then
|
|
||||||
echo '[quota]' >> ./conf/seafile.conf
|
|
||||||
echo 'default = ${toString cfg.defaultQuota}' >> ./conf/seafile.conf
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ${toString (! isNull cfg.fileRevisionHistoryDays)} ]; then
|
|
||||||
echo '[history]' >> ./conf/seafile.conf
|
|
||||||
echo 'keep_days = ${toString cfg.defaultQuota}' >> ./conf/seafile.conf
|
|
||||||
fi
|
|
||||||
|
|
||||||
# seafile database settings
|
|
||||||
|
|
||||||
if [ ${cfg.db.type} = "mysql" ]; then
|
|
||||||
echo '[database]
|
|
||||||
type = mysql
|
|
||||||
host = ${cfg.db.host}
|
|
||||||
port = ${toString cfg.db.dbport}
|
|
||||||
user = ${cfg.db.user}
|
|
||||||
connection_charset = utf8
|
|
||||||
db_name = ${cfg.db.dbname}
|
|
||||||
max_connections = 100' >> ./conf/seafile.conf
|
|
||||||
|
|
||||||
if [ ${toString (! isNull cfg.db.password)}; then
|
|
||||||
echo 'password = ${toString cfg.db.password}' >> ./conf/seafile.conf
|
|
||||||
else
|
|
||||||
echo "password = $(cat ${toString cfg.db.passwordFile})" >> ./conf/seafile.conf
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo '[database]
|
|
||||||
type = sqlite' >> ./conf/seafile.conf
|
|
||||||
fi
|
|
||||||
|
|
||||||
ln -s ${pkgs.seafile-server} seafile-server
|
ln -s ${pkgs.seafile-server} seafile-server
|
||||||
./seafile-server/seafile-server-latest/bin/seafile-admin setup
|
./seafile-server/seafile-server-latest/bin/seafile-admin setup
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
extraGroups = [ "wheel" ];
|
extraGroups = [ "wheel" ];
|
||||||
#hashedPassword = "$6$SZCzE/xB$Hr9sfsJ7xAcBCoptG39cxxQk8RZfldDjjGpSngOvn9Ufex5dHBEbdncXRZnfrGATsGcYPvLi7m4wIu.f8tY9B.";
|
#hashedPassword = "$6$SZCzE/xB$Hr9sfsJ7xAcBCoptG39cxxQk8RZfldDjjGpSngOvn9Ufex5dHBEbdncXRZnfrGATsGcYPvLi7m4wIu.f8tY9B.";
|
||||||
password = "";
|
password = "test";
|
||||||
home = "/home/test";
|
home = "/home/test";
|
||||||
createHome = true;
|
createHome = true;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue