Skip to content

Commit 27dd097

Browse files
Improved Nix package detection
#195
1 parent c7bf471 commit 27dd097

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/modules/packages.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,17 @@ static uint32_t getNixPackages(char* path)
119119
FFstrbuf output;
120120
ffStrbufInitA(&output, 128);
121121

122+
//https://github.com/LinusDierheimer/fastfetch/issues/195#issuecomment-1191748222
123+
FFstrbuf command;
124+
ffStrbufInitA(&command, 255);
125+
ffStrbufAppendS(&command, "for x in $(nix-store --query --requisites ");
126+
ffStrbufAppendS(&command, path);
127+
ffStrbufAppendS(&command, "); do if [ -d $x ]; then echo $x ; fi ; done | cut -d- -f2- | egrep '([0-9]{1,}\\.)+[0-9]{1,}' | egrep -v '\\-doc$|\\-man$|\\-info$|\\-dev$|\\-bin$|^nixos-system-nixos-' | uniq");
128+
122129
ffProcessAppendStdOut(&output, (char* const[]) {
123-
"nix-store",
124-
"-qR",
125-
path,
130+
"sh",
131+
"-c",
132+
command.chars,
126133
NULL
127134
});
128135

@@ -222,7 +229,7 @@ static void getPackageCounts(const FFinstance* instance, FFstrbuf* baseDir, Pack
222229
ffStrbufSubstrBefore(baseDir, baseDirLength);
223230

224231
//nix default
225-
ffStrbufAppendS(baseDir, "/var/nix/profiles/default");
232+
ffStrbufAppendS(baseDir, "/run/current-system");
226233
packageCounts->nixDefault += getNixPackages(baseDir->chars);
227234
ffStrbufSubstrBefore(baseDir, baseDirLength);
228235

@@ -242,15 +249,20 @@ static void getPackageCounts(const FFinstance* instance, FFstrbuf* baseDir, Pack
242249

243250
static void getPackageCountsBedrock(const FFinstance* instance, FFstrbuf* baseDir, PackageCounts* packageCounts)
244251
{
252+
uint32_t baseDirLength = baseDir->length;
253+
245254
ffStrbufAppendS(baseDir, "/bedrock/strata");
246255

247256
DIR* dir = opendir(baseDir->chars);
248257
if(dir == NULL)
258+
{
259+
ffStrbufSubstrBefore(baseDir, baseDirLength);
260+
getPackageCounts(instance, baseDir, packageCounts);
249261
return;
262+
}
250263

251264
ffStrbufAppendC(baseDir, '/');
252-
253-
uint32_t baseDirLength = baseDir->length;
265+
baseDirLength = baseDir->length;
254266

255267
struct dirent* entry;
256268
while((entry = readdir(dir)) != NULL)

0 commit comments

Comments
 (0)