-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
112 lines (96 loc) · 3.7 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
{
description = "Musawarah dev environment setup";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = {nixpkgs, flake-utils, rust-overlay, ...}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; overlays = [ rust-overlay.overlays.default ]; };
# super hacky way to use mold
bintools-wrapper = "${nixpkgs}/pkgs/build-support/bintools-wrapper";
mold' = pkgs.symlinkJoin {
name = "mold";
paths = [ pkgs.mold ];
nativeBuildInputs = [ pkgs.makeWrapper ];
suffixSalt = pkgs.lib.replaceStrings ["-" "."] ["_" "_"] pkgs.targetPlatform.config;
postBuild = ''
for bin in ${pkgs.mold}/bin/*; do
rm $out/bin/"$(basename "$bin")"
export prog="$bin"
substituteAll "${bintools-wrapper}/ld-wrapper.sh" $out/bin/"$(basename "$bin")"
chmod +x $out/bin/"$(basename "$bin")"
mkdir -p $out/nix-support
substituteAll "${bintools-wrapper}/add-flags.sh" $out/nix-support/add-flags.sh
substituteAll "${bintools-wrapper}/add-hardening.sh" $out/nix-support/add-hardening.sh
substituteAll "${bintools-wrapper}/../wrapper-common/utils.bash" $out/nix-support/utils.bash
done
'';
};
in
with pkgs; {
devShell = mkShell {
NIX_CFLAGS_LINK = "-fuse-ld=mold";
packages = [
# test ci locally
act
# general utilities
exa
fd
bat
lazygit
# database
postgresql
docker
];
nativeBuildInputs = [
mold'
clang
];
buildInputs = [
# backend
(rust-bin.stable.latest.default.override {
extensions = [ "rust-src" "rust-analyzer" ];
})
diesel-cli
# auto reload server on save
# cargo watch -x run
cargo-watch
# needed for openssl dependant packages
openssl
pkg-config
# frontend
nodejs
nodePackages_latest.pnpm
# LSPs
nodePackages_latest.svelte-language-server
nodePackages_latest.vscode-langservers-extracted
];
shellHook = ''
# cool aliases
alias ls='exa --time-style=long-iso --group-directories-first --icons --no-permissions --no-user -l --git'
alias ll="exa --time-style=long-iso --group-directories-first --icons -la"
alias find=fd
alias cat=bat
# run dev servers
alias lcr='RUST_LOG=musawarah=debug,tower=debug cargo run'
alias lcw='RUST_LOG=musawarah=debug,tower=debug cargo watch -x run'
alias npmd='pnpm run dev'
# start dev database if available, if not create, and run it on port 5445
docker start musawarah-dev || \
docker run \
--name musawarah-dev \
-p 5445:5432 \
-e POSTGRES_PASSWORD=musawarah-dev \
-d postgres
# add DATABASE_URL to .env file if not already there
grep DATABASE_URL .env || echo "DATABASE_URL=postgres://postgres:musawarah-dev@localhost:5445/postgres" >> .env
# export environment variables
export $(cat .env)
'';
};
formatter.x86_64-linux = legacyPackages.${system}.nixpkgs-fmt;
});
}