Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changes:
* DF BSD keeps introducing broken packages and breaks fastfetch CI, making it difficult to maintain reliable support. Considering its low usage and the maintenance burden, I have decided to deprecate it.

Features:
* Added `InstallDate` module that detects when the OS was installed and displays the system age. Uses `statx()` birth time of `/etc/machine-id` as the primary probe, with `stat()` mtime and distro-specific installer artifacts as fallbacks. (InstallDate, Linux)
* Added glob and environment variable expansion to logo sources on Windows. `%VAR%`, `$VAR` and `${VAR}` are supported, and a glob matching several files picks one randomly. (#2718, Logo, Windows)
* Added opt-in drive health detection for NVMe disks, via udisks2 on Linux (no root required), NVMe SMART on macOS and the NVMe health log on Windows. (#2726, PhysicalDisk, Linux / macOS / Windows)
* Enable it with `"health": true`. The default output appends `Health <100 - percentage used>%` and any critical warnings.
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ if(LINUX)
src/detection/theme/theme_linux.c
src/detection/top/top_linux.c
src/detection/tpm/tpm_linux.c
src/detection/installdate/installdate_linux.c
src/detection/uptime/uptime_linux.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_linux.c
Expand Down Expand Up @@ -762,6 +763,7 @@ elseif(ANDROID)
src/detection/theme/theme_linux.c
src/detection/top/top_linux.c
src/detection/tpm/tpm_nosupport.c
src/detection/installdate/installdate_linux.c
src/detection/uptime/uptime_linux.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_android.c
Expand Down Expand Up @@ -847,6 +849,7 @@ elseif(FreeBSD)
src/detection/terminalsize/terminalsize_linux.c
src/detection/theme/theme_linux.c
src/detection/tpm/tpm_bsd.c
src/detection/installdate/installdate_nosupport.c
src/detection/uptime/uptime_bsd.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_linux.c
Expand Down Expand Up @@ -945,6 +948,7 @@ elseif(NetBSD)
src/detection/terminalsize/terminalsize_linux.c
src/detection/theme/theme_linux.c
src/detection/tpm/tpm_nosupport.c
src/detection/installdate/installdate_nosupport.c
src/detection/top/top_nbsd.c
src/detection/uptime/uptime_bsd.c
src/detection/users/users_linux.c
Expand Down Expand Up @@ -1033,6 +1037,7 @@ elseif(OpenBSD)
src/detection/terminalsize/terminalsize_linux.c
src/detection/theme/theme_linux.c
src/detection/tpm/tpm_nosupport.c
src/detection/installdate/installdate_nosupport.c
src/detection/top/top_obsd.c
src/detection/uptime/uptime_bsd.c
src/detection/users/users_obsd.c
Expand Down Expand Up @@ -1104,6 +1109,7 @@ elseif(APPLE)
src/detection/theme/theme_apple.c
src/detection/top/top_apple.c
src/detection/tpm/tpm_apple.c
src/detection/installdate/installdate_nosupport.c
src/detection/uptime/uptime_bsd.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_apple.m
Expand Down Expand Up @@ -1205,6 +1211,7 @@ elseif(WIN32)
src/detection/theme/theme_windows.c
src/detection/top/top_windows.c
src/detection/tpm/tpm_windows.c
src/detection/installdate/installdate_nosupport.c
src/detection/uptime/uptime_windows.c
src/detection/users/users_windows.c
src/detection/wallpaper/wallpaper_windows.c
Expand Down Expand Up @@ -1294,6 +1301,7 @@ elseif(SunOS)
src/detection/theme/theme_linux.c
src/detection/top/top_sunos.c
src/detection/tpm/tpm_nosupport.c
src/detection/installdate/installdate_nosupport.c
src/detection/uptime/uptime_sunos.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_linux.c
Expand Down Expand Up @@ -1365,6 +1373,7 @@ elseif(Haiku)
src/detection/theme/theme_nosupport.c
src/detection/top/top_haiku.c
src/detection/tpm/tpm_nosupport.c
src/detection/installdate/installdate_nosupport.c
src/detection/uptime/uptime_haiku.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_haiku.cpp
Expand Down Expand Up @@ -1451,6 +1460,7 @@ elseif(GNU)
src/detection/theme/theme_linux.c
src/detection/top/top_gnu.c
src/detection/tpm/tpm_nosupport.c
src/detection/installdate/installdate_linux.c
src/detection/uptime/uptime_linux.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_linux.c
Expand Down
10 changes: 10 additions & 0 deletions src/detection/installdate/installdate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include "fastfetch.h"

typedef struct FFInstallDateResult {
uint64_t installTime; // milliseconds since epoch
const char* source; // which probe succeeded
} FFInstallDateResult;

const char* ffDetectInstallDate(FFInstallDateResult* result);
90 changes: 90 additions & 0 deletions src/detection/installdate/installdate_linux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include "installdate.h"
#include "common/debug.h"
#include "common/io.h"

#include <sys/stat.h>

#if defined(STATX_BTIME) && !defined(__ANDROID__)
#include <sys/syscall.h>
#endif

/*
* Detection strategy (priority cascade):
*
* 1. statx() birth time of /etc/machine-id
* The most reliable signal: machine-id is generated once at install time
* (by systemd-machine-id-setup or equivalent) and never rewritten.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this works only on systemd distros.

* statx() with STATX_BTIME retrieves the inode birth timestamp, which
* survives file copies and permission changes — unlike mtime or ctime.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

survives file copies

I don't think so. Copying files recreates inodes.

*
* 2. mtime of /etc/machine-id
* Fallback for filesystems that do not support birth time (ext3, old XFS).
* mtime reflects the last write, which for machine-id is typically the
* initial generation at install time.
*
* 3. mtime of /var/log/installer (Debian/Ubuntu) or /root/anaconda-ks.cfg (RHEL/Fedora)
* Installer artifacts left by distro-specific installers. Less universal
* but useful when machine-id has been regenerated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if machine-id has been regenerated, it's still there, and statx(machine-id) still works, so /var/log/installer path never reaches.

*/

#ifdef SYS_statx
static bool tryStatxBtime(const char* path, uint64_t* resultMs, const char** source)
{
struct statx stx;
if (syscall(SYS_statx, 0, path, 0, STATX_BTIME, &stx) == 0

@CarterLi CarterLi Nov 29, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks Android.
On Android, calling unsupported syscall raises SIGSYS, see #1993

&& (stx.stx_mask & STATX_BTIME)
&& stx.stx_btime.tv_sec > 685065600 /* 1991-09-17, birth of Linux */)
{
*resultMs = (uint64_t) stx.stx_btime.tv_sec * 1000 + (uint64_t) stx.stx_btime.tv_nsec / 1000000;
*source = path;
return true;
}
return false;
}
#endif

static bool tryMtime(const char* path, uint64_t* resultMs, const char** source)
{
struct stat st;
if (stat(path, &st) == 0 && st.st_mtime > 685065600)
{
*resultMs = (uint64_t) st.st_mtime * 1000;
*source = path;
return true;
}
return false;
}

const char* ffDetectInstallDate(FFInstallDateResult* result)
{
static const char* candidates[] = {
"/etc/machine-id",
"/var/log/installer",
"/root/anaconda-ks.cfg",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires root

};

// Probe 1: statx birth time (best signal — inode creation timestamp)
#ifdef SYS_statx
for (uint32_t i = 0; i < ARRAY_SIZE(candidates); ++i)
{
if (tryStatxBtime(candidates[i], &result->installTime, &result->source))
{
FF_DEBUG("Install date detected via statx btime of %s", result->source);
return nullptr;
}
}
#endif

// Probe 2: mtime fallback (for filesystems without birth time support)
for (uint32_t i = 0; i < ARRAY_SIZE(candidates); ++i)
{
if (tryMtime(candidates[i], &result->installTime, &result->source))
{
FF_DEBUG("Install date detected via mtime of %s", result->source);
return nullptr;
}
}

FF_DEBUG("Install date: all probes failed");
return "No install date could be determined";
}
5 changes: 5 additions & 0 deletions src/detection/installdate/installdate_nosupport.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "installdate.h"

const char* ffDetectInstallDate([[maybe_unused]] FFInstallDateResult* result) {
return "Not supported on this platform";
}
127 changes: 127 additions & 0 deletions src/modules/installdate/installdate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#include "common/printing.h"
#include "common/jsonconfig.h"
#include "common/time.h"
#include "detection/installdate/installdate.h"
#include "modules/installdate/installdate.h"

bool ffPrintInstallDate(FFInstallDateOptions* options) {
FFInstallDateResult result = {};

const char* error = ffDetectInstallDate(&result);

if (error) {
ffPrintError(FF_MODULE_GET_DISPLAY_NAME(InstallDate), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return false;
}

uint64_t nowMs = ffTimeGetNow();
FFTimeGetAgeResult age = ffTimeGetAge(result.installTime, nowMs);

if (options->moduleArgs.outputFormat.length == 0) {
ffPrintLogoAndKey(FF_MODULE_GET_DISPLAY_NAME(InstallDate), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);

// Default output: "X years, Y days (since YYYY-MM-DD)"
if (age.years > 0) {
printf("%u year%s, %u day%s", age.years, age.years == 1 ? "" : "s", age.daysOfYear, age.daysOfYear == 1 ? "" : "s");
} else {
printf("%u day%s", age.daysOfYear, age.daysOfYear == 1 ? "" : "s");
}
printf(" (since %s)\n", ffTimeToShortStr(result.installTime));
} else {
FF_PRINT_FORMAT_CHECKED(FF_MODULE_GET_DISPLAY_NAME(InstallDate), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
FF_ARG(age.years, "years"),
FF_ARG(age.daysOfYear, "days-of-year"),
FF_ARG(age.yearsFraction, "years-fraction"),
{ FF_ARG_TYPE_STRING, ffTimeToShortStr(result.installTime), "install-date" },
{ FF_ARG_TYPE_STRING, ffTimeToFullStr(result.installTime), "install-date-full" },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ffTimeToShortStr and ffTimeToFullStr share the same static buffer, so in this case they are always the same.

{ FF_ARG_TYPE_STRING, result.source, "source" },
}));
}

return true;
}

void ffParseInstallDateJsonObject(FFInstallDateOptions* options, yyjson_val* module) {
yyjson_val *key, *val;
size_t idx, max;
yyjson_obj_foreach (module, idx, max, key, val) {
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) {
continue;
}

ffPrintError(FF_MODULE_GET_DISPLAY_NAME(InstallDate), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
}
}

[[gnu::cold]]
void ffGenerateInstallDateJsonConfig(FFInstallDateOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}

bool ffGenerateInstallDateJsonResult([[maybe_unused]] FFInstallDateOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
FFInstallDateResult result = {};
const char* error = ffDetectInstallDate(&result);

if (error) {
yyjson_mut_obj_add_str(doc, module, "error", error);
return false;
}

yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_uint(doc, obj, "installTime", result.installTime);
yyjson_mut_obj_add_strcpy(doc, obj, "installDate", ffTimeToFullStr(result.installTime));
yyjson_mut_obj_add_str(doc, obj, "source", result.source);

return true;
}

void ffInitInstallDateOptions(FFInstallDateOptions* options) {
ffOptionInitModuleArg(&options->moduleArgs, "󰃭");
}

void ffDestroyInstallDateOptions(FFInstallDateOptions* options) {
ffOptionDestroyModuleArg(&options->moduleArgs);
}

FFModuleBaseInfo ffInstallDateModuleInfo = {
.name = "InstallDate",
.description = "Print when the operating system was installed and how long ago",
.displayName = {
.en = "Install Date",
.ar = "تاريخ التثبيت",
.cs = "Datum instalace",
.de = "Installationsdatum",
.es = "Fecha de instalación",
.fi = "Asennuspäivä",
.fr = "Date d'installation",
.gl = "Data de instalación",
.he = "תאריך התקנה",
.id = "Tanggal Instalasi",
.it = "Data di installazione",
.ja = "インストール日",
.ko = "설치 날짜",
.pl = "Data instalacji",
.pt = "Data de instalação",
.ru = "Дата установки",
.tr = "Kurulum Tarihi",
.uk = "Дата встановлення",
.vi = "Ngày cài đặt",
.zh_CN = "安装日期",
.zh_TW = "安裝日期",
},
.initOptions = (void*) ffInitInstallDateOptions,
.destroyOptions = (void*) ffDestroyInstallDateOptions,
.parseJsonObject = (void*) ffParseInstallDateJsonObject,
.printModule = (void*) ffPrintInstallDate,
.generateJsonResult = (void*) ffGenerateInstallDateJsonResult,
.generateJsonConfig = (void*) ffGenerateInstallDateJsonConfig,
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
{ "Years since install", "years" },
{ "Days of year since install", "days-of-year" },
{ "Years fraction since install", "years-fraction" },
{ "Install date in short format", "install-date" },
{ "Install date in full format", "install-date-full" },
{ "Detection source path", "source" },
})),
.defaultOrder = 12,
};
9 changes: 9 additions & 0 deletions src/modules/installdate/installdate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "option.h"

bool ffPrintInstallDate(FFInstallDateOptions* options);
void ffInitInstallDateOptions(FFInstallDateOptions* options);
void ffDestroyInstallDateOptions(FFInstallDateOptions* options);

extern FFModuleBaseInfo ffInstallDateModuleInfo;
9 changes: 9 additions & 0 deletions src/modules/installdate/option.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "common/option.h"

typedef struct FFInstallDateOptions {
FFModuleArgs moduleArgs;
} FFInstallDateOptions;

static_assert(sizeof(FFInstallDateOptions) <= FF_OPTION_MAX_SIZE, "FFInstallDateOptions size exceeds maximum allowed size");
3 changes: 3 additions & 0 deletions src/modules/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ static FFModuleBaseInfo* I[] = {
#endif
#if !FF_MODULE_DISABLE_INITSYSTEM
&ffInitSystemModuleInfo,
#endif
#if !FF_MODULE_DISABLE_INSTALLDATE
&ffInstallDateModuleInfo,
#endif
nullptr,
};
Expand Down
1 change: 1 addition & 0 deletions src/modules/modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "modules/host/host.h"
#include "modules/icons/icons.h"
#include "modules/initsystem/initsystem.h"
#include "modules/installdate/installdate.h"
#include "modules/kernel/kernel.h"
#include "modules/keyboard/keyboard.h"
#include "modules/lm/lm.h"
Expand Down