-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
132 lines (130 loc) · 3.71 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
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
flocken = {
url = "github:mirkolenz/flocken/v2";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs@{
flake-parts,
systems,
flocken,
self,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = import systems;
perSystem =
{
pkgs,
lib,
self',
system,
...
}:
let
npmDeps = pkgs.importNpmLock {
npmRoot = ./.;
};
rewrites = lib.mapAttrsToList (
source: target: "redir ${source} ${target} permanent"
) (import ./rewrites.nix);
caddyport = "8080";
caddyfile = pkgs.writeText "caddyfile" ''
{
admin off
auto_https off
persist_config off
}
:${caddyport} {
root * ${self'.packages.default}
encode gzip
${lib.concatLines rewrites}
try_files {path} {path}/ /404/
file_server {
index index.html
}
}
'';
in
{
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
(final: prev: {
nodejs = final.nodejs_18;
})
];
};
apps.docker-manifest.program = flocken.legacyPackages.${system}.mkDockerManifest {
github = {
enable = true;
token = "$GH_TOKEN";
};
images = with self.packages; [ x86_64-linux.docker ];
};
devShells.default = pkgs.mkShell {
shellHook = ''
${lib.getExe' pkgs.nodejs "npm"} install
'';
packages = [ pkgs.nodejs ];
};
packages = {
default = pkgs.buildNpmPackage {
inherit npmDeps;
inherit (npmDeps) pname version;
inherit (pkgs.importNpmLock) npmConfigHook;
src = ./.;
npmFlags = [ "--legacy-peer-deps" ];
installPhase = ''
runHook preInstall
mkdir -p "$out"
cp -r "public/." "$out"
runHook postInstall
'';
buildInputs = with pkgs; [ vips ];
nativeBuildInputs = with pkgs; [
pkg-config
nodejs.passthru.python
];
};
server = pkgs.writeShellApplication {
name = "server";
text = ''
${lib.getExe pkgs.caddy} run --config ${caddyfile} --adapter caddyfile
'';
};
docker = pkgs.dockerTools.buildLayeredImage {
name = "recap-website";
tag = "latest";
created = "now";
contents = with pkgs; [
dockerTools.fakeNss
cacert
tzdata
];
extraCommands = ''
mkdir -m 1777 tmp
'';
config = {
Entrypoint = [ (lib.getExe self'.packages.server) ];
ExposedPorts = {
"${caddyport}/tcp" = { };
};
User = "nobody:nobody";
Env = [
"XDG_CONFIG_HOME=/config"
"XDG_DATA_HOME=/data"
"HOME=/root"
];
WorkingDir = "/srv";
};
};
};
};
};
}