2019-11-09 20:35:50 +01:00
|
|
|
import ./make-test-python.nix ({ pkgs, lib, ... }:
|
2018-12-21 19:36:58 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
port = 3142;
|
|
|
|
username = "alice";
|
|
|
|
password = "correcthorsebatterystaple";
|
|
|
|
defaultPort = 8080;
|
|
|
|
defaultUsername = "admin";
|
|
|
|
defaultPassword = "password";
|
2022-01-02 13:00:00 +01:00
|
|
|
adminCredentialsFile = pkgs.writeText "admin-credentials" ''
|
|
|
|
ADMIN_USERNAME=${defaultUsername}
|
|
|
|
ADMIN_PASSWORD=${defaultPassword}
|
|
|
|
'';
|
|
|
|
customAdminCredentialsFile = pkgs.writeText "admin-credentials" ''
|
|
|
|
ADMIN_USERNAME=${username}
|
|
|
|
ADMIN_PASSWORD=${password}
|
|
|
|
'';
|
2024-02-15 11:29:39 +01:00
|
|
|
postgresPassword = "correcthorsebatterystaple";
|
|
|
|
postgresPasswordFile = pkgs.writeText "pgpass" ''
|
|
|
|
*:*:*:*:${postgresPassword}
|
|
|
|
'';
|
2022-01-02 13:00:00 +01:00
|
|
|
|
2018-12-21 19:36:58 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
name = "miniflux";
|
2023-04-30 16:26:17 +02:00
|
|
|
meta.maintainers = [ ];
|
2018-12-21 19:36:58 +01:00
|
|
|
|
|
|
|
nodes = {
|
|
|
|
default =
|
|
|
|
{ ... }:
|
|
|
|
{
|
2023-07-08 02:18:34 +02:00
|
|
|
security.apparmor.enable = true;
|
2022-01-02 13:00:00 +01:00
|
|
|
services.miniflux = {
|
|
|
|
enable = true;
|
|
|
|
inherit adminCredentialsFile;
|
|
|
|
};
|
2018-12-21 19:36:58 +01:00
|
|
|
};
|
|
|
|
|
2021-01-28 19:09:31 +01:00
|
|
|
withoutSudo =
|
|
|
|
{ ... }:
|
|
|
|
{
|
2023-07-08 02:18:34 +02:00
|
|
|
security.apparmor.enable = true;
|
2022-01-02 13:00:00 +01:00
|
|
|
services.miniflux = {
|
|
|
|
enable = true;
|
|
|
|
inherit adminCredentialsFile;
|
|
|
|
};
|
2021-01-28 19:09:31 +01:00
|
|
|
security.sudo.enable = false;
|
|
|
|
};
|
|
|
|
|
2018-12-21 19:36:58 +01:00
|
|
|
customized =
|
|
|
|
{ ... }:
|
|
|
|
{
|
2023-07-08 02:18:34 +02:00
|
|
|
security.apparmor.enable = true;
|
2018-12-21 19:36:58 +01:00
|
|
|
services.miniflux = {
|
|
|
|
enable = true;
|
|
|
|
config = {
|
|
|
|
CLEANUP_FREQUENCY = "48";
|
|
|
|
LISTEN_ADDR = "localhost:${toString port}";
|
|
|
|
};
|
2022-01-02 13:00:00 +01:00
|
|
|
adminCredentialsFile = customAdminCredentialsFile;
|
2018-12-21 19:36:58 +01:00
|
|
|
};
|
|
|
|
};
|
2024-02-15 11:29:39 +01:00
|
|
|
|
|
|
|
postgresTcp = { config, pkgs, lib, ... }: {
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
initialScript = pkgs.writeText "init-postgres" ''
|
|
|
|
CREATE USER miniflux WITH PASSWORD '${postgresPassword}';
|
|
|
|
CREATE DATABASE miniflux WITH OWNER miniflux;
|
|
|
|
'';
|
|
|
|
enableTCPIP = true;
|
|
|
|
authentication = ''
|
|
|
|
host sameuser miniflux samenet scram-sha-256
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
systemd.services.postgresql.postStart = lib.mkAfter ''
|
|
|
|
$PSQL -tAd miniflux -c 'CREATE EXTENSION hstore;'
|
|
|
|
'';
|
2024-03-17 11:54:30 +01:00
|
|
|
networking.firewall.allowedTCPPorts = [ config.services.postgresql.settings.port ];
|
2024-02-15 11:29:39 +01:00
|
|
|
};
|
|
|
|
externalDb = { ... }: {
|
|
|
|
security.apparmor.enable = true;
|
|
|
|
services.miniflux = {
|
|
|
|
enable = true;
|
|
|
|
createDatabaseLocally = false;
|
|
|
|
inherit adminCredentialsFile;
|
|
|
|
config = {
|
|
|
|
DATABASE_URL = "user=miniflux host=postgresTcp dbname=miniflux sslmode=disable";
|
|
|
|
PGPASSFILE = "/run/miniflux/pgpass";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
systemd.services.miniflux.preStart = ''
|
|
|
|
cp ${postgresPasswordFile} /run/miniflux/pgpass
|
|
|
|
chmod 600 /run/miniflux/pgpass
|
|
|
|
'';
|
|
|
|
};
|
2018-12-21 19:36:58 +01:00
|
|
|
};
|
|
|
|
testScript = ''
|
2024-02-15 10:12:34 +01:00
|
|
|
def runTest(machine, port, user):
|
|
|
|
machine.wait_for_unit("miniflux.service")
|
|
|
|
machine.wait_for_open_port(port)
|
|
|
|
machine.succeed(f"curl --fail 'http://localhost:{port}/healthcheck' | grep OK")
|
|
|
|
machine.succeed(
|
|
|
|
f"curl 'http://localhost:{port}/v1/me' -u '{user}' -H Content-Type:application/json | grep '\"is_admin\":true'"
|
|
|
|
)
|
|
|
|
machine.fail('journalctl -b --no-pager --grep "^audit: .*apparmor=\\"DENIED\\""')
|
2018-12-21 19:36:58 +01:00
|
|
|
|
2024-02-15 11:29:39 +01:00
|
|
|
default.start()
|
|
|
|
withoutSudo.start()
|
|
|
|
customized.start()
|
|
|
|
postgresTcp.start()
|
2021-01-28 19:09:31 +01:00
|
|
|
|
2024-02-15 10:12:34 +01:00
|
|
|
runTest(default, ${toString defaultPort}, "${defaultUsername}:${defaultPassword}")
|
|
|
|
runTest(withoutSudo, ${toString defaultPort}, "${defaultUsername}:${defaultPassword}")
|
|
|
|
runTest(customized, ${toString port}, "${username}:${password}")
|
2024-02-15 11:29:39 +01:00
|
|
|
|
|
|
|
postgresTcp.wait_for_unit("postgresql.service")
|
|
|
|
externalDb.start()
|
|
|
|
runTest(externalDb, ${toString defaultPort}, "${defaultUsername}:${defaultPassword}")
|
2018-12-21 19:36:58 +01:00
|
|
|
'';
|
|
|
|
})
|