oh-my-posh: add cache clearing on package version changes (#7757)

* add cache clearing for oh-my-posh package changes

Using oh-my-posh creates script files in `~/.cache/oh-my-posh` which include an old derivation path. Once that path is garbage collected, oh-my-posh stops working preventing to successfully create new shells.

```
bash: /nix/store/5ddhz8nsahf1d03smzx2xpmynjspjfh8-oh-my-posh-26.8.0/bin/oh-my-posh: No such file or directory
```

* fix oh-my-posh package reference in cache clear

Use the configured value from programs.oh-my-posh.package as the value of oh-my-posh to compare during cache cleanup.
This commit is contained in:
Evgeny Zislis
2025-09-10 05:15:16 +03:00
committed by GitHub
parent d587e11cef
commit 0c7c71a212

View File

@@ -94,5 +94,21 @@ in
}
'';
};
# Clear oh-my-posh cache when the oh-my-posh package derivation changes
home.activation.ohMyPoshClearCache = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
set -eu
nixver="${config.programs.oh-my-posh.package}"
cache="${config.xdg.cacheHome}/oh-my-posh"
state="$cache/pkg-path"
if [ ! -f "$state" ] || [ "$(cat "$state")" != "$nixver" ]; then
rm -rf "$cache"
fi
mkdir -p "$cache"
printf '%s' "$nixver" > "$state"
'';
};
}