Skip to content

Commit 8e0f5bf

Browse files
feat: Add flake.nix for nix users
Co-authored-by: Winter <winter@winter.cafe>
1 parent c923e7a commit 8e0f5bf

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ curl -L https://raw.githubusercontent.com/rust-lang/rustlings/main/install.sh |
2828

2929
This will install Rustlings and give you access to the `rustlings` command. Run it to get started!
3030

31+
### Nix
32+
Basically: Clone the repository at the latest tag, finally run `nix develop` or `nix-shell`.
33+
34+
```bash
35+
# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.2.1)
36+
git clone -b 5.2.1 --depth 1 https://github.com/rust-lang/rustlings
37+
cd rustlings
38+
# if nix version > 2.3
39+
nix develop
40+
# if nix version <= 2.3
41+
nix-shell
42+
```
43+
3144
## Windows
3245

3346
In PowerShell (Run as Administrator), set `ExecutionPolicy` to `RemoteSigned`:

flake.lock

Lines changed: 60 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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
description = "Small exercises to get you used to reading and writing Rust code";
3+
4+
inputs = {
5+
flake-compat = {
6+
url = "github:edolstra/flake-compat";
7+
flake = false;
8+
};
9+
flake-utils.url = "github:numtide/flake-utils";
10+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
11+
};
12+
13+
outputs = { self, flake-utils, nixpkgs, ... }:
14+
flake-utils.lib.eachDefaultSystem (system:
15+
let
16+
pkgs = nixpkgs.legacyPackages.${system};
17+
rustlings =
18+
pkgs.rustPlatform.buildRustPackage {
19+
name = "rustlings";
20+
version = "5.2.1";
21+
22+
src = with pkgs.lib; cleanSourceWith {
23+
src = self;
24+
# a function that returns a bool determining if the path should be included in the cleaned source
25+
filter = path: type:
26+
let
27+
# filename
28+
baseName = builtins.baseNameOf (toString path);
29+
# path from root directory
30+
path' = builtins.replaceStrings [ "${self}/" ] [ "" ] path;
31+
# checks if path is in the directory
32+
inDirectory = directory: hasPrefix directory path';
33+
in
34+
inDirectory "src" ||
35+
inDirectory "tests" ||
36+
hasPrefix "Cargo" baseName ||
37+
baseName == "info.toml";
38+
};
39+
40+
cargoLock.lockFile = ./Cargo.lock;
41+
};
42+
in
43+
{
44+
devShell = pkgs.mkShell {
45+
buildInputs = with pkgs; [
46+
cargo
47+
rustc
48+
rust-analyzer
49+
rustlings
50+
];
51+
};
52+
});
53+
}

shell.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(import (let lock = builtins.fromJSON (builtins.readFile ./flake.lock);
2+
in fetchTarball {
3+
url =
4+
"https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
5+
sha256 = lock.nodes.flake-compat.locked.narHash;
6+
}) { src = ./.; }).shellNix

0 commit comments

Comments
 (0)