diff options
Diffstat (limited to 'Omni/Deploy')
| -rw-r--r-- | Omni/Deploy/Systemd.hs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Omni/Deploy/Systemd.hs b/Omni/Deploy/Systemd.hs index ee337bb..b47776a 100644 --- a/Omni/Deploy/Systemd.hs +++ b/Omni/Deploy/Systemd.hs @@ -158,16 +158,22 @@ getRunningStorePath serviceName' = do content <- Text.IO.readFile unitPath pure <| extractStorePath content where - -- Extract /nix/store/...-service-name from ExecStart=/nix/store/.../bin/... + -- Extract /nix/store/xxx-name from ExecStart=/nix/store/xxx-name/bin/... extractStorePath content = - content - |> Text.lines - |> find (Text.isPrefixOf "ExecStart=") - |> fmap (Text.drop (Text.length "ExecStart=")) - |> fmap (Text.dropWhile (/= '/')) - |> fmap (Text.drop 1) - |> fmap (Text.takeWhile (/= '/')) - |> fmap ("/nix/store/" <>) + case find (Text.isPrefixOf "ExecStart=") (Text.lines content) of + Nothing -> Nothing + Just line -> + let cmd = Text.drop (Text.length "ExecStart=") line + in extractNixStorePath cmd + + -- Extract store path up to /bin/ or end + extractNixStorePath :: Text -> Maybe Text + extractNixStorePath t + | "/nix/store/" `Text.isPrefixOf` t = + let afterStore = Text.drop 11 t -- drop "/nix/store/" + hashAndName = Text.takeWhile (/= '/') afterStore + in Just ("/nix/store/" <> hashAndName) + | otherwise = Nothing test :: Test.Tree test = |
