-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
117 lines (104 loc) · 3.37 KB
/
flake.nix
File metadata and controls
117 lines (104 loc) · 3.37 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
{
description = "RustMail — a modern, self-hosted SMTP mail catcher";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, crane, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
rustToolchain = pkgs.rust-bin.stable.latest.default;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
# Build the SolidJS UI first
uiDist = pkgs.stdenv.mkDerivation {
pname = "rustmail-ui";
version = "0.1.0";
src = ./ui;
nativeBuildInputs = [ pkgs.nodejs_22 pkgs.pnpm_10 ];
pnpmDeps = pkgs.pnpm_10.fetchDeps {
pname = "rustmail-ui";
version = "0.1.0";
src = ./ui;
# First `nix build` will fail and print the correct hash — paste it here.
hash = "";
};
configurePhase = ''
runHook preConfigure
export HOME=$TMPDIR
pnpm config set store-dir $TMPDIR/.pnpm-store
pnpm install --offline --frozen-lockfile
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
pnpm build
runHook postBuild
'';
installPhase = ''
runHook preInstall
cp -r dist $out
runHook postInstall
'';
};
# Filter source to only include Rust/Cargo files
rustSrc = let
rawSrc = craneLib.cleanCargoSource ./.;
in
pkgs.stdenv.mkDerivation {
name = "rustmail-src-with-ui";
src = rawSrc;
buildCommand = ''
cp -r $src $out
chmod -R u+w $out
mkdir -p $out/ui
cp -r ${uiDist} $out/ui/dist
'';
};
commonArgs = {
src = rustSrc;
strictDeps = true;
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.sqlite ]
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
];
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
rustmail = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
cargoExtraArgs = "--package rustmail-server --no-default-features";
meta = {
description = "A modern, self-hosted SMTP mail catcher with web UI";
homepage = "https://github.com/rustmailapp/rustmail";
license = with pkgs.lib.licenses; [ mit asl20 ];
mainProgram = "rustmail";
};
});
in
{
packages = {
default = rustmail;
inherit rustmail;
};
devShells.default = craneLib.devShell {
inputsFrom = [ rustmail ];
packages = [
pkgs.nodejs_22
pkgs.pnpm_10
pkgs.cargo-watch
pkgs.sqlx-cli
];
};
}
);
}