-
Notifications
You must be signed in to change notification settings - Fork 69
Avoid having to run lorri watch
yourself
#2
Comments
We had planned a feature like this, but hadn’t found a good design yet. Your snippet above might come in handy, thanks! |
What was the rationale behind having a |
Running a single daemon for the whole system could also be a good alternative. Then client instances kicked off by direnv could just communicate with the daemon, which would have control over potentially long running builds. |
For me the biggest drawback of my approach is that I have no clue what builds might be happening unless I check something like |
lorri uses the native filesystem watchers (via the We want to re-build on changes in the background, so we need a push-based mechanism. Plus, I don’t know how well |
@BrianHicks wrote:
|
An alternative on nixos so you don't have to do manual pid tracking is simply to use a systemd user unit and start it like this:
And the corresponding unit: # /nix/store/nym436n8j68pj32ryn0sn5vcj8jnam6d-unit-lorri-.service/[email protected]
[Unit]
ConditionPathExists=%I
ConditionUser=!@system
Description=Lorri Watch
[Service]
Environment="LOCALE_ARCHIVE=/nix/store/k1mlzmf7czx6xpizqwnj4fyd62c65qlw-glibc-locales-2.27/lib/locale/locale-archive"
Environment="PATH=/run/wrappers/bin:%h/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/nix/store/6w3670wdhf83b9xj0wnyq4s9yz7gfvr6-libnotify-0.7.7/bin:/nix/store/d9s1kq1bnwqgxwcvv4zrc36ysnxg8gv7-coreutils-8.30/bin:/nix/store/krhqmaqal0gklh15rs2bwrqzz8mg9lrn-findutils-4.6.0/bin:/nix/store/wnjv27b3j6jfdl0968xpcymlc7chpqil-gnugrep-3.3/bin:/nix/store/x1khw8x0465xhkv6w31af75syyyxc65j-gnused-4.7/bin:/nix/store/rl4ky8x58ixnfjssliygq7iwyd30l3gn-systemd-239.20190219/bin:/run/wrappers/sbin:%h/.nix-profile/sbin:/nix/var/nix/profiles/default/sbin:/run/current-system/sw/sbin:/nix/store/6w3670wdhf83b9xj0wnyq4s9yz7gfvr6-libnotify-0.7.7/sbin:/nix/store/d9s1kq1bnwqgxwcvv4zrc36ysnxg8gv7-coreutils-8.30/sbin:/nix/store/krhqmaqal0gklh15rs2bwrqzz8mg9lrn-findutils-4.6.0/sbin:/nix/store/wnjv27b3j6jfdl0968xpcymlc7chpqil-gnugrep-3.3/sbin:/nix/store/x1khw8x0465xhkv6w31af75syyyxc65j-gnused-4.7/sbin:/nix/store/rl4ky8x58ixnfjssliygq7iwyd30l3gn-systemd-239.20190219/sbin"
Environment="TZ=Asia/Singapore"
Environment="TZDIR=/nix/store/izrzziiaa27bf9rbdb8hy867vxfjfzbi-tzdata-2018g/share/zoneinfo"
ExecStart=%h/.nix-profile/bin/lorri watch
PrivateTmp=true
ProtectSystem=full
Restart=on-failure
WorkingDirectory=%I |
I am a If I check https://direnv.net/, I guess it is actually |
@gotcha exactly. For reference i'm using home-manager for it with this: home.file.".direnvrc".text = ''
use_nix() {
eval "$(lorri direnv)"
found=false
for lpid in $(pgrep -xf "lorri watch"); do
lpwd="$(readlink -e "/proc/$lpid/cwd")"
self="$(readlink -e "/proc/$$/cwd")"
if [[ "$lpwd" == "$self" ]]; then
found=true
fi
done
if [[ "$found" == "false" ]]; then
lorri watch 2>/dev/null 1>/dev/null &
pid=$!
echo "started lorri watch with pid $pid"
disown $pid
fi
}
''; |
Just in case that wasn't clear, home.file.".direnvrc".text = ''
use_nix() {
eval "$(lorri direnv)"
systemctl --user start lorri@$(systemd-escape $(pwd))
}
''; And if you then wanted to kill all the lorri watchers at one go: systemctl --user stop lorri.slice You then don't have to hunt for them. |
For those of us living without the blessings of use_nix() {
eval "$(lorri direnv)"
target="$(lsof -p "$$" | grep cwd | awk '{ print $9 }')"
for pid in $(ps -o pid,command | grep 'lorri watch' | grep -v 'grep' | awk '{ print $1 }'); do
if lsof -p "$pid" | grep cwd | grep -q "$target"; then
echo "using existing lorri watch with pid $pid"
return 0;
fi
done
# existing lorri watch wasn't found
lorri watch 2>/dev/null 1>/dev/null &
lorri_pid=$!
disown $lorri_pid
echo "started lorri watch with pid $lorri_pid"
} (n.b. terrible hacks with the |
@BrianHicks assuming |
Tracking issue for this is #96 |
I’ll close this, since we have |
So, lorri is amazing, but immediately after trying it, i found it lacking in one regard: I jump between projects a lot, and would have to remember to run
lorri watch
.So instead i wrote this little
.direnvrc
:I'm sure this could be written in a better way, but that's the quickest pure-shell version i could come up with right now.
I'd just like to have this functionality in lorri :)
The text was updated successfully, but these errors were encountered: