-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy pathflake.nix
More file actions
167 lines (142 loc) · 4.24 KB
/
Copy pathflake.nix
File metadata and controls
167 lines (142 loc) · 4.24 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
{
description = "selfoss feed reader and aggregator";
inputs = {
# Shim to make flake.nix work with stable Nix.
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
# Package expression for old PHP versions.
phps.url = "github:fossar/nix-phps";
};
outputs = { self, phps, ... }:
let
# nixpkgs is a repository with software packages and some utilities.
# From simplicity, we inherit it from the phps flake.
inherit (phps.inputs) nixpkgs utils;
# Configure the development shell here (e.g. for CI).
# By default, we use the default PHP version from Nixpkgs.
matrix.phpPackage = "php";
# We install all storage backends by default.
matrix.storage = "all";
in
# For each supported platform,
utils.lib.eachDefaultSystem (system:
let
# Get Nixpkgs packages for current platform.
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
mergeAttribute =
l:
r:
if builtins.isAttrs l && builtins.isAttrs r then
l // r
else if builtins.isList l && builtins.isList r then
l ++ r
else
throw "Unsupported combination of types: ${builtins.typeOf l} and ${builtins.typeOf r}";
mergeEnvs = lib.foldr (lib.mergeAttrsWithFunc mergeAttribute) {};
mkShell =
attrs:
let
attrs' = attrs // {
nativeBuildInputs = lib.map lib.getBin attrs.nativeBuildInputs or [ ];
};
in
pkgs.mkShell attrs';
# Create a PHP package from the selected PHP package, with some extra extensions enabled.
php = phps.packages.${system}.${matrix.phpPackage}.withExtensions ({ enabled, all }: with all; enabled ++ [
imagick
tidy
]);
# Create a Python package with some extra packages installed.
python = pkgs.python3.withPackages (pp: with pp; [
# For integration tests.
bcrypt
requests
]);
# Database servers for testing.
dbServers = {
mysql = {
nativeBuildInputs = [ pkgs.mariadb ];
};
postgresql = {
nativeBuildInputs = [ pkgs.postgresql ];
};
sqlite = { };
all = mergeEnvs (builtins.attrValues (builtins.removeAttrs dbServers [ "all" ]));
};
languageEnv = {
nativeBuildInputs = [
# Composer and PHP for back-end.
php
php.packages.composer
# npm for front-end.
pkgs.nodejs_latest
];
env = {
# node-gyp wants some locales, let’s make them available through an environment variable.
LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";
};
};
developmentSupport = {
nativeBuildInputs = [
# PHP LSP
pkgs.phpactor
];
};
qaTools = {
nativeBuildInputs = [
# For building zip archive and integration tests.
python
# Python code linting.
pkgs.black
];
};
websiteTools = {
nativeBuildInputs = [
# Website generator.
pkgs.zola
];
};
in
{
# Expose shell environment for development.
devShells = {
default = mkShell (
mergeEnvs [
languageEnv
developmentSupport
qaTools
websiteTools
dbServers.${matrix.storage}
]
);
ci = mkShell (
mergeEnvs [
languageEnv
qaTools
websiteTools
dbServers.${matrix.storage}
]
);
# Minimal environment for deploy ci job
ci-dist = mkShell (
mergeEnvs [
languageEnv
{
nativeBuildInputs = [
pkgs.python3
];
}
]
);
website = mkShell (
mergeEnvs [
websiteTools
]
);
};
}
);
}