Skip to content

Commit 96fbbb7

Browse files
T00fysimplykenny
authored andcommitted
fix(nix): build with the system zstd, add a CLI-only package and CI
Nix now sets ZSTD_SYS_USE_PKG_CONFIG, Battle.net needed a 32-bit FreeType, and Add to Steam saved a store path that garbage collection deletes.
1 parent 2510622 commit 96fbbb7

6 files changed

Lines changed: 76 additions & 10 deletions

File tree

‎.github/workflows/nix.yml‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Nix
2+
3+
# The flake has no lock file, so it builds against whatever nixos-unstable is
4+
# that day: a nixpkgs change can break it on a commit that changed nothing
5+
# here. Weekly, like the glibc ceiling, to catch that ahead of a release, and
6+
# on the commits that change the packaging or the dependencies, where a crate
7+
# that wants a system library breaks it.
8+
on:
9+
schedule:
10+
- cron: "0 5 * * 1"
11+
push:
12+
branches: [main, dev]
13+
paths:
14+
- flake.nix
15+
- packaging/nix/**
16+
- Cargo.lock
17+
- .github/workflows/nix.yml
18+
workflow_dispatch:
19+
20+
jobs:
21+
build:
22+
name: Flake builds on nixos-unstable
23+
runs-on: ubuntu-24.04
24+
steps:
25+
- uses: actions/checkout@v5
26+
27+
- uses: cachix/install-nix-action@v31
28+
29+
- name: Check
30+
run: nix flake check
31+
32+
# Everything but Lightforge itself comes from cache.nixos.org.
33+
- name: Build
34+
run: nix build .#lightforge --print-build-logs

‎INSTALL.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ any ARM machine, tell me how it went, with the output of `lightforge doctor`.
146146
nix run github:LightforgeProject/lightforge
147147
```
148148

149+
For the command line only, without the launcher:
150+
151+
```bash
152+
nix run github:LightforgeProject/lightforge#lightforge-cli
153+
```
154+
149155
The flake starts Lightforge through `steam-run-free`, because Proton needs a
150156
32-bit loader in the standard paths and NixOS has none. Keep
151157
`hardware.graphics.enable32Bit = true;` set for Battle.net's 32-bit graphics.

‎crates/core/src/upgrade/mod.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ pub fn lasting_exe() -> std::io::Result<PathBuf> {
215215
if let Some(appimage) = appimage::running() {
216216
return Ok(appimage);
217217
}
218-
let exe = std::env::current_exe()?;
218+
// Set by the flake's wrapper, which starts this binary through steam-run.
219+
let exe = match std::env::var_os("LIGHTFORGE_WRAPPER") {
220+
Some(wrapper) => PathBuf::from(wrapper),
221+
None => std::env::current_exe()?,
222+
};
219223
if !exe.starts_with(NIX_STORE) {
220224
return Ok(exe);
221225
}

‎flake.nix‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@
1313
overlays.default = final: _prev: {
1414
lightforge-unwrapped = final.callPackage ./packaging/nix/package.nix { };
1515
lightforge = final.callPackage ./packaging/nix/fhs.nix { };
16+
lightforge-cli = final.callPackage ./packaging/nix/fhs.nix {
17+
lightforge-unwrapped = final.lightforge-unwrapped.override { withGui = false; };
18+
};
1619
};
1720

1821
packages = forAllSystems (_: pkgs: rec {
1922
lightforge-unwrapped = pkgs.callPackage ./packaging/nix/package.nix { };
2023
lightforge = pkgs.callPackage ./packaging/nix/fhs.nix { inherit lightforge-unwrapped; };
24+
lightforge-cli = pkgs.callPackage ./packaging/nix/fhs.nix {
25+
lightforge-unwrapped = lightforge-unwrapped.override { withGui = false; };
26+
};
2127
default = lightforge;
2228
});
2329

‎packaging/nix/fhs.nix‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
{
22
symlinkJoin,
33
makeWrapper,
4-
steam-run-free,
4+
steam,
55
lightforge-unwrapped,
66
}:
77

88
# NixOS has no /lib/ld-linux.so.2 with or without hardware.graphics.enable32Bit,
99
# and Proton's binaries need it, so setup would stop at the 32-bit check.
1010
# steam-run-free is steam-run without the unfree Steam package.
11+
let
12+
# Its FreeType is 64-bit only; without a 32-bit one Battle.net has no text.
13+
steam-run-free = (steam.override { extraLibraries = pkgs: [ pkgs.freetype ]; }).run-free;
14+
in
1115
symlinkJoin {
12-
name = "lightforge-${lightforge-unwrapped.version}";
16+
name = "${lightforge-unwrapped.pname}-${lightforge-unwrapped.version}";
1317
paths = [ lightforge-unwrapped ];
1418
nativeBuildInputs = [ makeWrapper ];
1519

1620
postBuild = ''
17-
for bin in lightforge lightforge-gui; do
21+
# Whichever binaries the package built.
22+
for exe in ${lightforge-unwrapped}/bin/*; do
23+
bin=''${exe##*/}
1824
rm $out/bin/$bin
1925
makeWrapper ${steam-run-free}/bin/steam-run $out/bin/$bin \
20-
--add-flags ${lightforge-unwrapped}/bin/$bin
26+
--add-flags ${lightforge-unwrapped}/bin/$bin \
27+
--set LIGHTFORGE_WRAPPER $out/bin/$bin
2128
done
2229
'';
2330

‎packaging/nix/package.nix‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
rustPlatform,
44
pkg-config,
55
udev,
6+
zstd,
67
vulkan-loader,
78
libGL,
89
wayland,
@@ -13,6 +14,8 @@
1314
libxcursor ? xorg.libXcursor,
1415
libxi ? xorg.libXi,
1516
libxrandr ? xorg.libXrandr,
17+
# Off: only the command line, `lightforge`, without the launcher.
18+
withGui ? true,
1619
}:
1720

1821
let
@@ -31,7 +34,7 @@ let
3134
];
3235
in
3336
rustPlatform.buildRustPackage {
34-
pname = "lightforge";
37+
pname = if withGui then "lightforge" else "lightforge-cli";
3538
inherit (cargoToml.workspace.package) version;
3639

3740
src = lib.fileset.toSource {
@@ -52,16 +55,22 @@ rustPlatform.buildRustPackage {
5255

5356
cargoLock.lockFile = ../../Cargo.lock;
5457

58+
cargoBuildFlags = lib.optionals (!withGui) [ "-p" "lightforge-cli" ];
59+
cargoTestFlags = lib.optionals (!withGui) [ "-p" "lightforge-core" "-p" "lightforge-cli" ];
60+
5561
nativeBuildInputs = [ pkg-config ];
56-
buildInputs = [ udev ];
62+
# zstd: Nix's Rust builds set ZSTD_SYS_USE_PKG_CONFIG, so zstd-sys links
63+
# the system library instead of building its bundled copy. udev: for
64+
# gamepads in the launcher.
65+
buildInputs = [ zstd ] ++ lib.optionals withGui [ udev ];
5766

58-
postInstall = ''
67+
postInstall = lib.optionalString withGui ''
5968
install -Dm644 packaging/pro.tuxcore.Lightforge.desktop -t $out/share/applications
6069
install -Dm644 packaging/pro.tuxcore.Lightforge.metainfo.xml -t $out/share/metainfo
6170
cp -r packaging/icons $out/share/icons
6271
'';
6372

64-
postFixup = ''
73+
postFixup = lib.optionalString withGui ''
6574
patchelf --add-rpath ${lib.makeLibraryPath runtimeLibs} $out/bin/lightforge-gui
6675
'';
6776

@@ -71,7 +80,7 @@ rustPlatform.buildRustPackage {
7180
description = "Install, update and play World of Warcraft on Linux, and a home for all your other Battle.net games";
7281
homepage = cargoToml.workspace.package.homepage;
7382
license = lib.licenses.gpl3Plus;
74-
mainProgram = "lightforge-gui";
83+
mainProgram = if withGui then "lightforge-gui" else "lightforge";
7584
platforms = [ "x86_64-linux" ];
7685
};
7786
}

0 commit comments

Comments
 (0)