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