-
Notifications
You must be signed in to change notification settings - Fork 0
/
devenv.nix
155 lines (136 loc) · 5.16 KB
/
devenv.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
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
147
148
149
150
151
152
153
154
155
# my first endeavours with reusable NIX.
#
# Learnings:
#
# - everything is super-lazy by default. Thus, variables (defined after let) will only be evaluated when necessary.
# - this includes side-effects (e.g. building derivations) or downloading from github like pkgs.fetchFromGitHub
# - lib.mkIf cannot be used everywhere
# - lib.mkDefault makes a value overridable; lib.mkForce now.
{ pkgs, lib, config, ... }:
# we can simply write mkIf instead of lib.mkIf.
with lib;
########################################################################################
########################################################################################
# Variable declarations (can reference other variables declared beforehand.)
########################################################################################
########################################################################################
let
cfg = config.neos;
shellColors = ''
# https://stackoverflow.com/questions/4332478/read-the-current-text-color-in-a-xterm/4332530#4332530
bold=$(tput bold)
green=$(tput setaf 2)
normal=$(tput sgr0)
'';
in
{
imports = [
./_neosFlowConfig.nix
./_phpAndExtensions.nix
./_mysql.nix
./_caddy.nix
./_ideConfig.nix
./services/imagor.nix
];
########################################################################################
########################################################################################
# CONFIG definition
#
# Reference: https://devenv.sh/reference/options/
########################################################################################
########################################################################################
config = lib.mkIf cfg.enable {
# Setup and Documentation
enterShell = ''
${shellColors}
echo ""
echo "''${green}=============================================''${normal}"
echo "''${bold}FINISHED: ''${green}Your PHP environment is ready!''${normal}"
echo ""
echo " - ''${green}PHP ${cfg.phpPackage.version}''${normal} installed"
${if cfg.flowConfig then ''
echo " - Neos ''${green}Configuration/Settings.yaml''${normal} written"
'' else ""}
${if cfg.vips then ''
echo " - ''${green}VIPS''${normal} activated"
'' else ""}
${if cfg.spx then ''
echo " - ''${green}SPX''${normal} profiler activated. URL: ''${green}http://127.0.0.1:<port>/?SPX_UI_URI=/&SPX_KEY=dev''${normal}"
echo " For further help, see ''${bold}help-spx''${normal}"
'' else ""}
${if cfg.jetbrainsIdeConfig then ''
echo " - ''${green}IntelliJ/PHPStorm''${normal} configured:"
echo " - ''${green}Data Source''${normal} (Password: empty)"
echo " - ''${green}PHP Interpreter''${normal} set up"
'' else ""}
echo "''${green}=============================================''${normal}"
cd ${cfg.distributionDir}
'';
};
########################################################################################
########################################################################################
# SCHEMA: defining which properties/options the user can set.
########################################################################################
########################################################################################
options.neos = {
enable = mkEnableOption "Neos Addon";
distributionDir = mkOption {
type = types.str;
default = ".";
description = "the Neos distribution directory (e.g. where composer.json and ./flow is located)";
};
phpPackage = mkOption {
type = types.package;
default = pkgs.php81;
defaultText = literalExpression "pkgs.php81";
description = ''
The PHP package to use, e.g. pkgs.php81 or pkgs.php82.
You are NOT allowed to specify languages.php.package, or languages.php.version; because we want to configure Neos with VIPS support.
'';
};
mysql = mkOption {
type = types.bool;
description = "Should configure Mysql DB?";
default = true;
};
vips = mkOption {
type = types.bool;
description = "Should configure VIPS?";
default = true;
};
spx = mkOption {
type = types.bool;
description = "Should configure SPX Profiler?";
default = true;
};
jetbrainsIdeConfig = mkOption {
type = types.bool;
description = "Should generate .idea/datasources.xml and .idea/php.xml ? (for use in PHPStorm or IntelliJ)";
default = true;
};
flowConfig = mkOption {
type = types.bool;
description = "Should generate Configuration/Settings.yaml";
default = true;
};
caddyDefaultVhostConfig = mkOption {
type = types.lines;
default = "";
description = ''
These lines go into the default vhost verbatim.
'';
};
caddyDefaultVhostPort = lib.mkOption {
type = lib.types.int;
default = 8081;
description = ''
Caddy port
'';
};
caddyDefaultVhostRoot = lib.mkOption {
type = types.str;
default = config.devenv.root;
description = "The default vhost root";
};
};
}