Skip to content

Commit 8c32f5f

Browse files
committed
nix: build with Mold linker on x86_64-linux
Signed-off-by: NotAShelf <[email protected]> Change-Id: I771c36297577aba189058a2183ec2b4a6a6a6964
1 parent 3ad14a9 commit 8c32f5f

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ on your system: it is pretty _[fast](#benchmarks)_...
4343
- Fast
4444
- Really fast
4545
- Minimal dependencies
46-
- Tiny binary (~370kb)
46+
- Tiny binary (~370kb [^1])
4747
- Actually really fast
4848
- Cool NixOS logo (other, inferior, distros are not supported)
4949
- Reliable detection of following info:
@@ -60,6 +60,9 @@ on your system: it is pretty _[fast](#benchmarks)_...
6060
- Did I mention fast?
6161
- Respects [`NO_COLOR` spec](https://no-color.org/)
6262

63+
[^1]: With the Mold linker, which is enabled by default in the Flake package,
64+
the binary size is roughly 350kb. That's nearly 20kb reduction in size :)
65+
6366
## Motivation
6467

6568
Fastfetch, as its name probably hinted, is a very fast fetch tool written in C.

flake.nix

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
forEachSystem = nixpkgs.lib.genAttrs systems;
1111
pkgsForEach = nixpkgs.legacyPackages;
1212
in {
13-
packages = forEachSystem (system: {
13+
packages = forEachSystem (system: let
14+
pkgs = pkgsForEach.${system};
15+
in {
1416
default = self.packages.${system}.microfetch;
15-
microfetch = pkgsForEach.${system}.callPackage ./nix/package.nix {};
17+
microfetch = pkgs.callPackage ./nix/package.nix {};
18+
microfetch-mold = pkgs.callPackage ./nix/package.nix {useMold = true;};
1619
});
1720

1821
devShells = forEachSystem (system: {

nix/package.nix

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
{
22
lib,
3-
rustPlatform,
3+
stdenv,
44
stdenvAdapters,
5+
rustPlatform,
56
llvm,
7+
useMold ? stdenv.isLinux && !stdenv.hostPlatform.isAarch,
68
}: let
79
toml = (lib.importTOML ../Cargo.toml).package;
810
pname = toml.name;
911
inherit (toml) version;
12+
13+
# Select stdenv based on useMold flag
14+
stdenv =
15+
if useMold
16+
then stdenvAdapters.useMoldLinker llvm.stdenv
17+
else llvm.stdenv;
1018
in
11-
rustPlatform.buildRustPackage.override {stdenv = stdenvAdapters.useMoldLinker llvm.stdenv;} {
19+
rustPlatform.buildRustPackage.override {inherit stdenv;} {
1220
inherit pname version;
1321
src = let
1422
fs = lib.fileset;
@@ -26,7 +34,14 @@ in
2634

2735
cargoLock.lockFile = ../Cargo.lock;
2836
enableParallelBuilding = true;
29-
env.RUSTFLAGS = "-C link-arg=-fuse-ld=mold";
37+
buildNoDefaultFeatures = true;
38+
doCheck = false;
39+
40+
# Only set RUSTFLAGS for mold if useMold is enabled
41+
env = lib.optionalAttrs useMold {
42+
CARGO_LINKER = "clang";
43+
RUSTFLAGS = "-C link-arg=-fuse-ld=mold";
44+
};
3045

3146
meta = {
3247
description = "Microscopic fetch script in Rust, for NixOS systems";

0 commit comments

Comments
 (0)