Skip to content

Commit 574b786

Browse files
authored
Initial commit
0 parents  commit 574b786

15 files changed

+248
-0
lines changed

Diff for: .clippy.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# see https://doc.rust-lang.org/stable/clippy/configuration.html
2+
# see https://rust-lang.github.io/rust-clippy/master/index.html#Configuration

Diff for: .editorconfig

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[*]
2+
indent_size = 2
3+
indent_style = space
4+
trim_trailing_whitespace = true
5+
insert_final_newline = true
6+
charset = utf-8
7+
8+
[*.rs]
9+
indent_size = 4
10+
11+
[*.py]
12+
indent_size = 4
13+
14+
[Makefile]
15+
indent_style = tab
16+
17+
[*.go]
18+
indent_style = tab
19+

Diff for: .envrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
export COLORTERM=truecolor
3+
use flake
4+
export RUST_BACKTRACE=1

Diff for: .gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flake.lock linguist-generated=true

Diff for: .gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.direnv
2+
target
3+
result*
4+
# ./result* is owned by `nix build`.
5+
# see https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-build

Diff for: .rustfmt.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://rust-lang.github.io/rustfmt/
2+
newline_style = "Unix"
3+
use_try_shorthand = true

Diff for: .shellcheckrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
external-sources=true
2+
source-path=SCRIPTDIR

Diff for: .vscode/settings.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"nixEnvSelector.nixFile": "${workspaceRoot}/flake.nix",
4+
"nix.enableLanguageServer": true,
5+
"nix.serverPath": "nil"
6+
}

Diff for: Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "rust-nix-project-template"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

Diff for: flake.lock

+85
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: flake.nix

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
description = ""; # FIXME: add a description
3+
inputs = {
4+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; # TODO: pin
5+
flake-utils.url = "github:numtide/flake-utils"; # TODO: pin
6+
rust-overlay = {
7+
url = "github:oxalica/rust-overlay"; # TODO: pin;
8+
inputs.flake-utils.follows = "flake-utils";
9+
inputs.nixpkgs.follows = "nixpkgs";
10+
};
11+
};
12+
13+
outputs = { self, flake-utils, nixpkgs, rust-overlay }:
14+
flake-utils.lib.eachDefaultSystem (system:
15+
let
16+
overlays = [ (import rust-overlay) ];
17+
pkgs = (import nixpkgs) {
18+
inherit system overlays;
19+
};
20+
# Generate a user-friendly version number.
21+
version = builtins.substring 0 8 self.lastModifiedDate;
22+
rust_toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
23+
info = (builtins.fromTOML (builtins.readFile ./Cargo.toml));
24+
filters = import ./nix/filter_filesets.nix { inherit (pkgs) lib; };
25+
in
26+
{
27+
packages = {
28+
# For `nix build` & `nix run`:
29+
default = pkgs.rustPlatform.buildRustPackage {
30+
# https://nixos.org/manual/nixpkgs/stable/#compiling-rust-applications-with-cargo
31+
inherit version;
32+
pname = info.package.name;
33+
src = pkgs.lib.fileset.toSource {
34+
root = ./. ;
35+
fileset = filters.rust ./. ;
36+
# ^ see https://johns.codes/blog/efficient-nix-derivations-with-file-sets
37+
# see https://github.com/JRMurr/roc2nix/blob/main/lib/languageFilters.nix
38+
};
39+
cargoLock = {
40+
lockFile = ./Cargo.lock;
41+
};
42+
nativeBuildInputs = [ rust_toolchain ];
43+
};
44+
};
45+
# For `nix develop`:
46+
devShell = pkgs.mkShell {
47+
# see https://github.com/NixOS/nixpkgs/issues/52447
48+
# see https://hoverbear.org/blog/rust-bindgen-in-nix/
49+
# see https://slightknack.dev/blog/nix-os-bindgen/
50+
# https://nixos.wiki/wiki/Rust#Installation_via_rustup
51+
nativeBuildInputs = [ rust_toolchain ];
52+
buildInputs = with pkgs;
53+
[
54+
# rust tools
55+
rust-analyzer-unwrapped
56+
cargo-bloat
57+
58+
# nix support
59+
nixpkgs-fmt
60+
nil
61+
62+
# other
63+
lychee
64+
shellcheck
65+
git
66+
bashInteractive
67+
];
68+
69+
# Environment variables
70+
RUST_SRC_PATH = "${rust_toolchain}/lib/rustlib/src/rust/library";
71+
};
72+
}
73+
);
74+
}

Diff for: nix/filter_filesets.nix

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# adapted from https://github.com/JRMurr/roc2nix/blob/main/lib/languageFilters.nix
2+
{ lib }:
3+
4+
# common file sets for different languages
5+
# https://nix.dev/tutorials/file-sets
6+
# https://nixos.org/manual/nixpkgs/unstable/#sec-functions-library-fileset
7+
with lib.fileset;
8+
9+
let
10+
11+
fileHasAnySuffix = fileSuffixes: file: (lib.lists.any (s: lib.hasSuffix s file.name) fileSuffixes);
12+
13+
rust = basePath: (
14+
let
15+
mainFilter = fileFilter
16+
(fileHasAnySuffix [ ".rs" "Cargo.toml"])
17+
basePath;
18+
in
19+
unions [ mainFilter (basePath + "/Cargo.toml") (basePath + "/Cargo.lock") ]
20+
);
21+
in
22+
{
23+
inherit rust;
24+
}

Diff for: rust-toolchain.toml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# see https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file
2+
[toolchain]
3+
channel = "stable"
4+
components = ["rustfmt", "clippy", "rust-src"]
5+
targets = []

Diff for: src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

0 commit comments

Comments
 (0)