forked from kitsune-soc/kitsune
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
199 lines (171 loc) · 5.99 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
{
inputs = {
devenv = {
inputs.nixpkgs.follows = "nixpkgs";
url = "github:cachix/devenv";
};
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
rust-overlay = {
inputs = {
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
};
url = "github:oxalica/rust-overlay";
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
# The premise is this is the "default" and if you want to do a debug build,
# pass it in as an arg.
# like so `nix build --override-input debugBuild github:boolean-option/true`
debugBuild.url = "github:boolean-option/false/d06b4794a134686c70a1325df88a6e6768c6b212";
};
outputs = { self, devenv, flake-utils, nixpkgs, rust-overlay, crane, ... } @ inputs:
(flake-utils.lib.eachDefaultSystem
(system:
let
features = "--all-features";
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit overlays system;
};
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv;
rustPlatform = pkgs.makeRustPlatform {
cargo = pkgs.rust-bin.stable.latest.minimal;
rustc = pkgs.rust-bin.stable.latest.minimal;
inherit stdenv;
};
craneLib = (crane.mkLib pkgs).overrideToolchain pkgs.rust-bin.stable.latest.minimal;
buildInputs = with pkgs; [
openssl
sqlite
zlib
];
nativeBuildInputs = with pkgs; [
protobuf
pkg-config
rustPlatform.bindgenHook
];
src = pkgs.lib.cleanSourceWith {
src = pkgs.lib.cleanSource ./.;
filter = name: type:
let baseName = baseNameOf (toString name);
in !(baseName == "flake.lock" || pkgs.lib.hasSuffix ".nix" baseName);
};
commonArgs = {
inherit src stdenv buildInputs nativeBuildInputs;
strictDeps = true;
meta = {
description = "ActivityPub-federated microblogging";
homepage = "https://joinkitsune.org";
};
OPENSSL_NO_VENDOR = 1;
NIX_OUTPATH_USED_AS_RANDOM_SEED = "aaaaaaaaaa";
cargoExtraArgs = "--locked ${features}";
} // (pkgs.lib.optionalAttrs inputs.debugBuild.value {
# do a debug build, as `dev` is the default debug profile
CARGO_PROFILE = "dev";
});
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
version = cargoToml.workspace.package.version;
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
pname = "kitsune-workspace";
src = craneLib.cleanCargoSource src;
});
in
{
formatter = pkgs.nixpkgs-fmt;
packages = rec {
default = main;
cli = craneLib.buildPackage (commonArgs // {
pname = "kitsune-cli";
cargoExtraArgs = commonArgs.cargoExtraArgs + " --bin kitsune-cli";
inherit cargoArtifacts;
doCheck = false;
});
mrf-tool = craneLib.buildPackage (commonArgs // {
pname = "mrf-tool";
cargoExtraArgs = commonArgs.cargoExtraArgs + " --bin mrf-tool";
inherit cargoArtifacts;
doCheck = false;
});
main = craneLib.buildPackage (commonArgs // rec {
pname = "kitsune";
cargoExtraArgs = commonArgs.cargoExtraArgs + " --bin kitsune --bin kitsune-job-runner";
inherit cargoArtifacts;
doCheck = false;
});
frontend = pkgs.mkYarnPackage {
inherit version;
packageJSON = "${src}/kitsune-fe/package.json";
yarnLock = "${src}/kitsune-fe/yarn.lock";
src = "${src}/kitsune-fe";
buildPhase = ''
export HOME=$(mktemp -d)
yarn --offline build
'';
installPhase = ''
mkdir -p $out
cp -R deps/kitsune-fe/dist $out
'';
distPhase = "true";
};
};
devShells = rec {
default = backend;
backend = devenv.lib.mkShell {
inherit pkgs inputs;
modules = [
({ pkgs, ... }: {
packages = with pkgs; [
cargo-insta
diesel-cli
rust-bin.stable.latest.default
]
++
buildInputs ++ nativeBuildInputs;
enterShell = ''
export PG_HOST=127.0.0.1
export PG_PORT=5432
[ -z "$DATABASE_URL" ] && export DATABASE_URL=postgres://$USER@$PG_HOST:$PG_PORT/$USER
export REDIS_PORT=6379
[ -z "$REDIS_URL" ] && export REDIS_URL="redis://127.0.0.1:$REDIS_PORT"
'';
services = {
postgres = {
enable = true;
listen_addresses = "127.0.0.1";
};
redis.enable = true;
};
})
];
};
frontend = pkgs.mkShell {
buildInputs = with pkgs; [
nodejs
yarn
];
};
};
}
) // {
overlays = rec {
default = kitsune;
kitsune = (import ./overlay.nix self);
};
nixosModules = rec {
default = kitsune;
kitsune = (import ./module.nix);
};
}) // {
nixci.default = {
debug = {
dir = ".";
overrideInputs.debugBuild = "github:boolean-option/true/6ecb49143ca31b140a5273f1575746ba93c3f698";
};
};
};
}