-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
171 lines (134 loc) · 4.39 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
{
description = "Game Night";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
};
outputs = { self, nixpkgs, flake-utils, crane, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-analyzer" "rust-src" ];
};
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
sqlFilter = path: _type: builtins.match ".*sql$" path != null;
sqlxFilter = path: _type: builtins.match ".*sqlx-data.json$" path != null;
templatesFilter = path: _type: builtins.match ".*html" path != null;
srcFilter = path: type:
(sqlFilter path type) || (sqlxFilter path type) || (templatesFilter path type) || (craneLib.filterCargoSources path type);
src = pkgs.lib.cleanSourceWith {
src = craneLib.path ./backend;
filter = srcFilter;
};
commonArgs = {
inherit src;
pname = "game-night-backend";
version = "0.1.0";
nativeBuildInputs = [ pkgs.grpc-tools ];
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
game-night-backend = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
});
in
rec {
checks = {
inherit game-night-backend;
clippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
});
doc = craneLib.cargoDoc (commonArgs // {
inherit cargoArtifacts;
});
fmt = craneLib.cargoFmt (commonArgs // {
inherit src;
});
};
packages.game-night-backend = game-night-backend;
packages.game-night-frontend = pkgs.mkYarnPackage {
pname = "game-night-frontend";
src = ./frontend;
# Create a node modules folder that is writable based on the downloaded dependencies
configurePhase = ''
cp -r $node_modules node_modules
chmod -R 755 node_modules;
'';
# run the vue-cli-service build in offline mode to avoid pull dependencies
buildPhase = ''
yarn run --offline build
'';
# copy the built sources into the output folder
installPhase = ''
cp -r dist/ $out
'';
# do not attempt to build distribution bundles
distPhase = ''
true
'';
};
packages.game-night-docker = pkgs.dockerTools.buildLayeredImage {
name = "game-night";
tag = "latest";
contents = [
pkgs.bash
pkgs.coreutils
pkgs.cacert
];
config = {
Env = [
"FRONTEND_DIR=${packages.game-night-frontend}"
"RUST_LOG=debug,h2::proto=warn,game_night=trace"
];
Cmd = [ "${packages.game-night-backend}/bin/game-night" ];
WorkingDir = "/app";
ExposedPorts = { "2727" = { }; };
};
};
packages.default = packages.game-night-docker;
apps.game-night-backend = flake-utils.lib.mkApp {
drv = packages.game-night-backend;
exePath = "/bin/game-night";
};
apps.default = apps.game-night-backend;
devShells.default = pkgs.mkShell {
packages = with pkgs; [
# General
just
# Rust / Backend
rustToolchain
cargo-edit
cargo-outdated
sqlx-cli
# Build Dependencies
grpc-tools
# Typescript / Frontend
nodejs
nodePackages.npm
nodePackages.yarn
nodePackages.vue-cli
# Infrastructure
tfswitch
packer
# GitHub tooling
gh
# Nix
nixpkgs-fmt
];
};
});
}