Skip to content

Commit 4642e27

Browse files
committed
caddy: move withPlugins function into a dedicated file
1 parent 930ee4a commit 4642e27

File tree

2 files changed

+82
-69
lines changed

2 files changed

+82
-69
lines changed

pkgs/by-name/ca/caddy/package.nix

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{ lib
22
, buildGoModule
3+
, callPackage
34
, fetchFromGitHub
45
, nixosTests
56
, caddy
@@ -74,75 +75,7 @@ buildGoModule {
7475
package = caddy;
7576
};
7677
};
77-
withPlugins =
78-
{ plugins
79-
, hash ? lib.fakeHash
80-
}: caddy.overrideAttrs (finalAttrs: prevAttrs:
81-
let
82-
pluginsSorted = builtins.sort builtins.lessThan plugins;
83-
pluginsList = lib.concatMapStrings (plugin: "${plugin}-") pluginsSorted;
84-
pluginsHash = builtins.hashString "md5" pluginsList;
85-
pluginsWithoutVersion = builtins.filter (p: !lib.hasInfix "@" p) pluginsSorted;
86-
in
87-
assert lib.assertMsg (builtins.length pluginsWithoutVersion == 0)
88-
"All plugins should have a version (eg ${builtins.elemAt pluginsWithoutVersion 0}@x.y.z)!";
89-
{
90-
vendorHash = null;
91-
subPackages = [ "." ];
92-
93-
src = stdenv.mkDerivation {
94-
pname = "caddy-src-with-plugins-${pluginsHash}";
95-
version = finalAttrs.version;
96-
97-
nativeBuildInputs = [
98-
go
99-
xcaddy
100-
cacert
101-
git
102-
];
103-
dontUnpack = true;
104-
buildPhase =
105-
let
106-
withArgs = lib.concatMapStrings (plugin: "--with ${plugin} ") pluginsSorted;
107-
in
108-
''
109-
export GOCACHE=$TMPDIR/go-cache
110-
export GOPATH="$TMPDIR/go"
111-
XCADDY_SKIP_BUILD=1 TMPDIR="$PWD" xcaddy build v${finalAttrs.version} ${withArgs}
112-
(cd buildenv* && go mod vendor)
113-
'';
114-
installPhase = ''
115-
mv buildenv* $out
116-
'';
117-
118-
outputHashMode = "recursive";
119-
outputHash = hash;
120-
outputHashAlgo = "sha256";
121-
};
122-
123-
124-
doInstallCheck = true;
125-
installCheckPhase = ''
126-
runHook preInstallCheck
127-
128-
${lib.toShellVar "notfound" pluginsSorted}
129-
while read kind module version; do
130-
[[ "$kind" = "dep" ]] || continue
131-
module="''${module}@''${version}"
132-
for i in "''${!notfound[@]}"; do
133-
if [[ ''${notfound[i]} = ''${module} ]]; then
134-
unset 'notfound[i]'
135-
fi
136-
done
137-
done < <($out/bin/caddy build-info)
138-
if (( ''${#notfound[@]} )); then
139-
>&2 echo "Plugins not found: ''${notfound[@]}"
140-
exit 1
141-
fi
142-
143-
runHook postInstallCheck
144-
'';
145-
});
78+
withPlugins = callPackage ./plugins.nix { inherit caddy; };
14679
};
14780

14881
meta = with lib; {

pkgs/by-name/ca/caddy/plugins.nix

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
lib,
3+
stdenv,
4+
go,
5+
xcaddy,
6+
cacert,
7+
git,
8+
caddy,
9+
}:
10+
{
11+
plugins,
12+
hash ? lib.fakeHash,
13+
}:
14+
let
15+
pluginsSorted = builtins.sort builtins.lessThan plugins;
16+
pluginsList = lib.concatMapStrings (plugin: "${plugin}-") pluginsSorted;
17+
pluginsHash = builtins.hashString "md5" pluginsList;
18+
pluginsWithoutVersion = builtins.filter (p: !lib.hasInfix "@" p) pluginsSorted;
19+
in
20+
assert lib.assertMsg (
21+
builtins.length pluginsWithoutVersion == 0
22+
) "All plugins should have a version (eg ${builtins.elemAt pluginsWithoutVersion 0}@x.y.z)!";
23+
caddy.overrideAttrs (
24+
finalAttrs: prevAttrs: {
25+
vendorHash = null;
26+
subPackages = [ "." ];
27+
28+
src = stdenv.mkDerivation {
29+
pname = "caddy-src-with-plugins-${pluginsHash}";
30+
version = finalAttrs.version;
31+
32+
nativeBuildInputs = [
33+
go
34+
xcaddy
35+
cacert
36+
git
37+
];
38+
dontUnpack = true;
39+
buildPhase =
40+
let
41+
withArgs = lib.concatMapStrings (plugin: "--with ${plugin} ") pluginsSorted;
42+
in
43+
''
44+
export GOCACHE=$TMPDIR/go-cache
45+
export GOPATH="$TMPDIR/go"
46+
XCADDY_SKIP_BUILD=1 TMPDIR="$PWD" xcaddy build v${finalAttrs.version} ${withArgs}
47+
(cd buildenv* && go mod vendor)
48+
'';
49+
installPhase = ''
50+
mv buildenv* $out
51+
'';
52+
53+
outputHashMode = "recursive";
54+
outputHash = hash;
55+
outputHashAlgo = "sha256";
56+
};
57+
58+
doInstallCheck = true;
59+
installCheckPhase = ''
60+
runHook preInstallCheck
61+
62+
${lib.toShellVar "notfound" pluginsSorted}
63+
while read kind module version; do
64+
[[ "$kind" = "dep" ]] || continue
65+
module="''${module}@''${version}"
66+
for i in "''${!notfound[@]}"; do
67+
if [[ ''${notfound[i]} = ''${module} ]]; then
68+
unset 'notfound[i]'
69+
fi
70+
done
71+
done < <($out/bin/caddy build-info)
72+
if (( ''${#notfound[@]} )); then
73+
>&2 echo "Plugins not found: ''${notfound[@]}"
74+
exit 1
75+
fi
76+
77+
runHook postInstallCheck
78+
'';
79+
}
80+
)

0 commit comments

Comments
 (0)