1/*
2 This file defines all OpenRA packages under `openraPackages`,
3 e.g. the OpenRA release engine can be found at `openraPackages.engines.release` (see `engines.nix`),
4 or the out-of-tree mod "Combined Arms" can be found at `openraPackages.mods.ca` (see `mods.nix`).
5 The `openra` package is just an alias to `openraPackages.engines.release`,
6 and just provides the mods included in the source code of the engine.
7 Additional engines or mods can be added with `openraPackages.buildOpenRAEngine` (function around `engine.nix`)
8 and `openraPackages.buildOpenRAMod` (function around `mod.nix`), respectively.
9*/
10{ pkgs, lib }:
11
12let
13 /*
14 Building an engine or out-of-tree mod is very similar,
15 but different enough not to be able to build them with the same package definition,
16 so instead we define what is common between them in a separate file.
17
18 Although `callPackage` could be used, it would require undoing `makeOverridable`,
19 because `common.nix` does not define a package, but just an attribute set,
20 which is directly passed as part of the argument to the engines and mods `callPackage`,
21 so either the attributes added by `makeOverridable` have to be removed
22 or the engine and mod package definitions will need to add `...` to the argument list.
23 */
24 common =
25 let
26 f = import ./common.nix;
27 fArgs = lib.functionArgs f;
28 in
29 f (
30 builtins.intersectAttrs fArgs pkgs
31 // {
32 lua = pkgs.lua5_1;
33 }
34 );
35
36 /*
37 Building a set of engines or mods requires some dependencies as well,
38 so the sets will actually be defined as a function instead,
39 requiring the dependencies and returning the actual set.
40
41 Not all dependencies for defining a engine or mod set are shared,
42 so additional arguments can be passed as well.
43
44 The builders for engines and mods allow to delay specifying the name,
45 by returning a function that expects a name, which we use, in this case,
46 to base the name on the attribute name instead, preventing the need to specify the name twice
47 if the attribute name and engine/mod name are equal.
48 */
49 callWithName = name: value: if lib.isFunction value then value name else value;
50 buildOpenRASet =
51 f: args:
52 pkgs.recurseIntoAttrs (
53 lib.mapAttrs callWithName (
54 f (
55 {
56 inherit (pkgs) fetchFromGitHub;
57 postFetch = ''
58 sed -i 's/curl/curl --insecure/g' $out/thirdparty/{fetch-thirdparty-deps,noget}.sh
59 $out/thirdparty/fetch-thirdparty-deps.sh
60 '';
61 }
62 // args
63 )
64 )
65 );
66
67in
68pkgs.recurseIntoAttrs rec {
69 # The whole attribute set is destructered to ensure those (and only those) attributes are given
70 # and to provide defaults for those that are optional.
71 buildOpenRAEngine =
72 {
73 name ? null,
74 version,
75 description,
76 homepage,
77 mods,
78 src,
79 }@engine:
80 # Allow specifying the name at a later point if no name has been given.
81 let
82 builder =
83 name:
84 pkgs.callPackage ./engine.nix (
85 common
86 // {
87 engine = engine // {
88 inherit name;
89 };
90 }
91 );
92 in
93 if name == null then builder else builder name;
94
95 # See `buildOpenRAEngine`.
96 buildOpenRAMod =
97 {
98 name ? null,
99 version,
100 title,
101 description,
102 homepage,
103 src,
104 engine,
105 assetsError ? "",
106 }@mod:
107 (
108 {
109 version,
110 mods ? [ ],
111 src,
112 }@engine:
113 let
114 builder =
115 name:
116 pkgs.callPackage ./mod.nix (
117 common
118 // {
119 mod = mod // {
120 inherit name assetsError;
121 };
122 engine = engine // {
123 inherit mods;
124 };
125 }
126 );
127 in
128 if name == null then builder else builder name
129 )
130 engine;
131
132 # See `buildOpenRASet`.
133 engines = buildOpenRASet (import ./engines.nix) { inherit buildOpenRAEngine; };
134 mods = buildOpenRASet (import ./mods.nix) { inherit buildOpenRAMod; };
135}