feat: add a few ways to easily run/author small rust packages
All checks were successful
/ build-host (map[host:beefcake]) (push) Successful in 34s
/ build-host (map[host:dragon]) (push) Successful in 47s
/ build-host (map[host:flipflop]) (push) Successful in 39s
/ build-host (map[host:foxtrot]) (push) Successful in 45s
/ build-host (map[host:rascal]) (push) Successful in 19s
/ build-host (map[host:router]) (push) Successful in 37s
/ build-host (map[host:steamdeck]) (push) Successful in 44s
/ build-devshell (push) Successful in 18s
/ flake-check (push) Successful in 5m48s

This commit is contained in:
Daniel Flanagan 2025-03-29 21:28:40 -05:00
parent a76394b643
commit eb0a6757cd
7 changed files with 54 additions and 2 deletions

View file

@ -18,8 +18,9 @@ let
];
*/
cargoHash = pkgs.lib.fakeHash;
useFetchCargoVendor = true;
cargoLock = {
lockFile = ./Cargo.lock;
};
};
in
{

View file

@ -9,4 +9,8 @@ in
# installer = pkgs.callPackage ./installer.nix { };
ghostty-terminfo = pkgs.callPackage ./ghostty-terminfo.nix { };
forgejo-actions-container = pkgs.callPackage ./forgejo-actions-container.nix { };
hello_world = pkgs.callPackage ./rust/hello_world { };
hello_world_script = pkgs.writeScriptBin "hello_world_script" (
builtins.readFile ./rust/hello_world_script/main.rs
);
}

7
packages/rust/hello_world/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 = 4
[[package]]
name = "hello_world"
version = "0.1.0"

View file

@ -0,0 +1,6 @@
[package]
name = "hello_world"
version = "0.1.0"
edition = "2024"
[dependencies]

View file

@ -0,0 +1,16 @@
{
rustPlatform,
}:
let
inherit (builtins) fromTOML readFile;
pname = "hello_world";
src = ./.;
package = rustPlatform.buildRustPackage {
inherit pname src;
version = (fromTOML (readFile "${src}/Cargo.toml")).package.version;
cargoLock = {
lockFile = ./Cargo.lock;
};
};
in
package

View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

View file

@ -0,0 +1,15 @@
#!/usr/bin/env nix
//! ```cargo
//! [dependencies]
//! time = "0.1.25"
//! ```
/*
#!nix shell nixpkgs#rustc nixpkgs#rust-script nixpkgs#cargo --command rust-script
*/
fn main() {
for argument in std::env::args().skip(1) {
println!("{}", argument);
}
println!("{}", std::env::var("HOME").expect(""));
println!("{}", time::now().rfc822z());
}