2023-06-13 00:44:22 +03:00
|
|
|
{ lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
idmReady = pkgs.writers.writeHaskellBin "idm-nss-ready" {
|
|
|
|
libraries = with pkgs.haskellPackages; [ watchdog ];
|
|
|
|
} ''
|
|
|
|
import Control.Monad.IO.Class
|
|
|
|
import Control.Watchdog
|
2023-10-22 14:09:20 +03:00
|
|
|
import System.IO
|
2023-06-13 00:44:22 +03:00
|
|
|
import System.IO.Error
|
|
|
|
import System.Posix.User
|
|
|
|
|
2023-10-22 14:09:20 +03:00
|
|
|
flushLogger :: WatchdogLogger String
|
|
|
|
flushLogger taskErr delay = do
|
|
|
|
defaultLogger taskErr delay
|
|
|
|
hFlush stdout
|
|
|
|
|
2023-06-13 00:44:22 +03:00
|
|
|
main :: IO ()
|
|
|
|
main = watchdog $ do
|
|
|
|
setInitialDelay 300_000
|
|
|
|
setMaximumDelay 30_000_000
|
2023-10-22 14:09:20 +03:00
|
|
|
setLoggingAction flushLogger
|
2023-06-13 00:44:22 +03:00
|
|
|
watch $ do
|
|
|
|
check <- liftIO $ tryIOError $ getGroupEntryForName "infra_admins"
|
|
|
|
case check of
|
|
|
|
Right _ -> return $ Right ()
|
|
|
|
Left _ -> return $ Left "group not found"
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
systemd.services.idm-nss-ready = {
|
|
|
|
description = "Wait for IDM NSS";
|
2023-10-30 02:40:43 +02:00
|
|
|
requires = [ "kanidm-unixd.service" "nscd.service" "nss-user-lookup.target" ];
|
|
|
|
after = [ "kanidm-unixd.service" "nscd.service" ];
|
2023-06-13 00:44:22 +03:00
|
|
|
before = [ "nss-user-lookup.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = lib.getExe idmReady;
|
|
|
|
DynamicUser = true;
|
|
|
|
TimeoutStartSec = "2m";
|
|
|
|
Type = "oneshot";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|