add some rust templates
This commit is contained in:
parent
3e22f2c3e7
commit
85dda3dbd3
@ -1,5 +1,15 @@
|
|||||||
|
# TODO: templates should be able to have initial states like
|
||||||
|
# repo name, author,...
|
||||||
{pkgs
|
{pkgs
|
||||||
,lib
|
,lib
|
||||||
,
|
,...
|
||||||
}: {
|
}: {
|
||||||
|
rust = {
|
||||||
|
path = ./rust;
|
||||||
|
description = "Minimal Rust build template using Naersk, rust-overlay, rust-analyzer";
|
||||||
|
};
|
||||||
|
rust-monorepo = {
|
||||||
|
path = ./rust-monorepo;
|
||||||
|
description = "hungtr's opinionated Rust monorepo, extended from ./rust, using Cargo workspace";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
1
templates/rust-monorepo/.envrc
Normal file
1
templates/rust-monorepo/.envrc
Normal file
@ -0,0 +1 @@
|
|||||||
|
use flake
|
||||||
13
templates/rust-monorepo/.github/workflows/build_nix.yml
vendored
Normal file
13
templates/rust-monorepo/.github/workflows/build_nix.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
name: "Build legacy Nix package on Ubuntu"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: cachix/install-nix-action@v12
|
||||||
|
- name: Building package
|
||||||
|
run: nix-build . -A defaultPackage.x86_64-linux
|
||||||
14
templates/rust-monorepo/Cargo.lock
generated
Normal file
14
templates/rust-monorepo/Cargo.lock
generated
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cli"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "core"
|
||||||
|
version = "0.1.0"
|
||||||
5
templates/rust-monorepo/Cargo.toml
Normal file
5
templates/rust-monorepo/Cargo.toml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"packages/*",
|
||||||
|
"exec/*"
|
||||||
|
]
|
||||||
7
templates/rust-monorepo/default.nix
Normal file
7
templates/rust-monorepo/default.nix
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
(import (
|
||||||
|
fetchTarball {
|
||||||
|
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
|
||||||
|
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }
|
||||||
|
) {
|
||||||
|
src = ./.;
|
||||||
|
}).defaultNix
|
||||||
1
templates/rust-monorepo/exec/cli/.gitignore
vendored
Normal file
1
templates/rust-monorepo/exec/cli/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
9
templates/rust-monorepo/exec/cli/Cargo.toml
Normal file
9
templates/rust-monorepo/exec/cli/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "cli"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
core = { version = "0.1.0", path = "../../packages/core" }
|
||||||
3
templates/rust-monorepo/exec/cli/src/main.rs
Normal file
3
templates/rust-monorepo/exec/cli/src/main.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
||||||
35
templates/rust-monorepo/flake.nix
Normal file
35
templates/rust-monorepo/flake.nix
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
inputs = {
|
||||||
|
naersk.url = "github:nix-community/naersk/master";
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
|
utils.url = "github:numtide/flake-utils";
|
||||||
|
rust-overlay = "github:oxalica/rust-overlay";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, utils, naersk, rust-overlay }:
|
||||||
|
utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
overlays = [ rust-overlay.overlays.default ];
|
||||||
|
pkgs = import nixpkgs { inherit system overlays; };
|
||||||
|
naersk-lib = pkgs.callPackage naersk { };
|
||||||
|
in
|
||||||
|
{
|
||||||
|
defaultPackage = naersk-lib.buildPackage ./.;
|
||||||
|
devShell = with pkgs; mkShell {
|
||||||
|
buildInputs = [
|
||||||
|
(pkgs.rust-bin.selectLatestNightlyWith
|
||||||
|
(
|
||||||
|
toolchain:
|
||||||
|
toolchain.default.override {
|
||||||
|
extensions = [ "rust-src" ];
|
||||||
|
}
|
||||||
|
))
|
||||||
|
pkgs.rust-analyzer
|
||||||
|
];
|
||||||
|
RUST_SRC_PATH = rustPlatform.rustLibSrc;
|
||||||
|
shellHook = ''
|
||||||
|
# nix flake update # is this even needed?
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
2
templates/rust-monorepo/packages/core/.gitignore
vendored
Normal file
2
templates/rust-monorepo/packages/core/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/target
|
||||||
|
/Cargo.lock
|
||||||
8
templates/rust-monorepo/packages/core/Cargo.toml
Normal file
8
templates/rust-monorepo/packages/core/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "core"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
14
templates/rust-monorepo/packages/core/src/lib.rs
Normal file
14
templates/rust-monorepo/packages/core/src/lib.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
pub fn add(left: usize, right: usize) -> usize {
|
||||||
|
left + right
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
let result = add(2, 2);
|
||||||
|
assert_eq!(result, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
7
templates/rust-monorepo/shell.nix
Normal file
7
templates/rust-monorepo/shell.nix
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
(import (
|
||||||
|
fetchTarball {
|
||||||
|
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
|
||||||
|
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }
|
||||||
|
) {
|
||||||
|
src = ./.;
|
||||||
|
}).shellNix
|
||||||
1
templates/rust/.envrc
Normal file
1
templates/rust/.envrc
Normal file
@ -0,0 +1 @@
|
|||||||
|
use flake
|
||||||
13
templates/rust/.github/workflows/build_nix.yml
vendored
Normal file
13
templates/rust/.github/workflows/build_nix.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
name: "Build legacy Nix package on Ubuntu"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: cachix/install-nix-action@v12
|
||||||
|
- name: Building package
|
||||||
|
run: nix-build . -A defaultPackage.x86_64-linux
|
||||||
7
templates/rust/default.nix
Normal file
7
templates/rust/default.nix
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
(import (
|
||||||
|
fetchTarball {
|
||||||
|
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
|
||||||
|
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }
|
||||||
|
) {
|
||||||
|
src = ./.;
|
||||||
|
}).defaultNix
|
||||||
35
templates/rust/flake.nix
Normal file
35
templates/rust/flake.nix
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
inputs = {
|
||||||
|
naersk.url = "github:nix-community/naersk/master";
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
|
utils.url = "github:numtide/flake-utils";
|
||||||
|
rust-overlay = "github:oxalica/rust-overlay";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, utils, naersk, rust-overlay }:
|
||||||
|
utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
overlays = [ rust-overlay.overlays.default ];
|
||||||
|
pkgs = import nixpkgs { inherit system overlays; };
|
||||||
|
naersk-lib = pkgs.callPackage naersk { };
|
||||||
|
in
|
||||||
|
{
|
||||||
|
defaultPackage = naersk-lib.buildPackage ./.;
|
||||||
|
devShell = with pkgs; mkShell {
|
||||||
|
buildInputs = [
|
||||||
|
(pkgs.rust-bin.selectLatestNightlyWith
|
||||||
|
(
|
||||||
|
toolchain:
|
||||||
|
toolchain.default.override {
|
||||||
|
extensions = [ "rust-src" ];
|
||||||
|
}
|
||||||
|
))
|
||||||
|
pkgs.rust-analyzer
|
||||||
|
];
|
||||||
|
RUST_SRC_PATH = rustPlatform.rustLibSrc;
|
||||||
|
shellHook = ''
|
||||||
|
# nix flake update # is this even needed?
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
7
templates/rust/shell.nix
Normal file
7
templates/rust/shell.nix
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
(import (
|
||||||
|
fetchTarball {
|
||||||
|
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
|
||||||
|
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }
|
||||||
|
) {
|
||||||
|
src = ./.;
|
||||||
|
}).shellNix
|
||||||
Loading…
Reference in New Issue
Block a user