-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
202 lines (188 loc) · 6.42 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
200
201
202
{
inputs = {
nixpkgs.url = "nixpkgs/release-21.05";
utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
naersk.url = "github:nix-community/naersk";
devshell.url = "github:numtide/devshell";
};
outputs = { self, utils, rust-overlay, devshell, nixpkgs, naersk, ... }:
utils.lib.eachDefaultSystem (system:
let
inherit (naersk.lib.${system}) buildPackage;
pkgs = import nixpkgs {
inherit system;
overlays = [ devshell.overlay rust-overlay.overlay ];
};
rust-stable = pkgs.rust-bin.stable."1.56.1".default.override {
extensions = [
"cargo"
"clippy"
"rust-docs"
"rust-src"
"rust-std"
"rustc"
"rustfmt"
];
};
naersk-lib = (naersk.lib."${system}".override {
cargo = rust-stable;
rustc = rust-stable;
});
codeSettings = pkgs.writeScriptBin "vscode-settings" ''
#!${pkgs.stdenv.shell}
if [ ! -f "''${PRJ_ROOT}/.vscode/settings.json" ]; then
if [ ! -d "''${PRJ_ROOT}/.vscode" ]; then
mkdir "''${PRJ_ROOT}/.vscode"
fi
${pkgs.coreutils}/bin/cat <<EOF > $PRJ_ROOT/.vscode/settings.json
{
"rust-analyzer.trace.extension": true,
"rust-analyzer.trace.server": "messages",
"rust-analyzer.server.path": "${pkgs.rust-analyzer}/bin/rust-analyzer",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash"
},
"zsh": {
"path": "zsh"
},
"nix" : {
"path": "nix-shell"
}
},
"terminal.integrated.defaultProfile.linux": "nix",
"editor.insertSpaces": false,
}
EOF
else
line=$(grep '"rust-analyzer.server.path"' $PRJ_ROOT/.vscode/settings.json)
nline='"rust-analyzer.server.path": "${pkgs.rust-analyzer}/bin/rust-analyzer",'
sed -i "s|$line|$nline|g" $PRJ_ROOT/.vscode/settings.json
fi
'';
extensions = (with pkgs.vscode-extensions; [
bbenoist.Nix
matklad.rust-analyzer
tamasfe.even-better-toml
pkief.material-icon-theme
]) ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [
{
name = "spacemacs";
publisher = "cometeer";
version = "1.1.1";
sha256 =
"da54d2a40b72bb814b2e4af6b03eff6b3982162ae6f4492e6ceccad8f70cc7d3";
}
{
name = "search-crates-io";
publisher = "belfz";
version = "1.2.1";
sha256 =
"2b61f83871fabe042f86170e15d3f7443d1f3e0840c716e0babbfe37cda914db";
}
{
name = "errorlens";
publisher = "usernamehw";
version = "3.4.0";
sha256 = "1x9rkyhbp15dwp6dikzpk9lzjnh9cnxac89gzx533681zld906m8";
}
];
vscodium-with-extensions = pkgs.vscode-with-extensions.override {
vscode = pkgs.vscodium;
vscodeExtensions = extensions;
};
in
{
# nix build
defaultPackage = buildPackage {
pname = "bulbb";
nativeBuildInputs = with pkgs; [ pkg-config ];
root = ./.;
};
# nix develop
devShell = pkgs.devshell.mkShell {
name = "bulbb";
bash.interactive = ''
alias ..='cd ..'
alias c='clear'
alias countfiles='fd -t f | wc -l'
alias f='fd . | grep '
alias folders='du -h --max-depth=1'
alias folderssort='fd . -d 1 -t d -print0 | xargs -0 du -sk | sort -rn'
alias gt='cd $(fd -H -t d -j $(nproc) | sk )'
alias h='history | grep '
alias l='exa --icons'
alias la='exa --all --icons'
alias ll='exa --long --header --git --icons'
alias ls='exa --icons'
alias lsa='exa --all --icons'
alias lsal='exa --long --all --header --git --icons'
alias lsl='exa --long --header --git --icons'
alias lsla='exa --long --all --header --git --icons'
alias mem='free -h --si'
alias sl='exa --icons'
alias sla='exa --all --icons'
alias slal='exa --long --all --header --git --icons'
alias sll='exa --long --header --git --icons'
alias slla='exa --long --all --header --git --icons'
alias topcpu='ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10'
eval "$(${pkgs.starship}/bin/starship init bash)"
bash ${codeSettings}/bin/vscode-settings
'';
# Custom scripts. Also easy to use them in CI/CD
commands = [
{
category = "bulbb";
name = "build";
help = "Build bulbb";
command = "cargo build";
}
{
category = "bulbb";
name = "code";
help = "Open bulbb in vscodium";
command = "${vscodium-with-extensions}/bin/codium $PRJ_ROOT";
}
{
category = "bulbb";
name = "fmt";
help = "Check formatting for bulbb";
command = "nixpkgs-fmt \${@} $PRJ_ROOT && cargo fmt";
}
{
category = "bulbb";
name = "run";
help = "Run bulbb";
command = "cargo run";
}
{
category = "bulbb";
name = "test";
help = "Run test for bulbb";
command = "cargo test";
}
];
packages = with pkgs;[
stdenv.cc
rust-stable
rust-analyzer
cargo-whatfeatures
cargo-release
cargo-license
cargo-tarpaulin
# for shell
zsh
neofetch
nixpkgs-fmt
starship
fd
ripgrep
exa
] ++ [ vscodium-with-extensions ];
env = [
{ name = "RUST_SRC_PATH"; eval = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; }
];
};
});
}