feat: Add flake.nix for nix users

Co-authored-by: Winter <winter@winter.cafe>
This commit is contained in:
Moritz Böhme 2022-01-25 11:47:16 +01:00
parent c923e7af73
commit 8e0f5bf125
No known key found for this signature in database
GPG key ID: 970C6E89EB0547A9
4 changed files with 132 additions and 0 deletions

View file

@ -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`:

60
flake.lock Normal file
View file

@ -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
}

53
flake.nix Normal file
View file

@ -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
shell.nix Normal file
View file

@ -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