-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
104 lines (99 loc) · 3.36 KB
/
flake.nix
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
{
description = "rooter";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
utils,
nixpkgs,
...
} @ inputs:
utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
rooterVersion = (builtins.readFile ./VERSION);
# @todo adapt PHP version if required
php = pkgs.php82.buildEnv {
extensions = { all, enabled }: with all; enabled;
extraConfig = ''
memory_limit=-1
'';
};
phpDev = pkgs.php82.buildEnv {
extensions = { all, enabled }: with all; enabled ++ [ xdebug ];
extraConfig = ''
memory_limit=-1
xdebug.mode=debug
'';
};
envConfig = ''
export ROOTER_TRAEFIK_BIN=${pkgs.traefik}/bin/traefik
export ROOTER_DNSMASQ_BIN=${pkgs.dnsmasq}/bin/dnsmasq
export ROOTER_GZIP_BIN=${pkgs.gzip}/bin/gzip
export ROOTER_PV_BIN=${pkgs.pv}/bin/pv
'';
in rec {
packages.php = php;
packages.traefik = pkgs.traefik;
packages.dnsmasq = pkgs.dnsmasq;
packages.pv = pkgs.pv;
packages.gzip = pkgs.gzip;
packages.rooter =
let
inherit (pkgs) stdenv lib;
rooterPhar = builtins.fetchurl {
url = "https://github.com/run-as-root/rooter/releases/download/${rooterVersion}/rooter.phar";
sha256 = "1dyp5gviprj4p7p2pfxvqkj3xnaxlj9ppcbnvbyy2zdmdd7jb6v1";
};
in
pkgs.writeScriptBin "rooter" ''
#!${pkgs.stdenv.shell}
export ROOTER_APP_MODE=production
export ROOTER_VERSION=${rooterVersion}
${envConfig}
${php}/bin/php ${rooterPhar} "$@"
'';
packages.rooterDev =
let
inherit (pkgs) stdenv lib;
PROJECT_ROOT = builtins.getEnv "PWD";
in
pkgs.writeShellScriptBin "rooterDev" ''
export ROOTER_APP_MODE=develop
export ROOTER_VERSION="develop@${rooterVersion}"
${envConfig}
${phpDev}/bin/php ${PROJECT_ROOT}/rooter.php "$@"
'';
packages.rooterDevPhar =
let
inherit (pkgs) stdenv lib;
box = builtins.fetchurl {
url = "https://github.com/box-project/box/releases/download/4.3.8/box.phar";
sha256 = "061vrxjvmqxy4yyi6j6i28kwl6ixfwhc743b6lw7bjgc4kdkvml3";
};
rooterPharLocal = pkgs.stdenv.mkDerivation {
name = "rooterPharBin";
src = self;
buildPhase = "
${pkgs.php82Packages.composer}/bin/composer install
${phpDev}/bin/php ${box} compile --composer-bin=${pkgs.php82Packages.composer}/bin/composer
";
installPhase = ''
mkdir -p $out/bin;
install -t $out/bin build/output/rooter.phar;
'';
};
in
pkgs.writeShellScriptBin "rooterDevPhar" ''
export ROOTER_APP_MODE=develop
export ROOTER_VERSION="develop-phar@${rooterVersion}"
${envConfig}
${phpDev}/bin/php ${rooterPharLocal}/bin/rooter.phar "$@"
'';
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [phpDev traefik dnsmasq pv gzip just packages.rooterDev];
};
});
}