From 520cf4e47ef47efec3f1ba2341ab0f7af68cd477 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 28 Oct 2026 22:06:29 +0100 Subject: [PATCH] flakelight module --- flake.nix | 5 ++++ nix/flakelight-module.nix | 60 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 nix/flakelight-module.nix diff --git a/flake.nix b/flake.nix index ce4e3f7..150dbf6 100644 --- a/flake.nix +++ b/flake.nix @@ -123,6 +123,11 @@ }; }; + imports = [flakelight.flakelightModules.extendFlakelight]; + flakelightModule = {lib, ...}: { + imports = [./nix/flakelight-module.nix]; + }; + devShells.default = {pkgs, ...}: { packages = with pkgs; [nix-update]; }; diff --git a/nix/flakelight-module.nix b/nix/flakelight-module.nix new file mode 100644 index 0000000..844b9b0 --- /dev/null +++ b/nix/flakelight-module.nix @@ -0,0 +1,60 @@ +# Copyright (C) 2026 Robin Appelman +# 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)) + ]; + } + ]; + }