Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Describe nix dev environment using nix flakes #20

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ engine_manager
temp
docs/build
include/UI.h
src/resources.c
result
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ STD ?= c17
GTK = gtk+-3.0
RSVG = librsvg-2.0
GIO = gio-unix-2.0 gio-2.0
PKGCONF = $(shell which pkg-config)
PKGCONF ?= $(shell which pkg-config)
CFLAGS += -Wall -Wextra -Wpedantic -Wno-overlength-strings -std=$(STD) -O3 `$(PKGCONF) --cflags $(GTK) $(RSVG) $(GIO)`
LDFLAGS += `$(PKGCONF) --libs $(GTK) $(RSVG) $(GIO)` -lm

Expand Down Expand Up @@ -38,7 +38,10 @@ UI = $(DATADIR)/window.glade $(DATADIR)/selected.css

all: prepare engine_manager $(OBJECTS)
$(CC) $(CFLAGS) -rdynamic -o GTKChess $(OBJECTS) $(LDFLAGS)
gio set -t string GTKChess metadata::custom-icon file://$(PWD)/data/textures/classic/WKnight.svg
# FIXME: `nix build` fails with error:
# gio: Setting attribute metadata::custom-icon not supported
#
# gio set -t string GTKChess metadata::custom-icon file://$(PWD)/src/textures/classic/WKnight.svg

engine_manager: $(OBJDIR)/engine_manager.o
$(CC) $(CFLAGS) -o engine_manager $< $(LDFLAGS) -pthread
Expand Down Expand Up @@ -85,4 +88,4 @@ docs: $(DOCDIR)/source

read: docs
xdg-open $(DOCDIR)/build/html/index.html &> /dev/null


27 changes: 27 additions & 0 deletions flake.lock

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

62 changes: 62 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
description = "A nix flake for GTK-Chess, UCI chess engine GUI written in C.";
nixConfig = {
extra-experimental-features = [ "nix-command" "flakes" ];
extra-substituters = [ "https://cache.zw3rk.com" ];
extra-trusted-public-keys = [ "loony-tools:pr9m4BkM/5/eSTZlkQyRt57Jz7OMBxNSUiMC4FkcNfk=" ];

bash-prompt = "\\[\\e[0m\\][\\[\\e[0;2m\\]nix-develop \\[\\e[0;1m\\]gtk-chess@\\[\\033[33m\\]$(git rev-parse --abbrev-ref HEAD) \\[\\e[0;32m\\]\\w\\[\\e[0m\\]]\\[\\e[0m\\]$ \\[\\e[0m\\]";
};

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=22.11";
};

outputs = { self, nixpkgs }:
let
supportedSystems = [ "x86_64-linux" "x86_64-darwin" ];
perSystem = nixpkgs.lib.genAttrs supportedSystems;
allNixpkgs = perSystem (system: import nixpkgs { inherit system; });
nixpkgsFor = system: allNixpkgs.${system};

nativeBuildInputs = perSystem (system:
with nixpkgsFor system; [ clang gnumake pkg-config which libxml2 ]
);

buildInputs = perSystem (system:
with nixpkgsFor system; [ gtk3 librsvg glib ]
);

inputsCombined = perSystem (system:
nativeBuildInputs.${system} ++ buildInputs.${system}
);
in
{
defaultPackage = perSystem (system: self.packages.${system}.gtkChess);

packages = perSystem (system:
with nixpkgsFor system; {
gtkChess = stdenv.mkDerivation {
name = "GTK-Chess";
version = "dev";
src = ./.;
nativeBuildInputs = nativeBuildInputs.${system};
buildInputs = buildInputs.${system};
buildPhase = "make all";
installPhase = "mkdir -p $out/bin; cp GTKChess $out/bin";
};
}
);

devShells = perSystem (system: {
default =
with nixpkgsFor system; mkShell {
buildInputs = [ cppcheck ] ++ inputsCombined.${system};
};
});

formatter = perSystem (system:
nixpkgs.legacyPackages.${system}.nixpkgs-fmt
);
};
}