Repository: flox/flox

Issue #1937: Support for services in nested activations
Created: 2024-08-14T11:16:56Z
Summary
We shouldn't:

break services in outer activations when inner activations are started/exited
warn about services already running when activating a different environment

Both of these issues appear to stem from us re-using an incorrect socket path for the inner activation.
Reproduction
Start an outer activation with services, works as expected:
(2) ~/projects/flox/flox on HEAD (56b0c943) [$]
% flox activate --start-services -d env-one
✅ You are now using the environment 'env-one'.
To stop using this environment, type 'exit'

flox [env-one dcarley/shell (remote)] 
(3) ~/projects/flox/flox on HEAD (56b0c943) [$]
% flox services status
NAME       STATUS            PID
one        Running         13124

flox [env-one dcarley/shell (remote)] 
(3) ~/projects/flox/flox on HEAD (56b0c943) [$]
% pstree -ws process-compose
-+= 00001 root (launchd)
 \-+= 13119 dcarley /nix/store/j5dp1ha8v91iayzjxw87fm3wzmrqzhky-process-compose-1.9.0/bin/process-compose up -f /Users/dcarley/projects/flox/flox/env-one/.flox/run/aarch64-darwin.env-one/service-config.yaml -u /Users/dcarley/.cache/flox/run/flox.5db402c4.sock -L /var/folders/8q/spckhr654cv4xrcv0fxsrlvc0000gn/T/nix-shell.rrPesn/tmp.s4MNJ4oTOt --tui=false
   |--= 13123 dcarley /nix/store/h0fgpyxfav7ybnw5sdg8jpyv9f95x4w0-coreutils-9.3/bin/sleep infinity
   \--= 13124 dcarley sleep infinity
Start an inner activation with services, works as expected except for the warning about skipping services:
flox [env-one dcarley/shell (remote)] 
(3) ~/projects/flox/flox on HEAD (56b0c943) [$]
% flox activate --start-services -d env-two
⚠️  Skipped starting services, services are already running
✅ You are now using the environment 'env-two'.
To stop using this environment, type 'exit'

flox [env-two env-one dcarley/shell (remote)] 
(4) ~/projects/flox/flox on HEAD (56b0c943) [$]
% flox services status
NAME       STATUS            PID
two        Running         13298

flox [env-two env-one dcarley/shell (remote)] 
(4) ~/projects/flox/flox on HEAD (56b0c943) [$]
% pstree -ws process-compose               
-+= 00001 root (launchd)
 |-+= 13119 dcarley /nix/store/j5dp1ha8v91iayzjxw87fm3wzmrqzhky-process-compose-1.9.0/bin/process-compose up -f /Users/dcarley/projects/flox/flox/env-one/.flox/run/aarch64-darwin.env-one/service-config.yaml -u /Users/dcarley/.cache/flox/run/flox.5db402c4.sock -L /var/folders/8q/spckhr654cv4xrcv0fxsrlvc0000gn/T/nix-shell.rrPesn/tmp.s4MNJ4oTOt --tui=false
 | |--= 13123 dcarley /nix/store/h0fgpyxfav7ybnw5sdg8jpyv9f95x4w0-coreutils-9.3/bin/sleep infinity
 | \--= 13124 dcarley sleep infinity
 \-+= 13293 dcarley /nix/store/j5dp1ha8v91iayzjxw87fm3wzmrqzhky-process-compose-1.9.0/bin/process-compose up -f /Users/dcarley/projects/flox/flox/env-two/.flox/run/aarch64-darwin.env-two/service-config.yaml -u /Users/dcarley/.cache/flox/run/flox.5db402c4.sock -L /var/folders/8q/spckhr654cv4xrcv0fxsrlvc0000gn/T/nix-shell.rrPesn/tmp.wewmcl6PGk --tui=false
   |--= 13298 dcarley sleep infinity
   \--= 13299 dcarley /nix/store/h0fgpyxfav7ybnw5sdg8jpyv9f95x4w0-coreutils-9.3/bin/sleep infinity
Exiting the inner activation breaks services for the outer activation:
flox [env-two env-one dcarley/shell (remote)] 
(4) ~/projects/flox/flox on HEAD (56b0c943) [$]
% exit
flox [env-one dcarley/shell (remote)] 
(3) ~/projects/flox/flox on HEAD (56b0c943) [$] took 7s
% flox services status                     
❌ ERROR: couldn't connect to service manager
flox [env-one dcarley/shell (remote)] 
(3) ~/projects/flox/flox on HEAD (56b0c943) [$]
1 % pstree -ws process-compose               
-+= 00001 root (launchd)
 \-+= 13119 dcarley /nix/store/j5dp1ha8v91iayzjxw87fm3wzmrqzhky-process-compose-1.9.0/bin/process-compose up -f /Users/dcarley/projects/flox/flox/env-one/.flox/run/aarch64-darwin.env-one/service-config.yaml -u /Users/dcarley/.cache/flox/run/flox.5db402c4.sock -L /var/folders/8q/spckhr654cv4xrcv0fxsrlvc0000gn/T/nix-shell.rrPesn/tmp.s4MNJ4oTOt --tui=false
   |--= 13123 dcarley /nix/store/h0fgpyxfav7ybnw5sdg8jpyv9f95x4w0-coreutils-9.3/bin/sleep infinity
   \--= 13124 dcarley sleep infinity
Exiting the outer activation leaves one instance of process-compose:
flox [env-one dcarley/shell (remote)] 
(3) ~/projects/flox/flox on HEAD (56b0c943) [$]
% exit

(2) ~/projects/flox/flox on HEAD (56b0c943) [$] took 22s
% pstree -ws process-compose               
-+= 00001 root (launchd)
 \-+= 13119 dcarley /nix/store/j5dp1ha8v91iayzjxw87fm3wzmrqzhky-process-compose-1.9.0/bin/process-compose up -f /Users/dcarley/projects/flox/flox/env-one/.flox/run/aarch64-darwin.env-one/service-config.yaml -u /Users/dcarley/.cache/flox/run/flox.5db402c4.sock -L /var/folders/8q/spckhr654cv4xrcv0fxsrlvc0000gn/T/nix-shell.rrPesn/tmp.s4MNJ4oTOt --tui=false
   |--= 13123 dcarley /nix/store/h0fgpyxfav7ybnw5sdg8jpyv9f95x4w0-coreutils-9.3/bin/sleep infinity
   \--= 13124 dcarley sleep infinity

Duplicate issue #1975: issues with layered activation with services 
Created: 2024-08-21T13:06:47Z
There is a bug/unimplemented enhancement with service management when trying to layer multiple environment with services. Here are a few findings:
STR:
Issue 1: a prompt that doesn't work & the inability to see the status of first services

have two environments (env1, env2) in two different directories, both with services defined
flox activate -s in env1
flox activate -s in env2
run flox services status

Expected: two services
Actual: an interactive prompt asking which environment to get services (neat!)

pick the first environment in the list

Expected: env1 status
Actual: env2 status (no matter what, we seem to only allow you to operate on the last service started)
Issue 2: exit kills everything

Now exit the outermost env (env2)
run flox services status

Expected: env1 status
Actual: ❌ ERROR: couldn't connect to service manager.
Note: process compose from env1 is now orphaned and doesn't get cleaned up by watchdog
thank you to @barstoolbluz for finding!

Closing comment (2024-08-21T13:26:54Z): This looks like a duplicate of:

#1937