Skip to content

Commit 7dcac9b

Browse files
Merge pull request #17 from nicholaschiasson/patch/nix-flake
Adding nix flake for development to project
2 parents 5f2c978 + 4d7d396 commit 7dcac9b

File tree

5 files changed

+199
-0
lines changed

5 files changed

+199
-0
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Add environment variables here to be available in development session.
2+
# Example: export SECRET_TOKEN=01234

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,92 @@ fcidr 10.0.0.0/8 + 127.0.0.0/16 | fcidr - 10.64.0.0/16 | fcidr !
118118
127.128.0.0/9
119119
128.0.0.0/1
120120
```
121+
122+
### Development
123+
124+
#### Prerequisites
125+
126+
- [nix](https://nixos.org/download.html)
127+
- [nix flakes](https://nixos.wiki/wiki/Flakes#Enable_flakes)
128+
129+
#### How-to
130+
131+
Create the development shell environment. Necessary to run all other commands.
132+
133+
```shell
134+
nix develop
135+
```
136+
137+
Build with cargo.
138+
139+
```shell
140+
just build
141+
```
142+
143+
Check the code with cargo's built-in fast static analysis.
144+
145+
```shell
146+
just check
147+
```
148+
149+
Remove build files.
150+
151+
```shell
152+
just clean
153+
```
154+
155+
Format the code.
156+
157+
```shell
158+
just format
159+
```
160+
161+
Check the code with clippy for better static analysis.
162+
163+
```shell
164+
just lint
165+
```
166+
167+
Run the application.
168+
169+
```shell
170+
just run
171+
```
172+
173+
Run tests with cargo's built-in test runner.
174+
175+
```shell
176+
just test
177+
```
178+
179+
Watch for code changes and rebuild.
180+
181+
```shell
182+
just watch
183+
```
184+
185+
All `just` commands can accept additional command line arguments after a `--`.
186+
187+
For example: run the application with a flag to report the version.
188+
189+
```shell
190+
just run -- --version
191+
```
192+
193+
##### Tips and Recommendations
194+
195+
###### Open IDE from Development Shell
196+
197+
To get linking to rust binaries in your IDE, you should open the development shell from your terminal and then open your IDE
198+
from that shell session. This will carry over the development shell's environment into your IDE.
199+
200+
For example if you work with VSCode.
201+
202+
```shell
203+
cd path/to/this/project
204+
nix develop
205+
code .
206+
```
207+
208+
By doing this, you can install the rust-analyzer VSCode extension and it will work properly since it will be able to point to
209+
the correct rust binaries and libraries. You will also have access in VSCode to any packages installed by the nix flake.

flake.lock

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
inputs = {
3+
flake-utils.url = "github:numtide/flake-utils";
4+
};
5+
6+
outputs = { self, nixpkgs, flake-utils }:
7+
flake-utils.lib.eachDefaultSystem (system: let
8+
pkgs = nixpkgs.legacyPackages.${system};
9+
in {
10+
devShell = pkgs.mkShell {
11+
buildInputs = [
12+
pkgs.cargo-watch
13+
pkgs.iconv
14+
pkgs.just
15+
pkgs.nerdfonts
16+
pkgs.rustup
17+
pkgs.starship
18+
];
19+
shellHook = ''
20+
source .env
21+
rustup default stable
22+
eval "$(starship init bash)"
23+
'';
24+
};
25+
});
26+
}

justfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
build *ARGS:
2+
cargo build {{ARGS}}
3+
4+
check *ARGS:
5+
cargo check {{ARGS}}
6+
7+
clean *ARGS:
8+
cargo clean {{ARGS}}
9+
10+
format *ARGS:
11+
cargo format {{ARGS}}
12+
13+
lint *ARGS:
14+
cargo lint {{ARGS}}
15+
16+
run *ARGS:
17+
cargo run {{ARGS}}
18+
19+
test *ARGS:
20+
cargo test {{ARGS}}
21+
22+
watch *ARGS:
23+
cargo watch {{ARGS}}

0 commit comments

Comments
 (0)