Nix-shell shebang: Difference between revisions
imported>Milahu add section: Performance |
imported>Artturin add rust |
||
| Line 55: | Line 55: | ||
print(ansicolor.green(f"done {path}")) | print(ansicolor.green(f"done {path}")) | ||
</syntaxHighlight> | </syntaxHighlight> | ||
=== Rust === | |||
==== No dependencies ==== | |||
<syntaxHighlight lang="bash"> | |||
#!/usr/bin/env nix-shell | |||
#![allow()] /* | |||
#!nix-shell -i bash -p rustc | |||
rsfile="$(readlink -f $0)" | |||
binfile="/tmp/$(basename "$rsfile").bin" | |||
rustc "$rsfile" -o "$binfile" --edition=2021 && exec "$binfile" $@ || exit $? | |||
*/ | |||
fn main() { | |||
for argument in std::env::args().skip(1) { | |||
println!("{}", argument); | |||
}; | |||
println!("{}", std::env::var("HOME").expect("")); | |||
} | |||
</syntaxHighlight> | |||
==== With dependencies ==== | |||
uses [https://github.com/fornwall/rust-script rust-script] | |||
<syntaxHighlight lang="bash"> | |||
#!/usr/bin/env nix-shell | |||
//! ```cargo | |||
//! [dependencies] | |||
//! time = "0.1.25" | |||
//! ``` | |||
/* | |||
#!nix-shell -i rust-script -p rustc -p rust-script -p cargo | |||
*/ | |||
fn main() { | |||
for argument in std::env::args().skip(1) { | |||
println!("{}", argument); | |||
}; | |||
println!("{}", std::env::var("HOME").expect("")); | |||
println!("{}", time::now().rfc822z()); | |||
} | |||
</syntaxHighlight> | |||
== Pinning nixpkgs == | == Pinning nixpkgs == | ||