add a flake template for rust binaries

This commit is contained in:
Colin 2023-04-26 07:20:02 +00:00
parent 44195a7d87
commit af394b315e
6 changed files with 131 additions and 0 deletions

View File

@ -290,6 +290,12 @@
path = ./templates/python-data;
description = "python environment for data processing";
};
rust = {
# initialize with:
# - `nix flake init -t '/home/colin/dev/nixos/#rust'`
path = ./templates/rust;
description = "rust package and development environment";
};
};
};
}

7
templates/rust/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "example-rust-pkg"
version = "0.1.0"

View File

@ -0,0 +1,8 @@
[package]
name = "example-rust-pkg"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

60
templates/rust/flake.lock Normal file
View File

@ -0,0 +1,60 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1681202837,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1682173319,
"narHash": "sha256-tPhOpJJ+wrWIusvGgIB2+x6ILfDkEgQMX0BTtM5vd/4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "ee7ec1c71adc47d2e3c2d5eb0d6b8fbbd42a8d1c",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-22.11",
"type": "indirect"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

45
templates/rust/flake.nix Normal file
View File

@ -0,0 +1,45 @@
{
description = "TODO: FILLME: description";
inputs = {
nixpkgs.url = "nixpkgs/nixos-22.11";
flake-utils.url = github:numtide/flake-utils;
};
outputs = { self, nixpkgs, flake-utils }:
with flake-utils.lib; eachSystem allSystems (system:
let
pkgs = import nixpkgs {
inherit system;
};
nativeBuildInputs = with pkgs; [
pkg-config
];
buildInputs = with pkgs; [
openssl
];
in rec {
packages = {
# docs: <nixpkgs>/doc/languages-frameworks/rust.section.md
example-rust-pkg = pkgs.rustPlatform.buildRustPackage {
name = "example-rust-pkg";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
# enables debug builds, if we want: https://github.com/NixOS/nixpkgs/issues/60919.
hardeningDisable = [ "fortify" ];
inherit buildInputs nativeBuildInputs;
};
};
defaultPackage = packages.example-rust-pkg;
devShells.default = with pkgs; mkShell {
# enables debug builds, if we want: https://github.com/NixOS/nixpkgs/issues/60919.
hardeningDisable = [ "fortify" ];
# Allow cargo to download crates.
SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
inherit buildInputs;
nativeBuildInputs = [ cargo ] ++ nativeBuildInputs;
};
});
}

View File

@ -0,0 +1,5 @@
//! hello world
pub fn main() {
println!("hello, world!");
}