diff options
| author | Seth Flynn <[email protected]> | 2025-03-05 15:27:26 -0500 |
|---|---|---|
| committer | Seth Flynn <[email protected]> | 2025-03-05 15:31:38 -0500 |
| commit | 6fa4458f59160cdf9e82ad2138300b1041f510ad (patch) | |
| tree | 88aeb808a13eadeacf0bc9b97d85c93f10de7a2d /module.nix | |
| parent | b229a37e59b9720b7017e72a6d159b869ff36458 (diff) | |
treewide: use flake
Signed-off-by: Seth Flynn <[email protected]>
Diffstat (limited to 'module.nix')
| -rw-r--r-- | module.nix | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/module.nix b/module.nix new file mode 100644 index 0000000..d828c97 --- /dev/null +++ b/module.nix @@ -0,0 +1,131 @@ +{ + config, + lib, + inputs, + ... +}: + +let + cfg = config.lwjgl; + + lwjglVersionSubmodule = + { name, ... }: + { + freeformType = lib.types.attrsOf lib.types.anything; + + options = { + version = lib.mkOption { + type = lib.types.str; + default = name; + defaultText = lib.literalExpression "config.name"; + description = "Version of LWJGL3 these arguments are for."; + }; + + hash = lib.mkOption { + type = lib.types.str; + description = "Hash of the LWJGL3 source tarball."; + }; + + antHash = lib.mkOption { + type = lib.types.str; + description = "Hash of the LWJGL3 ant dependencies."; + }; + }; + }; + + lwjglSubmodule = { + options = { + targets = lib.mkOption { + type = lib.types.listOf lib.types.str; + description = "A list of target triples to cross compile LWJGL3 for."; + }; + + versions = lib.mkOption { + type = lib.types.attrsOf (lib.types.submodule lwjglVersionSubmodule); + default = { }; + description = "An attribute set of LWJGL3 versions and hashes."; + }; + }; + }; +in + +{ + options.lwjgl = lib.mkOption { + type = lib.types.submodule lwjglSubmodule; + default = { }; + description = "Configuration for the LWJGL3 project."; + }; + + config = { + perSystem = + { + pkgs, + system, + self', + ... + }: + + let + nativeTarget = pkgs.stdenv.hostPlatform.config; + + fetchAntDeps = pkgs.callPackage ./pkgs/fetch-ant-deps.nix { }; + + # Loop over each target + forAllTargets = lib.genAttrs cfg.targets; + + # Nixpkgs re-instantiated to cross compile from our current system to each target + crossPkgsFor = forAllTargets ( + target: + + if target == nativeTarget then + pkgs + else + import inputs.nixpkgs { + inherit system; + inherit (pkgs) config overlays; + crossSystem = { + config = target; + }; + } + ); + + # Our package set for each target + ourPackagesFor = forAllTargets ( + target: + + let + lwjgls = lib.mapAttrs' ( + version: args: + + lib.nameValuePair "${target}-lwjgl-${version}" ( + crossPkgsFor.${target}.callPackage ./pkgs/lwjgl ({ inherit fetchAntDeps version; } // args) + ) + ) cfg.versions; + + versions = lib.naturalSort (lib.attrNames lwjgls); + in + + { + # Use latest version by default + lwjgl = lwjgls.${lib.elemAt versions (lib.length versions - 1)}; + } + // lwjgls + ); + in + + { + packages = lib.mergeAttrsList ( + (lib.attrValues ourPackagesFor) + ++ [ + { + lwjgl = + ourPackagesFor.${nativeTarget}.lwjgl + or (lib.trace "${nativeTarget} is not a supported target" pkgs.emptyFile); + + default = self'.packages.lwjgl; + } + ] + ); + }; + }; +} |
