summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md13
-rw-r--r--flake.lock60
-rw-r--r--flake.nix53
-rw-r--r--shell.nix6
4 files changed, 132 insertions, 0 deletions
diff --git a/README.md b/README.md
index 4e0bbf0..38972a4 100644
--- a/README.md
+++ b/README.md
@@ -28,6 +28,19 @@ curl -L https://raw.githubusercontent.com/rust-lang/rustlings/main/install.sh |
This will install Rustlings and give you access to the `rustlings` command. Run it to get started!
+### Nix
+Basically: Clone the repository at the latest tag, finally run `nix develop` or `nix-shell`.
+
+```bash
+# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.2.1)
+git clone -b 5.2.1 --depth 1 https://github.com/rust-lang/rustlings
+cd rustlings
+# if nix version > 2.3
+nix develop
+# if nix version <= 2.3
+nix-shell
+```
+
## Windows
In PowerShell (Run as Administrator), set `ExecutionPolicy` to `RemoteSigned`:
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..ceb62c6
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,60 @@
+{
+ "nodes": {
+ "flake-compat": {
+ "flake": false,
+ "locked": {
+ "lastModified": 1650374568,
+ "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=",
+ "owner": "edolstra",
+ "repo": "flake-compat",
+ "rev": "b4a34015c698c7793d592d66adbab377907a2be8",
+ "type": "github"
+ },
+ "original": {
+ "owner": "edolstra",
+ "repo": "flake-compat",
+ "type": "github"
+ }
+ },
+ "flake-utils": {
+ "locked": {
+ "lastModified": 1659877975,
+ "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1666629043,
+ "narHash": "sha256-Yoq6Ut2F3Ol73yO9hG93x6ts5c4F5BhKTbcF3DtBEAw=",
+ "owner": "nixos",
+ "repo": "nixpkgs",
+ "rev": "b39fd6e4edef83cb4a135ebef98751ce23becc33",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nixos",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "flake-compat": "flake-compat",
+ "flake-utils": "flake-utils",
+ "nixpkgs": "nixpkgs"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..15c82b7
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,53 @@
+{
+ description = "Small exercises to get you used to reading and writing Rust code";
+
+ inputs = {
+ flake-compat = {
+ url = "github:edolstra/flake-compat";
+ flake = false;
+ };
+ flake-utils.url = "github:numtide/flake-utils";
+ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+ };
+
+ outputs = { self, flake-utils, nixpkgs, ... }:
+ flake-utils.lib.eachDefaultSystem (system:
+ let
+ pkgs = nixpkgs.legacyPackages.${system};
+ rustlings =
+ pkgs.rustPlatform.buildRustPackage {
+ name = "rustlings";
+ version = "5.2.1";
+
+ src = with pkgs.lib; cleanSourceWith {
+ src = self;
+ # a function that returns a bool determining if the path should be included in the cleaned source
+ filter = path: type:
+ let
+ # filename
+ baseName = builtins.baseNameOf (toString path);
+ # path from root directory
+ path' = builtins.replaceStrings [ "${self}/" ] [ "" ] path;
+ # checks if path is in the directory
+ inDirectory = directory: hasPrefix directory path';
+ in
+ inDirectory "src" ||
+ inDirectory "tests" ||
+ hasPrefix "Cargo" baseName ||
+ baseName == "info.toml";
+ };
+
+ cargoLock.lockFile = ./Cargo.lock;
+ };
+ in
+ {
+ devShell = pkgs.mkShell {
+ buildInputs = with pkgs; [
+ cargo
+ rustc
+ rust-analyzer
+ rustlings
+ ];
+ };
+ });
+}
diff --git a/shell.nix b/shell.nix
new file mode 100644
index 0000000..fa2a56c
--- /dev/null
+++ b/shell.nix
@@ -0,0 +1,6 @@
+(import (let lock = builtins.fromJSON (builtins.readFile ./flake.lock);
+in fetchTarball {
+ url =
+ "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
+ sha256 = lock.nodes.flake-compat.locked.narHash;
+}) { src = ./.; }).shellNix