Skip to content

Instantly share code, notes, and snippets.

@shackra
Created February 27, 2024 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shackra/3f88f5fcbf35e5be197c2019265fce7d to your computer and use it in GitHub Desktop.
Save shackra/3f88f5fcbf35e5be197c2019265fce7d to your computer and use it in GitHub Desktop.
Integrate flake.nix into your Godot Engine projects, with pre-commit-hooks!
# This flake was initially generated by fh, the CLI for FlakeHub (version 0.1.9)
{
# A helpful description of your flake
description = "Editor depedencies for development";
# Flake inputs
inputs = {
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
flake-schemas.url =
"https://flakehub.com/f/DeterminateSystems/flake-schemas/*.tar.gz";
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz";
};
# Flake outputs that other flakes can use
outputs = { self, flake-schemas, nixpkgs, pre-commit-hooks }:
let
# Helpers for producing system-specific outputs
supportedSystems =
[ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" "aarch64-linux" ];
forEachSupportedSystem = f:
nixpkgs.lib.genAttrs supportedSystems (system:
f {
pkgs = import nixpkgs { inherit system; };
inherit system;
});
in
{
# Schemas tell Nix about the structure of your flake's outputs
schemas = flake-schemas.schemas;
checks = forEachSupportedSystem ({ system, ... }: {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
nixpkgs-fmt.enable = true;
shellcheck.enable = true;
gdlint = {
enable = true;
name = "gdtoolkit lint (for Godot Script source code)";
entry = "make lint"; # NOTE: I have a Makefile target called lint, change this to meet your needs
language = "system";
pass_filenames = false;
files = "\\.(gd|tscn|tres)$";
};
};
};
});
# Development environments
devShells = forEachSupportedSystem ({ pkgs, system }: {
default = pkgs.mkShell {
# Pinned packages available in the environment
packages = with pkgs; [
jq
nixpkgs-fmt
scons
python311
python311Packages.pip
python311Packages.setuptools
python311Packages.virtualenvwrapper
];
shellHook = self.checks.${system}.pre-commit-check.shellHook + ''
VENV=.venv
if test ! -d $VENV; then
virtualenv $VENV
fi
source ./$VENV/bin/activate
export PYTHONPATH=`pwd`/$VENV/${pkgs.python311.sitePackages}:$PYTHONPATH
if ! pip show gdtoolkit &> /dev/null; then
pip install gdtoolkit
fi
'';
};
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment