Skip to content

Commit 572d4ec

Browse files
NixOS support
1 parent 5bceb29 commit 572d4ec

File tree

5 files changed

+171
-4
lines changed

5 files changed

+171
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Title, Separator, OS, Host, Kernel, Uptime, Processes, Packages, Shell, Resoluti
4444

4545
##### Logos
4646
```
47-
Android, Arch, Arco, Artix, CachyOS, CentOS, Debian, Endeavour, Fedora, Garuda, Gentoo, KDE Neon, Linux, Manjaro, Mint, OpenSUSE, OpenSUSE Tumbleweed, OpenSUSE LEAP, Pop!_OS, RebornOS, Ubuntu, Void, Zorin
47+
Android, Arch, Arco, Artix, CachyOS, CentOS, Debian, Endeavour, Fedora, Garuda, Gentoo, KDE Neon, Linux, Manjaro, Mint, NixOS, OpenSUSE, OpenSUSE Tumbleweed, OpenSUSE LEAP, Pop!_OS, RebornOS, Ubuntu, Void, Zorin
4848
```
4949
* Most of the logos have a small variant. Access it by appending _small to the logo name.
5050
* Some logos have an old variant. Access it by appending _old to the logo name.
@@ -53,7 +53,7 @@ Android, Arch, Arco, Artix, CachyOS, CentOS, Debian, Endeavour, Fedora, Garuda,
5353

5454
##### Package managers
5555
```
56-
Pacman, dpkg, rpm, emerge, xbps, Flatpak, Snap
56+
Pacman, dpkg, rpm, emerge, xbps, nix, Flatpak, Snap
5757
```
5858

5959
##### WM themes

src/logo/builtin.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,90 @@ static const FFlogo* getLogoMintOld()
784784
FF_LOGO_RETURN
785785
}
786786

787+
static const FFlogo* getLogoNixOS()
788+
{
789+
FF_LOGO_INIT
790+
FF_LOGO_NAMES("nixos", "nix", "nixos-linux", "nix-linux", "nix-os", "nix_os", "nix_os_linux")
791+
FF_LOGO_LINES(
792+
"$1 ▗▄▄▄ $2▗▄▄▄▄ ▄▄▄▖\n"
793+
"$1 ▜███▙ $2▜███▙ ▟███▛\n"
794+
"$1 ▜███▙ $2▜███▙▟███▛\n"
795+
"$1 ▜███▙ $2▜██████▛\n"
796+
"$1 ▟█████████████████▙ $2▜████▛ $1▟▙\n"
797+
"$1 ▟███████████████████▙ $2▜███▙ $1▟██▙\n"
798+
"$2 ▄▄▄▄▖ ▜███▙ $1▟███▛\n"
799+
"$2 ▟███▛ ▜██▛ $1▟███▛\n"
800+
"$2 ▟███▛ ▜▛ $1▟███▛\n"
801+
"$2▟███████████▛ $1▟██████████▙\n"
802+
"$2▜██████████▛ $1▟███████████▛\n"
803+
"$2 ▟███▛ $1▟▙ ▟███▛\n"
804+
"$2 ▟███▛ $1▟██▙ ▟███▛\n"
805+
"$2 ▟███▛ $1▜███▙ ▝▀▀▀▀\n"
806+
"$2 ▜██▛ $1▜███▙ $2▜██████████████████▛\n"
807+
"$2 ▜▛ $1▟████▙ $2▜████████████████▛\n"
808+
"$1 ▟██████▙ $2▜███▙\n"
809+
"$1 ▟███▛▜███▙ $2▜███▙\n"
810+
"$1 ▟███▛ ▜███▙ $2▜███▙\n"
811+
"$1 ▝▀▀▀ ▀▀▀▀▘ $2▀▀▀▘"
812+
)
813+
FF_LOGO_COLORS(
814+
"34", //blue
815+
"36" //cyan
816+
)
817+
FF_LOGO_RETURN
818+
}
819+
820+
static const FFlogo* getLogoNixOsOld()
821+
{
822+
FF_LOGO_INIT
823+
FF_LOGO_NAMES("nixos_old", "nix-old", "nixos-old", "nix_old", "nix-os-old", "nix_os_old")
824+
FF_LOGO_LINES(
825+
"$1 ::::. $2'::::: ::::'\n"
826+
"$1 '::::: $2':::::. ::::'\n"
827+
"$1 ::::: $2'::::.:::::\n"
828+
"$1 .......:::::..... $2::::::::\n"
829+
"$1 ::::::::::::::::::. $2:::::: $1::::.\n"
830+
" ::::::::::::::::::::: $2:::::. $1.::::'\n"
831+
"$2 ..... ::::' $1:::::'\n"
832+
"$2 ::::: '::' $1:::::'\n"
833+
"$2 ........::::: ' $1:::::::::::.\n"
834+
"$2::::::::::::: $1:::::::::::::\n"
835+
"$2 ::::::::::: $1.. $1:::::\n"
836+
"$2 .::::: $1.::: $1:::::\n"
837+
"$2 .::::: $1::::: $1''''' $2.....\n"
838+
" ::::: $1':::::. $2......:::::::::::::'\n"
839+
" ::: $1::::::. $2':::::::::::::::::'\n"
840+
"$1 .:::::::: $2'::::::::::\n"
841+
"$1 .::::''::::. $2'::::.\n"
842+
"$1 .::::' ::::. $2'::::.\n"
843+
"$1 .:::: :::: $2'::::."
844+
)
845+
FF_LOGO_COLORS(
846+
"34", //blue
847+
"36" //cyan
848+
)
849+
FF_LOGO_RETURN
850+
}
851+
852+
static const FFlogo* getLogoNixOsSmall()
853+
{
854+
FF_LOGO_INIT
855+
FF_LOGO_NAMES("nixos_small", "nix-small", "nixos-small", "nix_small", "nix-os-small", "nix_os_small")
856+
FF_LOGO_LINES(
857+
"$1 \\\\ \\\\ //\n"
858+
" ==\\\\__\\\\/ //\n"
859+
" // \\\\//\n"
860+
"==// //==\n"
861+
" //\\\\___//\n"
862+
"// /\\\\ \\\\==\n"
863+
" // \\\\ \\\\"
864+
)
865+
FF_LOGO_COLORS(
866+
"34" //blue
867+
)
868+
FF_LOGO_RETURN
869+
}
870+
787871
static const FFlogo* getLogoOpenSuse()
788872
{
789873
FF_LOGO_INIT
@@ -1162,6 +1246,9 @@ static GetLogoMethod* getLogos()
11621246
getLogoMint,
11631247
getLogoMintSmall,
11641248
getLogoMintOld,
1249+
getLogoNixOS,
1250+
getLogoNixOsOld,
1251+
getLogoNixOsSmall,
11651252
getLogoOpenSuse,
11661253
getLogoOpenSuseSmall,
11671254
getLogoOpenSuseLeap,

src/modules/packages.c

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,48 @@ static uint32_t countFilesIn(const char* dirname, const char* filename)
136136
return result;
137137
}
138138

139+
static uint32_t getNixPackages(const FFstrbuf* path)
140+
{
141+
FFstrbuf output;
142+
ffStrbufInitA(&output, 128);
143+
144+
ffProcessAppendStdOut(&output, (char* const[]) {
145+
"nix-store",
146+
"-qR",
147+
path->chars,
148+
NULL
149+
});
150+
151+
//Each package is a new line in the output. If at least one line is found, add 1 for the last line.
152+
uint32_t result = ffStrbufCountC(&output, '\n');
153+
if(result > 0)
154+
result++;
155+
156+
ffStrbufDestroy(&output);
157+
return result;
158+
}
159+
160+
static uint32_t getNixPackagesDefault()
161+
{
162+
FFstrbuf path;
163+
ffStrbufInitA(&path, 64);
164+
ffStrbufAppendS(&path, FASTFETCH_TARGET_DIR_ROOT"/nix/var/nix/profiles/default");
165+
uint32_t result = getNixPackages(&path);
166+
ffStrbufDestroy(&path);
167+
return result;
168+
}
169+
170+
static uint32_t getNixPackagesUser(const FFinstance* instance)
171+
{
172+
FFstrbuf path;
173+
ffStrbufInitA(&path, 64);
174+
ffStrbufAppendS(&path, instance->state.passwd->pw_dir);
175+
ffStrbufAppendS(&path, "/.nix-profile");
176+
uint32_t result = getNixPackages(&path);
177+
ffStrbufDestroy(&path);
178+
return result;
179+
}
180+
139181
void ffPrintPackages(FFinstance* instance)
140182
{
141183
uint32_t pacman = getNumElements(FASTFETCH_TARGET_DIR_ROOT"/var/lib/pacman/local", DT_DIR);
@@ -149,14 +191,25 @@ void ffPrintPackages(FFinstance* instance)
149191

150192
uint32_t emerge = countFilesIn(FASTFETCH_TARGET_DIR_ROOT"/var/db/pkg", "SIZE");
151193
uint32_t xbps = getNumElements(FASTFETCH_TARGET_DIR_ROOT"/var/db/xbps", DT_REG);
194+
195+
uint32_t nixUser = 0;
196+
uint32_t nixDefault = 0;
197+
198+
//Nix detection is kinda slow, so we only do it if the nix dir exists
199+
if(ffFileExists(FASTFETCH_TARGET_DIR_ROOT"/nix", S_IFDIR))
200+
{
201+
nixUser = getNixPackagesUser(instance);
202+
nixDefault = getNixPackagesDefault();
203+
}
204+
152205
uint32_t flatpak = getNumElements(FASTFETCH_TARGET_DIR_ROOT"/var/lib/flatpak/app", DT_DIR);
153206
uint32_t snap = getNumElements(FASTFETCH_TARGET_DIR_ROOT"/snap", DT_DIR);
154207

155208
//Accounting for the /snap/bin folder
156209
if(snap > 0)
157210
--snap;
158211

159-
uint32_t all = pacman + dpkg + rpm + emerge + xbps + flatpak + snap;
212+
uint32_t all = pacman + dpkg + rpm + emerge + xbps + nixUser + nixDefault + flatpak + snap;
160213

161214
if(all == 0)
162215
{
@@ -193,7 +246,21 @@ void ffPrintPackages(FFinstance* instance)
193246
FF_PRINT_PACKAGE(dpkg)
194247
FF_PRINT_PACKAGE(rpm)
195248
FF_PRINT_PACKAGE(emerge)
196-
FF_PRINT_PACKAGE(xbps)
249+
250+
if(nixUser > 0)
251+
{
252+
printf("%u (nix-user)", nixUser);
253+
if((all = all - nixUser) > 0)
254+
printf(", ");
255+
}
256+
257+
if(nixDefault > 0)
258+
{
259+
printf("%u (nix-default)", nixDefault);
260+
if((all = all - nixDefault) > 0)
261+
printf(", ");
262+
}
263+
197264
FF_PRINT_PACKAGE(flatpak)
198265
FF_PRINT_PACKAGE(snap)
199266

src/util/FFstrbuf.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,17 @@ bool ffStrbufEndsWithS(const FFstrbuf* strbuf, const char* end)
495495
return true;
496496
}
497497

498+
uint32_t ffStrbufCountC(const FFstrbuf* strbuf, char c)
499+
{
500+
uint32_t result = 0;
501+
for(uint32_t i = 0; i < strbuf->length; i++)
502+
{
503+
if(strbuf->chars[i] == c)
504+
result++;
505+
}
506+
return result;
507+
}
508+
498509
static bool testEndsWithIgnCaseS(const FFstrbuf* strbuf, const char* end, uint32_t* endLength)
499510
{
500511
*endLength = (uint32_t) strlen(end);

src/util/FFstrbuf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ bool ffStrbufStartsWithIgnCaseS(const FFstrbuf* strbuf, const char* start);
8787
bool ffStrbufEndsWithC(const FFstrbuf* strbuf, char c);
8888
bool ffStrbufEndsWithS(const FFstrbuf* strbuf, const char* end);
8989

90+
uint32_t ffStrbufCountC(const FFstrbuf* strbuf, char c);
91+
9092
bool ffStrbufRemoveIgnCaseEndS(FFstrbuf* strbuf, const char* end);
9193

9294
void ffStrbufWriteTo(const FFstrbuf* strbuf, FILE* file);

0 commit comments

Comments
 (0)