Skip to content

Instantly share code, notes, and snippets.

@ivan
Last active November 14, 2020 03:51
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 ivan/4cfdb64f96cde53c14be764b34c25e5f to your computer and use it in GitHub Desktop.
Save ivan/4cfdb64f96cde53c14be764b34c25e5f to your computer and use it in GitHub Desktop.
Script to update rust nightly and recompile all of your projects
#!/usr/bin/env bash
set -eu -o pipefail
# --force to reinstall in case we updated NixOS and GC'ed old paths, but no new nightly is available
rustup update --force
rustup default nightly
# List most-used projects first so that they're available sooner
projects=(
~/code/rust/rust-analyzer
~/code/rust/something
~/code/rust/else
)
for p in "${projects[@]}"; do
echo $p
cd "$p" || continue
# Remove files older than 2 days from target/ because otherwise it grows
# to many GB as target/*/deps has builds for each Rust release
find target -type f -mtime +2 -delete || true
cargo build --release || true
if [[ $p = ~/code/rust/rust-analyzer ]]; then
# Custom install procedure for rust-analyzer
cp -alf ./target/release/rust-analyzer ~/bin/_rust-analyzer
else
cargo build || true
cargo test || true
fi
done
@ivan
Copy link
Author

ivan commented Nov 14, 2020

To run it nightly on NixOS, use configuration

{
  systemd.services.update-rust = {
    description = "Update Rust and rebuild projects";
    serviceConfig = {
      Type = "oneshot";
      User = "USERNAME";
      Environment = "PATH=/home/USERNAME/bin:/run/current-system/sw/bin";
    };
    # 04:00 PST is 12:00 UTC
    startAt = "12:00";
    script = ''
      update-rust
    '';
  };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment