-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
217 lines (186 loc) · 6.68 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
{
description = "zap dev shell";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
# required for latest zig
zig.url = "github:mitchellh/zig-overlay";
# required for latest neovim
neovim-flake.url = "github:neovim/neovim?dir=contrib";
neovim-flake.inputs.nixpkgs.follows = "nixpkgs";
# Used for shell.nix
flake-compat = {
url = github:edolstra/flake-compat;
flake = false;
};
};
outputs = {
self,
nixpkgs,
flake-utils,
...
} @ inputs: let
overlays = [
# Other overlays
(final: prev: {
zigpkgs = inputs.zig.packages.${prev.system};
neovim-nightly-pkgs = inputs.neovim-flake.packages.${prev.system};
})
];
# Our supported systems are the same supported systems as the Zig binaries
systems = builtins.attrNames inputs.zig.packages;
in
flake-utils.lib.eachSystem systems (
system: let
pkgs = import nixpkgs {inherit overlays system; };
in rec {
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
# neovim-nightly-pkgs.neovim
zigpkgs."0.11.0"
python3
poetry
bat
wrk
];
buildInputs = with pkgs; [
# we need a version of bash capable of being interactive
# as opposed to a bash just used for building this flake
# in non-interactive mode
bashInteractive
];
shellHook = ''
# once we set SHELL to point to the interactive bash, neovim will
# launch the correct $SHELL in its :terminal
export SHELL=${pkgs.bashInteractive}/bin/bash
'';
};
# shell that provides zig 0.11.0 via overlay
# use it for just building locally, via zig build
devShells.build = pkgs.mkShell {
# nativeBuildInputs = with pkgs; [
# zigpkgs."0.11.0"
# ];
buildInputs = with pkgs; [
# we need a version of bash capable of being interactive
# as opposed to a bash just used for building this flake
# in non-interactive mode
bashInteractive
zigpkgs."0.11.0"
];
shellHook = ''
# once we set SHELL to point to the interactive bash, neovim will
# launch the correct $SHELL in its :terminal
export SHELL=${pkgs.bashInteractive}/bin/bash
'';
};
# For compatibility with older versions of the `nix` binary
devShell = self.devShells.${system}.default;
defaultPackage = packages.sycl2023app-linux;
# build the app with nix for LINUX (linux musl)
# -- change zig build below for mac for now
# nix build .#sycl2023app-linux
packages.sycl2023app-linux = pkgs.stdenvNoCC.mkDerivation {
name = "sycl-app";
version = "master";
src = ./.;
nativeBuildInputs = [ pkgs.zigpkgs."0.11.0" ];
dontConfigure = true;
dontInstall = true;
postPatch = ''
mkdir -p .cache
ln -s ${pkgs.callPackage ./deps.nix { }} .cache/p
'';
buildPhase = ''
mkdir -p $out
mkdir -p .cache/{p,z,tmp}
zig build -Dtarget=x86_64-linux-musl -Dcpu=baseline install --cache-dir $(pwd)/zig-cache --global-cache-dir $(pwd)/.cache -Doptimize=ReleaseSafe --prefix $out
cp -pr frontend $out/bin/
cp -pr admin $out/bin/
cp -pr data $out/bin/
cp -p passwords.txt $out/bin/
# apparently not neccesary to link the path later in the docker image
# mkdir -p tmp
'';
};
# the following produces the exact same image size
# note: the following only works if you build on linux I guess
#
# Usage:
# nix build .#docker
# docker load < result
# docker run -p5000:5000 sycl-app:lastest
packages.docker = pkgs.dockerTools.buildImage { # helper to build Docker image
name = "sycl2023app"; # give docker image a name
tag = "latest"; # provide a tag
created = "now";
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [ packages.sycl2023app-linux.out ]; # .out seems to not make a difference
pathsToLink = [ "/bin" "/tmp"];
};
# facil.io needs a /tmp
# update: pathsToLink /tmp above seems to do the trick
config = {
Cmd = [ "/bin/sycl2023app" ];
WorkingDir = "/bin";
ExposedPorts = {
"5000/tcp" = {};
};
};
};
# this one with runAsRoot needs qemu but produces the same size as above
# # note: the following only works if you build on linux I guess
# # nix build .#docker
# packages.docker = pkgs.dockerTools.buildImage { # helper to build Docker image
# name = "sycl2023app"; # give docker image a name
# tag = "latest"; # provide a tag
#
# # facil.io needs a /tmp
# runAsRoot = ''
# mkdir /tmp
# chmod 1777 /tmp
# '';
#
# config = {
#
# Cmd = [ "${packages.sycl2023app-linux}/bin/sycl2023app" ];
# WorkingDir = "${packages.sycl2023app-linux}/bin";
#
# ExposedPorts = {
# "5000/tcp" = {};
# };
#
# };
# };
# buildLayeredImage creates huge images > 1 GB for us
# # note: the following only works if you build on linux I guess
# # nix build .#docker
# packages.docker = pkgs.dockerTools.buildLayeredImage { # helper to build Docker image
# name = "sycl2023app-linux"; # give docker image a name
# tag = "latest"; # provide a tag
# contents = [
# packages.sycl2023app-linux
# ];
#
# fakeRootCommands = ''
# mkdir /tmp
# chmod 1777 /tmp
# '';
#
# enableFakechroot = true;
#
# config = {
#
# Cmd = [ "${packages.sycl2023app-linux}/bin/sycl2023app" ];
# WorkingDir = "${packages.sycl2023app-linux}/bin";
#
# ExposedPorts = {
# "5000/tcp" = {};
# };
#
# };
# };
}
);
}