Skip to content

Commit 0508792

Browse files
committed
Simplify things.
1 parent 7fe74bd commit 0508792

File tree

1 file changed

+38
-58
lines changed

1 file changed

+38
-58
lines changed

Diff for: flake.nix

+38-58
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@
9393
# Convert sets into lists
9494
composerRequiresMap = map (package: (map (key: builtins.getAttr key package) (builtins.attrNames package))) composerRequiresKeys;
9595
in
96-
# Convert the set into a list, filter out values not starting with "ext-", get rid of the first 4 characters from the name
97-
map (x: builtins.substring 4 (builtins.stringLength x) x) (builtins.filter (x: (builtins.substring 0 4 x) == "ext-") (lib.flatten composerRequiresMap));
96+
# Convert the set into a list, filter out values not starting with "ext-", get rid of the first 4 characters from the name
97+
map (x: builtins.substring 4 (builtins.stringLength x) x) (builtins.filter (x: (builtins.substring 0 4 x) == "ext-") (lib.flatten composerRequiresMap));
9898

9999
requiredExts = getExtensionFromComposerSection "require";
100100
requiredDevExts = getExtensionFromComposerSection "require-dev";
@@ -115,9 +115,9 @@
115115
extensions = { all, ... }: (map (ext: all."${ext}") (builtins.filter (ext: all ? "${ext}") extensions));
116116
});
117117

118-
phpDerivations = rec
118+
phpConfigs = rec
119119
{
120-
default = phpDerivations.php81;
120+
default = phpConfigs.php81;
121121

122122
php56 = {
123123
php = phps.php56;
@@ -163,36 +163,38 @@
163163
};
164164
};
165165

166-
# Build PHP NTS.
167-
phpDerivationsWithNts = phpDerivations // lib.mapAttrs' (name: php:
168-
lib.nameValuePair
169-
(name + "-nts")
170-
(
171-
php // {
172-
flags = {
173-
apxs2Support = false;
174-
ztsSupport = false;
175-
};
176-
}
177-
)
178-
) phpDerivations;
179-
in
180-
{
181-
# In use for "nix shell"
182-
packages = builtins.mapAttrs
166+
# Build PHP NTS configurations.
167+
phpConfigsWithNts = phpConfigs // lib.mapAttrs'
168+
(name: php:
169+
lib.nameValuePair
170+
(name + "-nts")
171+
(
172+
php // {
173+
flags = {
174+
apxs2Support = false;
175+
ztsSupport = false;
176+
};
177+
}
178+
)
179+
)
180+
phpConfigs;
181+
182+
# Build PHP environments (simple + extended)
183+
phpEnvs = builtins.mapAttrs
183184
(name: phpConfig: pkgs.buildEnv {
184185
inherit name;
185186
paths = [
186187
(makePhp {
187188
php = phpConfig.php;
188-
flags = phpConfig.flags or {};
189+
flags = phpConfig.flags or { };
189190
withExtensions = phpConfig.withExtensions;
190-
withoutExtensions = phpConfig.withoutExtensions or [];
191+
withoutExtensions = phpConfig.withoutExtensions or [ ];
191192
})
192193
];
193194
})
194-
phpDerivationsWithNts //
195-
lib.mapAttrs' (name: phpConfig:
195+
phpConfigsWithNts //
196+
lib.mapAttrs'
197+
(name: phpConfig:
196198
let
197199
pname = "env-" + name;
198200
in
@@ -201,49 +203,27 @@
201203
(
202204
makePhpEnv pname (makePhp {
203205
php = phpConfig.php;
204-
flags = phpConfig.flags or {};
206+
flags = phpConfig.flags or { };
205207
withExtensions = phpConfig.withExtensions;
206-
withoutExtensions = phpConfig.withoutExtensions or [];
208+
withoutExtensions = phpConfig.withoutExtensions or [ ];
207209
})
208210
)
209-
) phpDerivationsWithNts;
211+
)
212+
phpConfigsWithNts;
213+
in
214+
{
215+
# In use for "nix shell"
216+
packages = phpEnvs;
210217

211218
# In use for "nix develop"
212219
devShells = builtins.mapAttrs
213-
(name: phpConfig: pkgs.mkShellNoCC {
220+
(name: phpEnv: pkgs.mkShellNoCC {
214221
inherit name;
215222
buildInputs = [
216-
(makePhp {
217-
php = phpConfig.php;
218-
flags = phpConfig.flags or {};
219-
withExtensions = phpConfig.withExtensions ++ requiredDevExts;
220-
withoutExtensions = phpConfig.withoutExtensions or [];
221-
})
223+
phpEnv
222224
];
223225
})
224-
phpDerivationsWithNts //
225-
lib.mapAttrs' (name: phpConfig:
226-
let
227-
phpEnv = makePhpEnv name (makePhp {
228-
php = phpConfig.php;
229-
flags = phpConfig.flags or {};
230-
withExtensions = phpConfig.withExtensions ++ requiredDevExts;
231-
withoutExtensions = phpConfig.withoutExtensions or [];
232-
});
233-
in
234-
let
235-
pname = "env-" + name;
236-
in
237-
lib.nameValuePair
238-
(pname)
239-
(
240-
pkgs.mkShellNoCC {
241-
name = pname;
242-
buildInputs = [ phpEnv ];
243-
}
244-
)
245-
)
246-
phpDerivationsWithNts;
226+
phpEnvs;
247227
}
248228
);
249229
}

0 commit comments

Comments
 (0)