allenap / firstaide Goto Github PK
View Code? Open in Web Editor NEWBootstrap tool for Nix environments. See NoRedInk's firstaide repo for future development! https://github.com/NoRedInk/firstaide
Bootstrap tool for Nix environments. See NoRedInk's firstaide repo for future development! https://github.com/NoRedInk/firstaide
2.20.x seems to have some weird behaviour that's confusing and results in broken environments.
Perhaps give advice to users along the lines of:
direnv is too old (2.20.2); upgrade to 2.21.2 or later.
Nix: `nix-channel --update && nix-env --install direnv && nix-env --upgrade direnv`
Homebrew: `brew update && brew install direnv && brew upgrade direnv`
Nix itself doesn't have a story for saying "I want some project specific options", but firstaide could do something useful with NIX_CONF_DIR
to make it work.
Quick idea: firstaide could write out a nix.conf in some situations:
Global NIX_CONF_DIR |
Project-specific NIX_CONF_DIR |
What do to |
---|---|---|
unset | unset | Nothing |
unset | project/etc | Write new nix.conf: include /etc/nix , include project/etc |
/some/thing | unset | Nothing |
/some/thing | project/etc | Write new nix.conf: include /some/thing , include project/etc |
Why include /etc/nix
? From nix.conf(5): 'this is the "system-wide configuration file sysconfdir/nix/nix.conf
'. It doesn't seem possible or at least obvious how to find out what Nix's notion of sysconfdir
is, so we assume it's /etc
for now.
We can probably cache recently-used environments based on dependency checksums (i.e. of those files yielded from watch_exe
). This might make life easier when switching branches.
What the title says! It would be nice to give a project specific help message here.
firstaide/src/cmds/hook/active.sh
Line 4 in 0c8ef2d
Nix shells and GC equals frustration. Below are my notes so far. I've managed to find a 95% solution or something like that; see DO THIS ONE
.
// 3c. Capture the environment's closure to prevent GC.
// nix-build --no-out-link stuff.nix | xargs -r nix-store -qR | \
// xargs -r nix-store --realise --add-root _build/firstaide/gc/$random --indirect
// log::info!("Capture closure of inside environment to prevent GC.");
// let gcroot_dir = &config.cache_dir.join("gc");
// fs::create_dir(gcroot_dir)?;
// let gcroot_output = process::Command::new("nix-build")
// .current_dir(&config.build_dir)
// .arg("--no-out-link")
// .arg("stuff.nix")
// .stdin(process::Stdio::null())
// .stdout(process::Stdio::piped())
// .stderr(process::Stdio::inherit())
// .output()?;
// let gcroot_inputs: Vec<&[u8]> = gcroot_output.stdout.fields().collect();
// Another approach?
// nix-instantiate shell.nix --add-root gc/shell --indirect
// nix-store -r gc/shell --add-root gc/root --indirect
// An approach that seems to work: *** DO THIS ONE ***
// nix-instantiate shell.nix --add-root _build/firstaide/shell --indirect
// nix-shell _build/firstaide/shell --run 'firstaide env ...'
// ALSO: Check that user has `keep-outputs` enabled. <-- IMPORTANT
// 3c. Add a GC root for this environment. This alone is not enough to
// ensure that the environment and its constituents are not garbage
// collected – Nix does *not* make this easy – but if we also check if users
// have `keep-outputs` enabled in their configuration then we're fairly
// close: Nix will only think it needs to GC a couple of dozen packages.
log::info!("Capture closure of inside environment to prevent GC.");
let gcroot_dir = &config.cache_dir.join("gc");
fs::create_dir(gcroot_dir)?;
let gcroot_output = process::Command::new("nix-build")
.current_dir(&config.build_dir)
.arg("--no-out-link")
.arg("stuff.nix")
.stdin(process::Stdio::null())
.stdout(process::Stdio::piped())
.stderr(process::Stdio::inherit())
.output()?;
let gcroot_inputs: Vec<&[u8]> = gcroot_output.stdout.fields().collect();
// let gcroot_dir = tempfile::TempDir::new_in(
// let gcroot_path = temp_path.join("inside");
// let mut dump_cmd = config.command_to_dump_env_inside(&dump_path, &env_outside);
// log::debug!("{:?}", dump_cmd);
// let mut dump_proc = dump_cmd.spawn()?;
// if !dump_proc.wait()?.success() {
// return Err(Error::EnvInsideCapture);
// }
// match bincode::deserialize(&fs::read(dump_path)?) {
// Ok(env) => Ok(env),
// Err(err) => Err(Error::EnvInsideDecode(err)),
// }
I wonder if it's possible to have a firstaide dwim
command (that Does What I Mean) that's also the default when firstaide
is invoked without arguments:
firstaide [dwim]
-> firstaide build
..envrc
, firstaide [dwim]
-> firstaide hook
.Calling watch_file
in direnv is slow, about 7-8ms per call for a single file.
However, we insist on direnv 2.20.1 (see check_direnv_version
) which has an implementation of watch_file
that can take multiple arguments. This is much faster: adding ~50 watches can take as little as 12ms.
We should do that.
firstaide exec -- some-command --with-args
should ensure a built environment then exec some-command --with-args
inside that environment, using the cache if possible of course.
Maybe hide DEBUG logs for now, allow INFO, but add --verbose
and --quiet
flags to change it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.