@@ -172,6 +172,102 @@ describe("getMinimalServicePathParts - Linux user directories", () => {
172172 } ) ;
173173} ) ;
174174
175+ describe ( "getMinimalServicePathParts - Nix Home Manager" , ( ) => {
176+ it ( "falls back to default Nix profile when NIX_PROFILES is absent on Linux" , ( ) => {
177+ const result = getMinimalServicePathParts ( {
178+ platform : "linux" ,
179+ home : "/home/testuser" ,
180+ } ) ;
181+
182+ expect ( result ) . toContain ( "/home/testuser/.nix-profile/bin" ) ;
183+ } ) ;
184+
185+ it ( "falls back to default Nix profile when NIX_PROFILES is absent on macOS" , ( ) => {
186+ const result = getMinimalServicePathParts ( {
187+ platform : "darwin" ,
188+ home : "/Users/testuser" ,
189+ } ) ;
190+
191+ expect ( result ) . toContain ( "/Users/testuser/.nix-profile/bin" ) ;
192+ } ) ;
193+
194+ it ( "places rightmost NIX_PROFILES entry before leftmost on Linux" , ( ) => {
195+ const result = getMinimalServicePathPartsFromEnv ( {
196+ platform : "linux" ,
197+ env : {
198+ HOME : "/home/testuser" ,
199+ NIX_PROFILES : "/nix/var/nix/profiles/default /home/testuser/.nix-profile" ,
200+ } ,
201+ } ) ;
202+
203+ const userIdx = result . indexOf ( "/home/testuser/.nix-profile/bin" ) ;
204+ const defaultIdx = result . indexOf ( "/nix/var/nix/profiles/default/bin" ) ;
205+ expect ( userIdx ) . toBeGreaterThan ( - 1 ) ;
206+ expect ( defaultIdx ) . toBeGreaterThan ( - 1 ) ;
207+ expect ( userIdx ) . toBeLessThan ( defaultIdx ) ;
208+ } ) ;
209+
210+ it ( "places rightmost NIX_PROFILES entry before leftmost on macOS" , ( ) => {
211+ const result = getMinimalServicePathPartsFromEnv ( {
212+ platform : "darwin" ,
213+ env : {
214+ HOME : "/Users/testuser" ,
215+ NIX_PROFILES : "/nix/var/nix/profiles/default /Users/testuser/.nix-profile" ,
216+ } ,
217+ } ) ;
218+
219+ const userIdx = result . indexOf ( "/Users/testuser/.nix-profile/bin" ) ;
220+ const defaultIdx = result . indexOf ( "/nix/var/nix/profiles/default/bin" ) ;
221+ expect ( userIdx ) . toBeGreaterThan ( - 1 ) ;
222+ expect ( defaultIdx ) . toBeGreaterThan ( - 1 ) ;
223+ expect ( userIdx ) . toBeLessThan ( defaultIdx ) ;
224+ } ) ;
225+
226+ it ( "includes single Nix profile from NIX_PROFILES on Linux" , ( ) => {
227+ const result = getMinimalServicePathPartsFromEnv ( {
228+ platform : "linux" ,
229+ env : {
230+ HOME : "/home/testuser" ,
231+ NIX_PROFILES : "/nix/var/nix/profiles/per-user/testuser/profile" ,
232+ } ,
233+ } ) ;
234+
235+ expect ( result ) . toContain ( "/nix/var/nix/profiles/per-user/testuser/profile/bin" ) ;
236+ } ) ;
237+
238+ it ( "includes single Nix profile from NIX_PROFILES on macOS" , ( ) => {
239+ const result = getMinimalServicePathPartsFromEnv ( {
240+ platform : "darwin" ,
241+ env : {
242+ HOME : "/Users/testuser" ,
243+ NIX_PROFILES : "/nix/var/nix/profiles/per-user/testuser/profile" ,
244+ } ,
245+ } ) ;
246+
247+ expect ( result ) . toContain ( "/nix/var/nix/profiles/per-user/testuser/profile/bin" ) ;
248+ } ) ;
249+
250+ it ( "preserves Nix precedence across three profiles" , ( ) => {
251+ const result = getMinimalServicePathPartsFromEnv ( {
252+ platform : "linux" ,
253+ env : {
254+ HOME : "/home/testuser" ,
255+ NIX_PROFILES :
256+ "/nix/var/nix/profiles/default /nix/var/nix/profiles/per-user/testuser/custom /home/testuser/.nix-profile" ,
257+ } ,
258+ } ) ;
259+
260+ const userIdx = result . indexOf ( "/home/testuser/.nix-profile/bin" ) ;
261+ const customIdx = result . indexOf ( "/nix/var/nix/profiles/per-user/testuser/custom/bin" ) ;
262+ const defaultIdx = result . indexOf ( "/nix/var/nix/profiles/default/bin" ) ;
263+ expect ( userIdx ) . toBeGreaterThan ( - 1 ) ;
264+ expect ( customIdx ) . toBeGreaterThan ( - 1 ) ;
265+ expect ( defaultIdx ) . toBeGreaterThan ( - 1 ) ;
266+ expect ( userIdx ) . toBeLessThan ( customIdx ) ;
267+ expect ( customIdx ) . toBeLessThan ( defaultIdx ) ;
268+ } ) ;
269+ } ) ;
270+
175271describe ( "buildMinimalServicePath" , ( ) => {
176272 const splitPath = ( value : string , platform : NodeJS . Platform ) =>
177273 value . split ( platform === "win32" ? path . win32 . delimiter : path . posix . delimiter ) ;
0 commit comments