Skip to content

Instantly share code, notes, and snippets.

@lovesegfault
Created June 13, 2020 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lovesegfault/2c2c490be072227debaeb584ed32ad81 to your computer and use it in GitHub Desktop.
Save lovesegfault/2c2c490be072227debaeb584ed32ad81 to your computer and use it in GitHub Desktop.
mod nix;
use nix::NixShellTemplateBuilder;
use std::io::Write;
use std::process::Command;
use tempfile::NamedTempFile;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let rust_shell = NixShellTemplateBuilder::default()
.name("Rust")
.build_inputs(&["rust-analyzer", "cargo"][..])
.shell_hook("echo 'foo'")
.build()?
.render();
let mut tmp_shell_file = NamedTempFile::new()?;
tmp_shell_file.write_all(rust_shell.as_bytes())?;
Command::new("nix-shell")
.arg(tmp_shell_file.path())
.status()?;
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment