-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathflake.nix
More file actions
146 lines (137 loc) · 5.84 KB
/
Copy pathflake.nix
File metadata and controls
146 lines (137 loc) · 5.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
composer2nix = {
url = "github:svanderburg/composer2nix";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, composer2nix, ... }@inputs:
flake-utils.lib.eachDefaultSystem (
system:
let
website-name = "ocramius.github.io";
pkgs = (import nixpkgs) {
inherit system;
};
composerEnv = import ./composer-env.nix {
stdenv = pkgs.stdenv;
lib = pkgs.lib;
writeTextFile = pkgs.writeTextFile;
fetchurl = pkgs.fetchurl;
unzip = pkgs.unzip;
php = pkgs.php;
phpPackages = pkgs.phpPackages;
};
with-vendor = import ./php-packages.nix {
inherit composerEnv;
noDev = true;
fetchurl = pkgs.fetchurl;
fetchgit = pkgs.fetchgit;
fetchhg = pkgs.fetchhg;
fetchsvn = pkgs.fetchsvn;
};
with-autoloader = derivation {
name = "with-autoloader";
src = with-vendor;
builder = pkgs.writeShellScript "install-via-composer.sh" ''
set -euxo pipefail
${pkgs.coreutils}/bin/cp -r $src/. $TMPDIR
cd $TMPDIR
${pkgs.coreutils}/bin/chmod -R +w $TMPDIR/vendor/composer
${pkgs.php84Packages.composer}/bin/composer install --no-dev --no-scripts --no-plugins
${pkgs.coreutils}/bin/cp -r $TMPDIR/. $out
'';
inherit system;
};
built-blog-assets = derivation {
name = "built-blog-assets";
src = with-autoloader;
builder = pkgs.writeShellScript "generate-blog-assets.sh" ''
set -euxo pipefail
${pkgs.coreutils}/bin/cp -r $src/. $TMPDIR
cd $TMPDIR
${pkgs.php}/bin/php vendor/bin/sculpin generate --env=prod
${pkgs.coreutils}/bin/cp -r $TMPDIR/output_prod $out
#${pkgs.coreutils}/bin/cp -r ${./presentations/.} $out/presentations
#${pkgs.findutils}/bin/find $out -name ".git" -exec ${pkgs.coreutils}/bin/rm -rf {} \;
'';
inherit system;
};
caddy-module-with-assets = derivation {
name = "caddy-module-with-assets";
builder = pkgs.writeShellScript "generate-blog-assets.sh" ''
set -euxo pipefail
${pkgs.coreutils}/bin/cp -r ${./caddy-embed/.} $out
${pkgs.coreutils}/bin/chmod +w $out/files/
${pkgs.coreutils}/bin/cp -rf ${built-blog-assets}/. $out/files/
'';
inherit system;
};
embedded-server = pkgs.buildGo126Module {
name = "embedded-server";
src = caddy-module-with-assets;
vendorHash = "sha256-v0YXbAaftLLc+e8/w1xghW5OHRjT7Xi87KyLv1siGSc=";
};
in {
packages = {
update-php-packages = pkgs.writeShellScriptBin "generate-composer-to-nix.sh" ''
set -euxo pipefail
TMPDIR="$(${pkgs.coreutils}/bin/mktemp -d)"
mkdir "$TMPDIR/src"
mkdir "$TMPDIR/composer2nix"
${pkgs.coreutils}/bin/cp "${./composer.json}" "$TMPDIR/src/"
${pkgs.coreutils}/bin/cp "${./composer.lock}" "$TMPDIR/src/"
${pkgs.coreutils}/bin/cp -r "${./app}" "$TMPDIR/src/app"
${pkgs.coreutils}/bin/cp -r "${composer2nix}/." "$TMPDIR/composer2nix"
${pkgs.coreutils}/bin/chmod -R +w "$TMPDIR/composer2nix"
${pkgs.php84Packages.composer}/bin/composer install --working-dir="$TMPDIR/composer2nix" --no-scripts --no-plugins
${pkgs.php}/bin/php $TMPDIR/composer2nix/bin/composer2nix --name=${website-name}
${pkgs.coreutils}/bin/rm -f default.nix
'';
built-blog-assets = built-blog-assets;
embedded-server = embedded-server;
runnable-container = pkgs.dockerTools.buildLayeredImage {
name = website-name;
tag = "latest";
contents = [
(pkgs.writeTextDir "Caddyfile" (builtins.readFile ./caddy-embed/Caddyfile))
];
config = {
Cmd = [
"${embedded-server}/bin/caddy-embed"
"run"
];
};
};
publish-to-github-pages = pkgs.writeShellScriptBin "publish-blog.sh" ''
set -euxo pipefail
TMPDIR="$(${pkgs.coreutils}/bin/mktemp -d)"
cd "$TMPDIR"
${pkgs.git}/bin/git clone git@github.com:Ocramius/ocramius.github.com.git .
git checkout master
${pkgs.rsync}/bin/rsync --quiet --archive --filter="P .git*" --exclude=".*.sw*" --exclude=".*.un~" --delete "${built-blog-assets}/" ./
git add -A :/
git commit -a -m "Deploying sculpin-generated pages to \`master\` branch"
git push origin HEAD
'';
};
checks = {
blog-assets-can-be-built = pkgs.stdenv.mkDerivation {
name = "Website blogpost pages are being built";
src = ./.;
doCheck = true;
checkPhase = ''
if [[ -f "${built-blog-assets}/blog/proxy-manager-1-0-0-release/index.html" && -r "${built-blog-assets}/blog/proxy-manager-1-0-0-release/index.html" ]]; then
echo "OK" >> $out;
else
echo "KO" >> $out;
exit 1;
fi
'';
};
};
}
);
}