Skip to content

Commit d14bdde

Browse files
committed
Upgrade asdf to golang version
1 parent 921b948 commit d14bdde

File tree

8 files changed

+113
-4
lines changed

8 files changed

+113
-4
lines changed

.config/home-manager/home.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555
historySubstringSearch.enable = true;
5656
shellAliases = userConfig.alias;
5757
initContent = ''
58-
. "${pkgs.asdf-vm}/share/asdf-vm/asdf.sh"
59-
. "${pkgs.asdf-vm}/share/asdf-vm/completions/asdf.bash"
58+
export PATH="${ASDF_DATA_DIR:-$HOME/.asdf}/shims:$PATH"
6059
'';
6160

6261
oh-my-zsh = {

.devcontainer/devcontainer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"version": "latest",
1919
"extraNixConfig": "filter-syscalls = false,sandbox = false,experimental-features = nix-command flakes"
2020
},
21+
"./local-features/asdf-go": {
22+
"version": "latest"
23+
},
2124
"./local-features/remote-tunnel": {
2225
"version": "latest"
2326
}
@@ -26,6 +29,7 @@
2629
"overrideFeatureInstallOrder": [
2730
"ghcr.io/devcontainers/features/common-utils",
2831
"ghcr.io/devcontainers/features/nix",
32+
"./local-features/asdf-go",
2933
"./local-features/remote-tunnel"
3034
],
3135

.devcontainer/first-run-notice.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
💡 Useful tips:
66
- Run `hms --flake <flake-uri>` to switch into a new generation.
7-
- Run `asdf list` to show installed packages, `asdf global <name> <version>` to set the package global version.
7+
- Run `asdf list` to show installed packages, `asdf set -u <name> <version>` to set the package global version.
88
- Run `code-cli tunnel service install` and follow the instructions to enable remote tunnel.

.devcontainer/first-run-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,6 @@ mkdir -p "$HOME/projects"
197197

198198
echo "Installing asdf plugins and packages..."
199199
# Install asdf plugins and packages from .tool-versions file
200+
sudo /bin/bash "$HOME/.codespaces/.devcontainer/local-features/asdf-go/install-asdf-go.sh"
200201
ln -sf "$HOME/.codespaces/.tool-versions" "$HOME/.tool-versions"
201202
cut -d ' ' -f1 "$HOME/.tool-versions" | xargs -I {} sh -c 'echo "Installing {}..."; asdf plugin add {} && asdf install {}'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"id": "asdf-go",
3+
"version": "1.1.1",
4+
"name": "ASDF-Go",
5+
"documentationURL": "https://asdf-vm.com/guide/getting-started.html",
6+
"description": "Install the multiple runtime version manager."
7+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
set -e
3+
4+
if [ "$(id -u)" -ne 0 ]; then
5+
echo -e 'Script must be run as root. Use sudo or switch to root before running this script.'
6+
exit 1
7+
fi
8+
9+
get_latest_release() {
10+
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
11+
grep '"tag_name":' | # Get tag line
12+
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
13+
}
14+
15+
platform="$(uname)"
16+
architecture="$(uname -m)"
17+
release=$(get_latest_release "asdf-vm/asdf")
18+
19+
if [ "$platform" = "Linux" ]; then
20+
platform="linux"
21+
elif [ "$platform" = "Darwin" ]; then
22+
platform="darwin"
23+
fi
24+
25+
case "$architecture" in
26+
x86_64 | amd64) architecture="amd64";;
27+
aarch64 | arm64 | armv8*) architecture="arm64";;
28+
*) echo "(!) Architecture $architecture unsupported."; exit 1 ;;
29+
esac
30+
31+
asdf_package="asdf-${release}-${platform}-${architecture}.tar.gz"
32+
URL="https://github.com/asdf-vm/asdf/releases/download/${release}/${asdf_package}"
33+
echo "Downloading asdf-go from $URL"
34+
wget -qP /tmp $URL
35+
tar -xzf /tmp/${asdf_package} -C /usr/local/bin
36+
rm -rf /tmp/${asdf_package}
37+
38+
echo "ASDF-Go has been installed! Run asdf --help for more information."
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Ensure apt is in non-interactive to avoid prompts
5+
export DEBIAN_FRONTEND=noninteractive
6+
7+
USERNAME=${USERNAME:-"codespace"}
8+
9+
# Clean up
10+
rm -rf /var/lib/apt/lists/*
11+
12+
if [ "$(id -u)" -ne 0 ]; then
13+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
14+
exit 1
15+
fi
16+
17+
# Ensure that login shells get the correct path if the user updated the PATH using ENV.
18+
rm -f /etc/profile.d/00-restore-env.sh
19+
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
20+
chmod +x /etc/profile.d/00-restore-env.sh
21+
22+
# Determine the appropriate non-root user
23+
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
24+
USERNAME=""
25+
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
26+
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
27+
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
28+
USERNAME=${CURRENT_USER}
29+
break
30+
fi
31+
done
32+
if [ "${USERNAME}" = "" ]; then
33+
USERNAME=root
34+
fi
35+
elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
36+
USERNAME=root
37+
fi
38+
39+
apt_get_update() {
40+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
41+
echo "Running apt-get update..."
42+
apt-get update -y
43+
fi
44+
}
45+
46+
# Checks if packages are installed and installs them if not
47+
check_packages() {
48+
if ! dpkg -s "$@" > /dev/null 2>&1; then
49+
apt_get_update
50+
apt-get -y install --no-install-recommends "$@"
51+
fi
52+
}
53+
54+
echo "Installing asdf-go..."
55+
check_packages wget curl tar
56+
/bin/bash "$(dirname $0)/install-asdf-go.sh"
57+
# Clean up
58+
rm -rf /var/lib/apt/lists/*
59+
60+
echo "Done!"

config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ brewup = "brew bundle install"
2525

2626
[nix]
2727
# https://search.nixos.org/packages
28-
packages = ["asdf-vm"]
28+
packages = ["fastfetch"]

0 commit comments

Comments
 (0)