flakelight module

This commit is contained in:
Robin Appelman 2026-10-28 22:06:29 +01:00
commit 520cf4e47e
Signed by: robin
SSH key fingerprint: SHA256:kifqgrqnut7q1YUIrI0AdMNC23qiKAS/T9uGFmIYvbE
2 changed files with 65 additions and 0 deletions

View file

@ -123,6 +123,11 @@
};
};
imports = [flakelight.flakelightModules.extendFlakelight];
flakelightModule = {lib, ...}: {
imports = [./nix/flakelight-module.nix];
};
devShells.default = {pkgs, ...}: {
packages = with pkgs; [nix-update];
};

60
nix/flakelight-module.nix Normal file
View file

@ -0,0 +1,60 @@
# Copyright (C) 2026 Robin Appelman <robin@icewind.nl>
# SPDX-License-Identifier: MIT
{
lib,
src,
config,
flakelight,
...
}: let
inherit (lib) mkMerge mkOption warnIf types filterAttrs readDir hasSuffix attrNames genAttrs mapAttrs removeSuffix map attrValues;
inherit (flakelight.types) function;
includes = pkgs: (config.includes pkgs.sourcepawn.includes) ++ [pkgs.sourcepawn.includes.sourcemod];
pluginsFileNames = attrNames (filterAttrs (name: ty: ty == "regular" && hasSuffix ".sp" name) (readDir config.pluginDir));
pluginNames = map (removeSuffix ".sp") pluginsFileNames;
in
warnIf (! builtins ? readFileType) "Unsupported Nix version in use."
{
options = {
includes = mkOption {
type = function;
default = _: [];
description = "sourcepawn includes to use";
};
pluginDir = mkOption {
type = with types; path;
default = src + "/plugin";
description = "directory containing the plugin sources";
};
};
config = mkMerge [
{
withOverlays = [
(import ./overlay.nix)
];
packages = let
pluginPackages = genAttrs pluginNames (name: pkgs:
pkgs.buildSourcePawnScript {
inherit name;
outPath = "${name}.smx";
src = config.pluginDir + "/${name}.sp";
});
in
pluginPackages
// {
default = pkgs:
pkgs.symlinkJoin {
name = "plugins";
paths = attrValues (mapAttrs (_: plugin: plugin pkgs) pluginPackages);
};
};
devShells.default.packages = pkgs: [
(pkgs.sourcepawn.buildEnv (includes pkgs))
];
}
];
}