source-engine
source-engine copied to clipboard
Wiki on Building: add Nix entry
The wiki isn't publicly editable, so I will put it here.
You need to put the following Nix expression in a file, say source-engine.nix
{ lib
, pkgs
, stdenv
, fetchFromGitHub
, game ? "hl2"
, python3, pkg-config, wafHook
, SDL2, freetype, fontconfig, zlib, bzip2, libjpeg, libpng, curl, openal, libopus
}:
stdenv.mkDerivation {
pname = "source-engine";
version = "2023-06-03";
nativeBuildInputs = [ python3 pkg-config wafHook ];
buildInputs = [ SDL2 freetype fontconfig zlib bzip2 libjpeg libpng curl openal libopus ];
src = fetchFromGitHub {
owner = "nillerusr";
repo = "source-engine";
rev = "0235b1ed4dcfdab52caaa98b40cfe15da15189c0";
sha256 = "sha256-3RxkUxISXFbO36K/wuqN6t8VfHgEhGruF5qryXNweo4=";
fetchSubmodules = true;
};
# --build-games actually builds a single game it seems
wafConfigureFlags = [ "-8" "-T release" "--disable-warns" "--build-games ${game}" ];
}
You can change the game fron "hl2" to what you need. There is also "--disable-warns" in the flags because I couldn't build the engine without it. Also note that I pinned a commit from 2023-06-03, you might want to update that too.
To build run nix-build -E 'with import <nixpkgs> {}; callPackage ./source-engine.nix {}'
Thanks! By the way, is there a way to run this derivation with a smaller command?
I don't know, this is the best command I could find. There is a newer nix build interface, but it is still experimental so I didn't research into that, and besides Nix documentation is a mess
if you put it into 'default.nix', you can just run nix-build (most projects put it into the repo, creating it yourself is unusual)
EDIT: actually, i think you are supposed to create a default.nix file that calls the other one (source)
EDIT: so the following default.nix appears to work:
let
pkgs = import <nixpkgs> {};
in
{
package = pkgs.callPackage ./package.nix { };
}
however, it seems 64-bit mode has been removed (is it now the default? -4 (32-bit) still exists). also, you require opengl. i wrote this package.nix instead:
{
lib,
pkgs,
stdenv,
fetchFromGitHub,
game ? "portal",
python3, pkg-config, wafHook,
SDL2, freetype, fontconfig, zlib, bzip2, libjpeg, libpng, curl, openal, libopus, libGL
}:
stdenv.mkDerivation {
pname = "source-engine";
version = "1.17";
nativeBuildInputs = [ python3 pkg-config wafHook ];
buildInputs = [ SDL2 freetype fontconfig zlib bzip2 libjpeg libpng curl openal libopus libGL ];
src = fetchFromGitHub {
owner = "nillerusr";
repo = "source-engine";
rev = "29985681a18508e78dc79ad863952f830be237b6";
sha256 = "sha256-KaXNsJoQ1muKsgLeipY6/6dr+GH5FqpCUJPRZWDJh5I=";
fetchSubmodules = true;
};
# --build-games actually builds a single game it seems
#wafConfigureFlags = [ "-8" "-T release" "--disable-warns" "--build-games ${game}" ]; # 64-bit not working?
wafConfigureFlags = [ "-T release" "--disable-warns" "--build-games ${game}" ];
}
EDIT: actually, you require more than just opengl. this is the final edit i hope
8c8,11
< SDL2, freetype, fontconfig, zlib, bzip2, libjpeg, libpng, curl, openal, libopus, libGL
---
> # source requires
> SDL2, freetype, fontconfig, zlib, bzip2, libjpeg, libpng, curl, openal, libopus,
> # togl requires (for linux, not ported to darwin)
> libGL #, xorg.libX11
16c19
< buildInputs = [ SDL2 freetype fontconfig zlib bzip2 libjpeg libpng curl openal libopus libGL ];
---
> buildInputs = [ SDL2 freetype fontconfig zlib bzip2 libjpeg libpng curl openal libopus libGL pkgs.xorg.libX11 ];
30d32
<
Yes you can also do that, put the Nix expression in a file called default.nix and just run nix-build. It's just that nix-build will evaluate the Nix expression in that file, while in my case I directly specified the Nix expression via the -E flag, which avoids the need to create an extra file. But both methods do the same thing.
As for the OpenGL dependency, my experience is that some package specify it explicitly while others don't, so I just left it out. It's probably an implicit dependency of SDL2, but in any case leaving out the libGL dep works too
i thought that it'd be better since the -E flag is an extra one you'd have to remember. also, it literally didn't work without libGL, etc
For me it worked at the time. Since it's 2 years ago I assume some changes were made that require you to make that explicit. Or is it because you're update the Source engine's version ?