Skip to content

Commit

Permalink
add support for nix flake (I-am-Erk#2117)
Browse files Browse the repository at this point in the history
  • Loading branch information
barsoosayque authored Aug 24, 2023
1 parent 2564064 commit 2a730c5
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.1.1; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.1.1/direnvrc" "sha256-b6qJ4r34rbE23yWjMqbmu3ia2z4b2wIlZUksBke/ol0="
fi
use flake
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.DS_Store
desktop.ini
__pycache__
.direnv
# generated on build
gfx/*/tile_config.json

Expand All @@ -14,4 +13,10 @@ book
# Krita
*.png-autosave.kra
*.kra
*.kra~
*.png~

# Direnv & Nix
.direnv
result
.local
1 change: 1 addition & 0 deletions doc/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [Installation & Building](installation.md)
- [Windows guide](installation_windows.md)
- [Nix](installation_nix.md)
- [Style guidelines](style/summary.md)
- [General](style/general.md)
- [Items](style/items.md)
Expand Down
3 changes: 1 addition & 2 deletions doc/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ You will need:
- Python 3
- [Libvips](https://libvips.github.io/libvips/install.html)
- pyvips (install it via python pip: `pip install pyvips`)
- [compose.py](https://github.com/CleverRaven/Cataclysm-DDA/blob/master/tools/gfx_tools/compose.py) script from the main [Cataclysm-DDA](https://github.com/CleverRaven/Cataclysm-DDA) repository

Once you have everything ready, you can build the tileset:
```sh
# Assuming that you are in the root of the tileset repository
$ python3 <path-to-compose-py-script>/compose.py gfx/UltimateCataclysm
$ python3 tools/compose.py gfx/UltimateCataclysm
```
31 changes: 31 additions & 0 deletions doc/installation_nix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Nix Installation

Documentation of developing tileset with [Nix](https://nixos.org/).

## Build

As this repository uses flakes, it's possible to build any of the tileset (not only UlitCa) using `nix build .#{name}` command. For example:

```sh
# This will build UltiCa
nix build .#UltimateCataclysm

# But this will build Mushroom Dream
nix build .#Mushroom-Dream
```

And the result will be in *result* directory, ready to put into the game. If you want to link the result to the different directory, use `--out-link {path}` argument.

## Devshell

Tileset flake also provide a simple devshell with python and vips to run tools such as `compose.py` or `generate_preview.py`.

```sh
# Enter the devshell
nix develop .

# This now works
python3 tools/compose.py --use-all gfx/UltimateCataclysm out
```

Or if you have [direnv](https://direnv.net/) enabled, it will automatically enter the devshell upon opening the repository.
61 changes: 61 additions & 0 deletions flake.lock

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

52 changes: 52 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
utils = {
url = "github:numtide/flake-utils";
};
};

outputs = { self, nixpkgs, utils }:
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };

requires = with pkgs; [
(python311.withPackages(ps: [ ps.pyvips ]))
vips
];
in
rec {
# `nix build`
packages = (pkgs.lib.mapAttrs' (name: _:
pkgs.lib.nameValuePair name (pkgs.stdenv.mkDerivation {
inherit name;
version = "master";
src = ./gfx/${name};
buildInputs = requires;

dontCheck = true;
dontPatch = true;
dontConfigure = true;

buildPhase = ''
python3 ${./tools/compose.py} --use-all --feedback CONCISE . compiled
'';
installPhase = ''
mkdir -p $out
cp compiled/* $out
for file in [ "fallback.png" "layering.json" "tileset.txt" ]; do
[ -f "$file" ] && cp "$file" $out ||:
done
'';
})
) (builtins.readDir ./gfx));

# `nix develop`
devShell = pkgs.mkShell rec {
nativeBuildInputs = requires;
};
});
}

0 comments on commit 2a730c5

Please sign in to comment.