summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatías Lang <shareman1204@gmail.com>2021-01-28 15:09:31 -0300
committerMatías Lang <shareman1204@gmail.com>2021-01-28 15:09:31 -0300
commitdac07be800a8f76757eee153e0e7424d18c5c08f (patch)
treeb0321b43964cc3f1f96256b7076976dfeb472a3b
parentd5f51d0660ca11ed326b168aaadd54849ce2e469 (diff)
downloadnixpkgs-dac07be800a8f76757eee153e0e7424d18c5c08f.tar
nixpkgs-dac07be800a8f76757eee153e0e7424d18c5c08f.tar.gz
nixpkgs-dac07be800a8f76757eee153e0e7424d18c5c08f.tar.bz2
nixpkgs-dac07be800a8f76757eee153e0e7424d18c5c08f.tar.lz
nixpkgs-dac07be800a8f76757eee153e0e7424d18c5c08f.tar.xz
nixpkgs-dac07be800a8f76757eee153e0e7424d18c5c08f.tar.zst
nixpkgs-dac07be800a8f76757eee153e0e7424d18c5c08f.zip
nixos/miniflux: don't depend on sudo
The miniflux service should work when sudo is not available in the
system.
-rw-r--r--nixos/modules/services/web-apps/miniflux.nix24
-rw-r--r--nixos/tests/miniflux.nix14
2 files changed, 31 insertions, 7 deletions
diff --git a/nixos/modules/services/web-apps/miniflux.nix b/nixos/modules/services/web-apps/miniflux.nix
index 304712d0efc..a2dff4277f0 100644
--- a/nixos/modules/services/web-apps/miniflux.nix
+++ b/nixos/modules/services/web-apps/miniflux.nix
@@ -14,17 +14,16 @@ let
     ADMIN_PASSWORD=password
   '';
 
-  pgsu = "${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser}";
   pgbin = "${config.services.postgresql.package}/bin";
   preStart = pkgs.writeScript "miniflux-pre-start" ''
     #!${pkgs.runtimeShell}
     db_exists() {
-      [ "$(${pgsu} ${pgbin}/psql -Atc "select 1 from pg_database where datname='$1'")" == "1" ]
+      [ "$(${pgbin}/psql -Atc "select 1 from pg_database where datname='$1'")" == "1" ]
     }
     if ! db_exists "${dbName}"; then
-      ${pgsu} ${pgbin}/psql postgres -c "CREATE ROLE ${dbUser} WITH LOGIN NOCREATEDB NOCREATEROLE ENCRYPTED PASSWORD '${dbPassword}'"
-      ${pgsu} ${pgbin}/createdb --owner "${dbUser}" "${dbName}"
-      ${pgsu} ${pgbin}/psql "${dbName}" -c "CREATE EXTENSION IF NOT EXISTS hstore"
+      ${pgbin}/psql postgres -c "CREATE ROLE ${dbUser} WITH LOGIN NOCREATEDB NOCREATEROLE ENCRYPTED PASSWORD '${dbPassword}'"
+      ${pgbin}/createdb --owner "${dbUser}" "${dbName}"
+      ${pgbin}/psql "${dbName}" -c "CREATE EXTENSION IF NOT EXISTS hstore"
     fi
   '';
 in
@@ -73,15 +72,26 @@ in
 
     services.postgresql.enable = true;
 
+    systemd.services.miniflux-dbsetup = {
+      description = "Miniflux database setup";
+      wantedBy = [ "multi-user.target" ];
+      requires = [ "postgresql.service" ];
+      after = [ "network.target" "postgresql.service" ];
+      serviceConfig = {
+        Type = "oneshot";
+        User = config.services.postgresql.superUser;
+        ExecStart = preStart;
+      };
+    };
+
     systemd.services.miniflux = {
       description = "Miniflux service";
       wantedBy = [ "multi-user.target" ];
       requires = [ "postgresql.service" ];
-      after = [ "network.target" "postgresql.service" ];
+      after = [ "network.target" "postgresql.service" "miniflux-dbsetup.service" ];
 
       serviceConfig = {
         ExecStart = "${pkgs.miniflux}/bin/miniflux";
-        ExecStartPre = "+${preStart}";
         DynamicUser = true;
         RuntimeDirectory = "miniflux";
         RuntimeDirectoryMode = "0700";
diff --git a/nixos/tests/miniflux.nix b/nixos/tests/miniflux.nix
index 9f8b52c3c85..797a2787d1a 100644
--- a/nixos/tests/miniflux.nix
+++ b/nixos/tests/miniflux.nix
@@ -20,6 +20,13 @@ with lib;
         services.miniflux.enable = true;
       };
 
+    withoutSudo =
+      { ... }:
+      {
+        services.miniflux.enable = true;
+        security.sudo.enable = false;
+      };
+
     customized =
       { ... }:
       {
@@ -46,6 +53,13 @@ with lib;
         "curl 'http://localhost:${toString defaultPort}/v1/me' -u '${defaultUsername}:${defaultPassword}' -H Content-Type:application/json | grep -q '\"is_admin\":true'"
     )
 
+    withoutSudo.wait_for_unit("miniflux.service")
+    withoutSudo.wait_for_open_port(${toString defaultPort})
+    withoutSudo.succeed("curl --fail 'http://localhost:${toString defaultPort}/healthcheck' | grep -q OK")
+    withoutSudo.succeed(
+        "curl 'http://localhost:${toString defaultPort}/v1/me' -u '${defaultUsername}:${defaultPassword}' -H Content-Type:application/json | grep -q '\"is_admin\":true'"
+    )
+
     customized.wait_for_unit("miniflux.service")
     customized.wait_for_open_port(${toString port})
     customized.succeed("curl --fail 'http://localhost:${toString port}/healthcheck' | grep -q OK")