-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
160 lines (155 loc) · 7.06 KB
/
Copy pathflake.nix
File metadata and controls
160 lines (155 loc) · 7.06 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
rust-overlay,
crane,
treefmt-nix,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
# Initialize nixpkgs
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
# Setup the rust toolchain
rust-bin = rust-overlay.lib.mkRustBin { } pkgs;
rust' = (rust-bin.fromRustupToolchainFile ./rust-toolchain.toml);
# Setup rust nix packaging
craneLib = (crane.mkLib pkgs).overrideToolchain (_: rust');
stdenvSelector =
p: if p.stdenv.hostPlatform.isElf then p.stdenvAdapters.useMoldLinker p.stdenv else p.stdenv;
commonArgs = {
src = craneLib.cleanCargoSource ./.;
strictDeps = true;
# buildInputs = with pkgs; [
# libpq
# openssl
# ];
# nativeBuildInputs = with pkgs; [ pkg-config ];
# Use mold linker for faster builds on ELF platforms
stdenv = stdenvSelector;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
commonArgsWithDeps = commonArgs // {
inherit cargoArtifacts;
};
cranePackage = craneLib.buildPackage (
commonArgsWithDeps
// {
meta = {
mainProgram = "plus-backend";
license = lib.licenses.gpl3Plus;
};
}
);
# The skinview3d cover render sidecar (render-service/). Pure-JS
# runtime deps (puppeteer + fflate) installed from the committed
# lockfile via importNpmLock (no vendored hash to maintain). The
# skinview3d fork is pre-bundled into render-service/vendor, so the
# Nix build never touches the git dependency or a JS build step.
# Puppeteer's Chromium download is skipped; the nixpkgs chromium is
# wired in at runtime instead.
render-service = pkgs.buildNpmPackage {
pname = "plus-render-service";
version = "0.1.0";
src = lib.cleanSourceWith {
src = ./render-service;
# Keep the local node_modules out of the store; npm ci
# reinstalls from the lockfile in the build sandbox.
filter = path: _type: baseNameOf path != "node_modules";
};
npmDeps = pkgs.importNpmLock { npmRoot = ./render-service; };
inherit (pkgs.importNpmLock) npmConfigHook;
dontNpmBuild = true;
# Skip Puppeteer's Chromium download during the build; the
# nixpkgs chromium is wired in at runtime below.
PUPPETEER_SKIP_DOWNLOAD = "1";
nativeBuildInputs = [ pkgs.makeWrapper ];
postInstall = ''
makeWrapper ${pkgs.nodejs}/bin/node $out/bin/plus-render-service \
--add-flags $out/lib/node_modules/plus-render-service/src/server.js \
--set PUPPETEER_EXECUTABLE_PATH ${pkgs.chromium}/bin/chromium
'';
meta.mainProgram = "plus-render-service";
};
# Setup treefmt-nix
treefmtModule = import ./treefmt.nix { inherit rust'; };
treefmtEval = treefmt-nix.lib.evalModule pkgs treefmtModule;
# Utilities for testing locally
start-dev-env = pkgs.writeShellApplication {
name = "start-dev-env";
text = builtins.readFile ./scripts/start-dev-env.sh;
runtimeInputs = with pkgs; [
rclone
curl
jq
postgresql
];
};
in
{
packages = {
default = self.packages.${system}.plus-backend;
plus-backend = cranePackage;
inherit render-service;
};
apps.render-service = {
type = "app";
program = "${render-service}/bin/plus-render-service";
};
formatter = treefmtEval.config.build.wrapper;
devShells.default =
craneLib.devShell.override { mkShell = pkgs.mkShell.override { stdenv = stdenvSelector pkgs; }; }
{
# Add all build-time dependencies to the environment
packages =
cranePackage.buildInputs
++ cranePackage.nativeBuildInputs
++ [
# Conveinience scripts for testing
start-dev-env
]
++ (with pkgs; [
# External rust dev utilities
sea-orm-cli
cargo-deny
cargo-udeps
cargo-nextest
# Rust repl for testing
evcxr
# Debugging
lldb
postgresql
# Add treefmt wrapper to the PATH for ease of use
self.formatter.${system}
# s3
s3cmd
# Node runtime for the skinview3d cover render sidecar
# (render-service/). It is installed and run via npm;
# Puppeteer provides its own headless Chromium.
nodejs
]);
env = {
MIGRATION_DIR = "./database/migrations";
};
};
}
);
}