Skip to content

Commit

Permalink
chore(nix): add Nix flake
Browse files Browse the repository at this point in the history
  • Loading branch information
yvt committed Jul 2, 2022
1 parent 6844e71 commit ada6a8e
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ OpenSpades.msvc/
# Linux build path
openspades.mk/

# Nix
/outputs
/result

# fltk / fluid output leftovers
Sources/Gui/DetailConfigWindow.txt
Sources/Gui/MainWindow.txt
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ Alternatively, to install the game to a different directory, take the following
After successful installation, optionally you can remove the source code and build outputs to save disk space (~100MB).
#### On Linux (from source, by Nix Flakes)
To build and run OpenSpades from the latest source code:
```bash
nix shell github:yvt/openspades -c openspades
```

To build and run OpenSpades for development:

```bash
git clone https://github.com/yvt/openspades.git && cd openspades
nix develop
# note: this will patch CMake files in the source tree
cmakeBuildType=RelWithDebInfo cmakeConfigurePhase
buildPhase
bin/openspades
```

**note**: Nix Flakes are an experimental feature of Nix and must be enabled manually. See [this wiki article](https://nixos.wiki/wiki/Flakes) for how to do that.

### On Windows (with Visual Studio)
1. Get the required software if you haven't already:
* CMake 2.8+
Expand Down
41 changes: 41 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
description = "A compatible client of Ace of Spades 0.75";

inputs = {
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) stdenv;

# Non-GPL assets - please see `PakLocation.txt` for the terms of use
# and issue #424 for the situation
devPackage = pkgs.fetchurl {
url = https://github.com/yvt/openspades-paks/releases/download/r33/OpenSpadesDevPackage-r33.zip;
sha256 = "CSfcMjoLOroO6NHWjWtUSwD+ZUdA/q1tH6rTeqx3oq0=";
};
# Google Noto Fonts, licensed under the SIL Open Font License
notoFontPak = pkgs.fetchurl {
url = https://github.com/yvt/openspades/releases/download/v0.1.1b/NotoFonts.pak;
sha256 = "VQYMZNYqNBZ9+01YCcabqqIfck/mU/BRcFZKXpBEX00=";
};
in rec {
packages.default = packages.openspades;

packages.openspades = stdenv.mkDerivation rec {
pname = "openspades";
version = "0.1.5-beta";

src = ./.;

nativeBuildInputs = with pkgs; [ cmake imagemagick unzip zip file ];

buildInputs = with pkgs;
([
freetype SDL2 SDL2_image libGL zlib curl glew opusfile openal libogg
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
darwin.apple_sdk.frameworks.Cocoa
]);

cmakeFlags = [ "-DOPENSPADES_INSTALL_BINARY=bin" ];

inherit notoFontPak;

# Used by `downloadpak.sh`. Instructs the script to copy the
# development package from this path instead of downloading it.
OPENSPADES_DEVPAK_PATH = devPackage;

postPatch = ''
patchShebangs Resources
'';

postInstall = ''
cp $notoFontPak $out/share/games/openspades/Resources/
'';

NIX_CFLAGS_LINK = "-lopenal";
};
});
}
25 changes: 8 additions & 17 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
with import <nixpkgs> {};

with pkgs.xorg;

runCommand "dummy" rec {
nativeBuildInputs = [ cmake imagemagick unzip zip file gcc ];

buildInputs = [
freetype SDL2 SDL2_image libGL zlib curl glew opusfile openal libogg pkgconfig libopus libGLU
libXext pkg-config
];

NIX_CFLAGS_LINK = [ "-L${libXext}/lib" ];
NIX_CFLAGS_COMPILE= ["-I${libogg.dev}/include" "-I${libopus.dev}/include" "-I${libGLU.dev}/include" ];

LD_LIBRARY_PATH = [ "${openal}/lib" ];
} ""
# Flake's devShell for non-flake-enabled nix instances
let
compat = builtins.fetchGit {
url = "https://github.com/edolstra/flake-compat.git";
rev = "b4a34015c698c7793d592d66adbab377907a2be8";
};
in
(import compat {src = ./.;}).shellNix.default

0 comments on commit ada6a8e

Please sign in to comment.