From 3e98034e55ff7ff5b23e076be85d67fbb223ab34 Mon Sep 17 00:00:00 2001 From: Juan <38849891+xoltia@users.noreply.github.com> Date: Thu, 2 May 2024 09:55:50 -0500 Subject: [PATCH] Packages (Linux): check xdg state home for nix user packages (#844) Check $XDG_STATE_HOME/nix/profile if ~/.nix-profile is not found as addressed in #837. Fix #837 --- src/detection/packages/packages_linux.c | 31 ++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/detection/packages/packages_linux.c b/src/detection/packages/packages_linux.c index 775fb2607..0e19043a4 100644 --- a/src/detection/packages/packages_linux.c +++ b/src/detection/packages/packages_linux.c @@ -502,7 +502,36 @@ void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options) ffStrbufSet(&baseDir, &instance.state.platform.homeDir); if (!(options->disabled & FF_PACKAGES_FLAG_NIX_BIT)) - result->nixUser = getNixPackages(&baseDir, "/.nix-profile"); + { + // check if ~/.nix-profile exists + FF_STRBUF_AUTO_DESTROY profilePath = ffStrbufCreateCopy(&baseDir); + ffStrbufAppendS(&profilePath, ".nix-profile"); + if (ffPathExists(profilePath.chars, FF_PATHTYPE_DIRECTORY)) + { + result->nixUser = getNixPackages(&baseDir, ".nix-profile"); + } + // check if $XDG_STATE_HOME/nix/profile exists + else + { + FF_STRBUF_AUTO_DESTROY stateDir = ffStrbufCreate(); + const char* stateHome = getenv("XDG_STATE_HOME"); + if(ffStrSet(stateHome)) + { + ffStrbufSetS(&stateDir, stateHome); + ffStrbufEnsureEndsWithC(&stateDir, '/'); + } + else + { + ffStrbufSet(&stateDir, &instance.state.platform.homeDir); + ffStrbufAppendS(&stateDir, ".local/state/"); + } + + ffStrbufSet(&profilePath, &stateDir); + ffStrbufAppendS(&profilePath, "nix/profile"); + result->nixUser = getNixPackages(&stateDir, "nix/profile"); + } + } + if (!(options->disabled & FF_PACKAGES_FLAG_FLATPAK_BIT)) result->flatpakUser = getFlatpak(&baseDir, "/.local/share/flatpak"); }