diff --git a/dot_config/private_fish/functions/dev-remove.fish b/dot_config/private_fish/functions/dev-remove.fish new file mode 100644 index 0000000..6893c4f --- /dev/null +++ b/dot_config/private_fish/functions/dev-remove.fish @@ -0,0 +1,3 @@ +function dev-remove + distrobox rm --force dev +end diff --git a/dot_config/private_fish/functions/dev.fish b/dot_config/private_fish/functions/dev.fish index c81fbf1..8916937 100644 --- a/dot_config/private_fish/functions/dev.fish +++ b/dot_config/private_fish/functions/dev.fish @@ -36,48 +36,16 @@ function dev echo "Creating Distrobox container '$name'..." - set -l init_hook ' - set -e - - echo "Initializing development environment..." - - sudo mkdir -p /opt/rustup /opt/cargo - sudo chown -R $USER:$USER /opt/rustup /opt/cargo - - sudo mkdir -p /etc/fish/conf.d /etc/fish/completions - - printf "%s\n" \ - "set -gx RUSTUP_HOME /opt/rustup" \ - "set -gx CARGO_HOME /opt/cargo" \ - "fish_add_path \$CARGO_HOME/bin /home/user/.local/bin" \ - | sudo tee /etc/fish/conf.d/rust.fish >/dev/null - - export RUSTUP_HOME=/opt/rustup - export CARGO_HOME=/opt/cargo - - curl --proto "=https" \ - --tlsv1.2 \ - -sSf https://sh.rustup.rs \ - | sh -s -- -y --no-modify-path - - /opt/cargo/bin/rustup default stable - - /opt/cargo/bin/rustup completions fish \ - | sudo tee /etc/fish/completions/rustup.fish >/dev/null - - echo "Development environment initialized successfully." - ' - distrobox create \ --name $name \ --image $image --yes \ --additional-packages (string join ' ' $packages) \ - --init-hooks "$init_hook" + --init-hooks 'bash "$HOME/.scripts/distrobox-dev-init.sh"' if test $status -ne 0 echo "Failed to create container '$name'." >&2 return 1 end - distrobox enter $name + distrobox enter $name --verbose end diff --git a/dot_scripts/executable_distrobox-dev-init.sh b/dot_scripts/executable_distrobox-dev-init.sh new file mode 100644 index 0000000..8925923 --- /dev/null +++ b/dot_scripts/executable_distrobox-dev-init.sh @@ -0,0 +1,123 @@ +#!/usr/bin/env bash + +set -euo pipefail + +echo "Initializing development environment..." + +# ----------------------------------------------------------------------------- +# Rust directories +# ----------------------------------------------------------------------------- + +mkdir -p /opt/rustup /opt/cargo +chown "$(id -u):$(id -g)" /opt/rustup /opt/cargo + +# ----------------------------------------------------------------------------- +# Fish configuration +# ----------------------------------------------------------------------------- + +mkdir -p /etc/fish/conf.d +mkdir -p /etc/fish/completions + +tee /etc/fish/conf.d/rust.fish >/dev/null <<'EOF' +set -gx RUSTUP_HOME /opt/rustup +set -gx CARGO_HOME /opt/cargo +fish_add_path $CARGO_HOME/bin +EOF + +# ----------------------------------------------------------------------------- +# Rustup +# ----------------------------------------------------------------------------- + +export RUSTUP_HOME=/opt/rustup +export CARGO_HOME=/opt/cargo + +echo "Installing rustup..." + +curl \ + --proto '=https' \ + --tlsv1.2 \ + -sSf \ + https://sh.rustup.rs \ + | sh -s -- -y --no-modify-path + +# ----------------------------------------------------------------------------- +# Rust toolchain +# ----------------------------------------------------------------------------- + +echo "Installing stable Rust toolchain..." + +/opt/cargo/bin/rustup default stable + +# ----------------------------------------------------------------------------- +# Fish completions +# ----------------------------------------------------------------------------- + +echo "Installing rustup Fish completion..." + +/opt/cargo/bin/rustup completions fish \ + | tee /etc/fish/completions/rustup.fish >/dev/null + +# ----------------------------------------------------------------------------- +# Export Rust development tools to the host +# ----------------------------------------------------------------------------- +export PATH="/opt/cargo/bin:$PATH" +echo "Exporting development tools..." + +DEV_HOME="$HOME" +DEV_USER="$(basename "$DEV_HOME")" + +export_bin() { + local binary="$1" + + if command -v "$binary" >/dev/null 2>&1; then + echo " exporting $binary" + sudo -u "$DEV_USER" \ + env HOME="$DEV_HOME" \ + distrobox-export \ + --bin "$(command -v "$binary")" \ + --export-path "$DEV_HOME/.local/bin" + else + echo " warning: $binary not found" + fi +} + +# Rust +for binary in \ + cargo \ + cargo-clippy \ + cargo-fmt \ + cargo-miri \ + clippy-driver \ + rls \ + rust-analyzer \ + rustc \ + rustdoc \ + rustfmt \ + rust-gdb \ + rust-gdbgui \ + rust-lldb \ + rustup +do + export_bin "$binary" +done + +# Native toolchain +export_bin clang +export_bin clang++ +export_bin cmake +export_bin lld +export_bin ld.lld +export_bin gdb +export_bin strace + +# ----------------------------------------------------------------------------- +# Done +# ----------------------------------------------------------------------------- + +echo +echo "Development environment initialized successfully." +echo +echo "Rust:" +/opt/cargo/bin/rustc --version +/opt/cargo/bin/cargo --version +/opt/cargo/bin/rustup --version