summaryrefslogtreecommitdiff
path: root/Omni/Deploy/Systemd.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bensima.com>2025-12-25 19:35:47 -0500
committerBen Sima <ben@bensima.com>2025-12-25 19:35:47 -0500
commit5e9cb8c4983f6cdd05568029e9c233202d01c9bf (patch)
tree3fd60f6efe728d7258e7b358e4ea1c52ac6b176e /Omni/Deploy/Systemd.hs
parente7c740be5fd5a4d9c505e451e6c12c7e03ec6e11 (diff)
Omni/Deploy/Systemd: fix extractStorePath parsing bug
The function was incorrectly extracting store paths from ExecStart lines. For "ExecStart=/nix/store/xxx/bin/ava" it would return "/nix/store/nix" instead of "/nix/store/xxx". This caused the deployer to think services needed redeployment on every cycle, restarting them every 5 minutes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'Omni/Deploy/Systemd.hs')
-rw-r--r--Omni/Deploy/Systemd.hs24
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 =