Skip to content

Commit

Permalink
feat: Add flake.nix for nix users
Browse files Browse the repository at this point in the history
Co-authored-by: Winter <[email protected]>
  • Loading branch information
MoritzBoehme and winterqt committed Oct 25, 2022
1 parent c923e7a commit 8e0f5bf
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
60 changes: 60 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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
];
};
});
}
6 changes: 6 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8e0f5bf

Please sign in to comment.