Skip to content

Commit cfb62fd

Browse files
committed
docs: Added rust example
1 parent 847f6a8 commit cfb62fd

File tree

10 files changed

+192
-8
lines changed

10 files changed

+192
-8
lines changed

docs/content/3.config/6.environments/c.md

Whitespace-only changes.

docs/content/3.config/6.environments/dotnet.md

Whitespace-only changes.

docs/content/3.config/6.environments/go.md

Whitespace-only changes.

docs/content/3.config/6.environments/gpu.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# GPU
22

3-
::: tip
3+
::alert{type="info"}
44
Try it out with `codchi init <NAME> https://github.com/aformatik/codchi nixosModules.gpu`.
5-
:::
5+
::
66

77
GPU usage should work by default inside a code machine. Codchi uses the GPU driver from your host and therefore only works when the driver is installed on your host. Currently only Nvidia/CUDA is tested.
88

docs/content/3.config/6.environments/javascript.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Javascript
22

3-
::: tip
3+
::alert{type="info"}
44
Try it out with `codchi init <NAME> https://github.com/aformatik/codchi nixosModules.javascript`.
5-
:::
5+
::
66

77
```nix
88
{ pkgs, ... }: {

docs/content/3.config/6.environments/jvm.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# JVM
22

3-
::: tip
3+
::alert{type="info"}
44
Try it out with `codchi init <NAME> https://github.com/aformatik/codchi nixosModules.jvm`.
5-
:::
5+
::
66

77

88
## General, Java & Kotlin

docs/content/3.config/6.environments/python.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Python
22

3-
::: tip
3+
::alert{type="info"}
44
Try it out with `codchi init <NAME> https://github.com/aformatik/codchi nixosModules.python`.
5-
:::
5+
::
66

77
```nix
88
{ pkgs, ... }: {
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Rust
2+
3+
## Rust via flakes
4+
5+
::alert{type="info"}
6+
Try it out with `codchi clone <NAME> https://github.com/aformatik/codchi nixosModules.codchi`.
7+
::
8+
9+
There is already great support for Rust development environments via Nix Flakes. Additionally to providing a development environment, this method also allows building the Rust project itself. Codchi itself uses this approach.
10+
11+
To use this method with Codchi, just install an IDE (and optionally nix-direnv) like [Codchi's code machine](https://github.com/aformatik/codchi/blob/master/configuration.nix) does:
12+
13+
```nix
14+
{ pkgs, ... }:
15+
{
16+
environment.systemPackages = [
17+
(pkgs.vscode-with-extensions.override {
18+
vscode = pkgs.vscodium;
19+
vscodeExtensions = with pkgs.vscode-extensions; [
20+
rust-lang.rust-analyzer
21+
jnoortheen.nix-ide
22+
mkhl.direnv
23+
asvetliakov.vscode-neovim
24+
];
25+
})
26+
pkgs.bashInteractive # fix terminal in VSCode
27+
];
28+
programs.neovim.enable = true; # needed for vscode-neovim plugin
29+
programs.direnv = {
30+
enable = true;
31+
nix-direnv.enable = true;
32+
};
33+
}
34+
```
35+
36+
When not using direnv and its IDE integration, the IDE must be started from within the Nix Flakes devshell:
37+
```bash
38+
cd my/project
39+
nix develop
40+
codium .
41+
```
42+
43+
## Rust via NixOS
44+
45+
Cargo can also be installed globally. For this we recommend [oxalica/rust-overlay](https://github.com/oxalica/rust-overlay), a rustup-like distribution of rust within the Nix ecosystem.
46+
47+
::alert{type="info"}
48+
Try it out with `codchi init <NAME> https://github.com/aformatik/codchi nixosModules.rust`.
49+
::
50+
51+
52+
```nix
53+
{ pkgs, ... }: {
54+
55+
# https://github.com/oxalica/rust-overlay
56+
nixpkgs.overlays = [
57+
(self: super:
58+
let
59+
overlay = super.fetchFromGitHub {
60+
repo = "rust-overlay";
61+
owner = "oxalica";
62+
sha256 = "1bp1k5qla5gwh6vc50m5pcwdfxn6g703yx1i8qrjs4l7kgh3y507";
63+
rev = "573c674a3ad06e8a525263185ebef336a411d1d5";
64+
};
65+
in
66+
{
67+
inherit (import overlay self super) rust-bin;
68+
}
69+
)
70+
];
71+
72+
environment.systemPackages = [
73+
74+
pkgs.gcc
75+
76+
# https://github.com/oxalica/rust-overlay
77+
(
78+
let
79+
rustConfig = {
80+
extensions = [
81+
"rust-src"
82+
"rust-analyzer"
83+
];
84+
targets = [
85+
"x86_64-unknown-linux-gnu"
86+
"wasm32-wasi"
87+
];
88+
};
89+
in
90+
# stable
91+
pkgs.rust-bin.stable.latest.default.override rustConfig
92+
# nightly
93+
# pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override rustConfig);
94+
)
95+
96+
# You can also install IJ with plugins (experimental).
97+
# For more information see <https://github.com/NixOS/nixpkgs/tree/nixos-24.05/pkgs/applications/editors/jetbrains>
98+
(with pkgs.jetbrains; plugins.addPlugins rust-rover [
99+
"nixidea"
100+
])
101+
102+
# When using VSCode instead of RustRover
103+
# (pkgs.vscode-with-extensions.override {
104+
# vscode = pkgs.vscodium;
105+
# vscodeExtensions = with pkgs.vscode-extensions; [
106+
# rust-lang.rust-analyzer
107+
# jnoortheen.nix-ide
108+
# ];
109+
# })
110+
# pkgs.bashInteractive # fix terminal in VSCode
111+
];
112+
113+
# For proprietary apps like RustRover
114+
nixpkgs.config.allowUnfree = true;
115+
}
116+
```

nix/examples/rust/configuration.nix

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{ pkgs, ... }: {
2+
3+
# https://github.com/oxalica/rust-overlay
4+
nixpkgs.overlays = [
5+
(self: super:
6+
let
7+
overlay = super.fetchFromGitHub {
8+
repo = "rust-overlay";
9+
owner = "oxalica";
10+
sha256 = "1bp1k5qla5gwh6vc50m5pcwdfxn6g703yx1i8qrjs4l7kgh3y507";
11+
rev = "573c674a3ad06e8a525263185ebef336a411d1d5";
12+
};
13+
in
14+
{
15+
inherit (import overlay self super) rust-bin;
16+
}
17+
)
18+
];
19+
20+
environment.systemPackages = [
21+
22+
pkgs.gcc
23+
24+
# https://github.com/oxalica/rust-overlay
25+
(
26+
let
27+
rustConfig = {
28+
extensions = [
29+
"rust-src"
30+
"rust-analyzer"
31+
];
32+
targets = [
33+
"x86_64-unknown-linux-gnu"
34+
"wasm32-wasi"
35+
];
36+
};
37+
in
38+
# stable
39+
pkgs.rust-bin.stable.latest.default.override rustConfig
40+
# nightly
41+
# pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override rustConfig);
42+
)
43+
44+
# You can also install IJ with plugins (experimental).
45+
# For more information see <https://github.com/NixOS/nixpkgs/tree/nixos-24.05/pkgs/applications/editors/jetbrains>
46+
(with pkgs.jetbrains; plugins.addPlugins rust-rover [
47+
"nixidea"
48+
])
49+
50+
(pkgs.vscode-with-extensions.override {
51+
vscode = pkgs.vscodium;
52+
vscodeExtensions = with pkgs.vscode-extensions; [
53+
rust-lang.rust-analyzer
54+
jnoortheen.nix-ide
55+
];
56+
})
57+
pkgs.bashInteractive # fix terminal in VSCode
58+
];
59+
60+
# For proprietary apps like RustRover
61+
nixpkgs.config.allowUnfree = true;
62+
}

nix/examples/rust/flake.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
3+
outputs = { ... }: {
4+
nixosModules.default = import ./configuration.nix;
5+
};
6+
}

0 commit comments

Comments
 (0)