From 2a730c54fb06baff31fd56848175adae890b6b26 Mon Sep 17 00:00:00 2001 From: barsoosayque <33784900+barsoosayque@users.noreply.github.com> Date: Thu, 24 Aug 2023 16:46:28 +0000 Subject: [PATCH] add support for nix flake (#2117) --- .envrc | 4 +++ .gitignore | 7 ++++- doc/SUMMARY.md | 1 + doc/installation.md | 3 +- doc/installation_nix.md | 31 +++++++++++++++++++++ flake.lock | 61 +++++++++++++++++++++++++++++++++++++++++ flake.nix | 52 +++++++++++++++++++++++++++++++++++ 7 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 .envrc create mode 100644 doc/installation_nix.md create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000000..5e9005b714 --- /dev/null +++ b/.envrc @@ -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 diff --git a/.gitignore b/.gitignore index 9ac437e956..c59d20f186 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ .DS_Store desktop.ini __pycache__ -.direnv # generated on build gfx/*/tile_config.json @@ -14,4 +13,10 @@ book # Krita *.png-autosave.kra *.kra +*.kra~ *.png~ + +# Direnv & Nix +.direnv +result +.local diff --git a/doc/SUMMARY.md b/doc/SUMMARY.md index 65a29abf93..ccc4422fcd 100644 --- a/doc/SUMMARY.md +++ b/doc/SUMMARY.md @@ -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) diff --git a/doc/installation.md b/doc/installation.md index 4ac54dffe9..fff2fd1735 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -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 /compose.py gfx/UltimateCataclysm +$ python3 tools/compose.py gfx/UltimateCataclysm ``` diff --git a/doc/installation_nix.md b/doc/installation_nix.md new file mode 100644 index 0000000000..7c377bf18d --- /dev/null +++ b/doc/installation_nix.md @@ -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. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..adc650ea5b --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1692463654, + "narHash": "sha256-F8hZmsQINI+S6UROM4jyxAMbQLtzE44pI8Nk6NtMdao=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ca3c9ac9f4cdd4bea19f592b32bb59b74ab7d783", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..e16716b3cc --- /dev/null +++ b/flake.nix @@ -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; + }; + }); +}