-
Notifications
You must be signed in to change notification settings - Fork 345
/
flake.nix
148 lines (125 loc) · 3.82 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
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
{
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;
};
# Repository with software packages.
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
# Package expression for old PHP versions.
phps.url = "github:fossar/nix-phps";
};
outputs = { self, flake-compat, nixpkgs, phps, utils }:
let
# 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.fold (lib.mergeAttrsWithFunc mergeAttribute) {};
# 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 = [
# Back-end code validation.
php.packages.phpstan
# 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 = pkgs.mkShell (
mergeEnvs [
languageEnv
developmentSupport
qaTools
websiteTools
dbServers.${matrix.storage}
]
);
ci = pkgs.mkShell (
mergeEnvs [
languageEnv
qaTools
websiteTools
dbServers.${matrix.storage}
]
);
website = pkgs.mkShell (
mergeEnvs [
websiteTools
]
);
};
}
);
}