Skip to content

Commit 35dfc1d

Browse files
author
Marc Henry de Frahan
committed
Use a scratch variable for some installs
1 parent 482e62b commit 35dfc1d

8 files changed

Lines changed: 49 additions & 11 deletions

File tree

.chezmoi.toml.tmpl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,30 @@
1717
{{ $ornl_hpc = true -}}
1818
{{- end -}}
1919

20+
{{/* Set scratch directory */}}
21+
{{/* Default based on system type, but user can override */}}
22+
{{ $scratch_default := "${HOME}" -}}
23+
{{- if $nrel_hpc -}}
24+
{{ $scratch_default = "/scratch/${USER}" -}}
25+
{{- else if $ornl_hpc -}}
26+
{{ $scratch_default = "/lustre/orion/${USER}" -}}
27+
{{- end -}}
28+
{{- $scratch_root := "" -}}
29+
{{- if (get . "scratch_root") -}}
30+
{{- $scratch_root = get . "scratch_root" -}}
31+
{{- else if .chezmoi.stdinIsATTY -}}
32+
{{- $scratch_input := promptStringOnce . "scratch_root" (printf "Scratch directory [%s]" $scratch_default) -}}
33+
{{- $scratch_root = or $scratch_input $scratch_default -}}
34+
{{- else -}}
35+
{{- $scratch_root = $scratch_default -}}
36+
{{- end -}}
37+
2038
[data]
2139
use_zsh_root_dir = {{ $use_zsh_root_dir }}
2240
email = {{ $email | quote }}
2341
test_machine = {{ $test_machine }}
2442
spack_packages = false
2543
nrel_hpc = {{ $nrel_hpc }}
2644
nrel_cluster = {{ $nrel_cluster }}
27-
ornl_hpc = {{ $ornl_hpc }}
45+
ornl_hpc = {{ $ornl_hpc }}
46+
scratch_root = {{ $scratch_root | quote }}

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
git clone --depth 1 --branch "${{ github.head_ref || github.ref_name }}" https://github.com/marchdf/dotfiles.git "$HOME/.local/share/chezmoi"
3838
- name: Install
3939
run: |
40-
chezmoi init --source="$HOME/.local/share/chezmoi" --promptBool test_machine=t,"Use ZSH_ROOT_DIR for tmux shell"=f --promptString email=""
40+
chezmoi init --source="$HOME/.local/share/chezmoi" --promptBool test_machine=t,"Use ZSH_ROOT_DIR for tmux shell"=f --promptString email="",scratch_root=""
4141
chezmoi data
4242
chezmoi apply
4343
- name: Cold start zsh

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ENV PATH="/home/$USERNAME/.local/bin:${PATH}"
5151
# Initialize chezmoi with dotfiles from GitHub
5252
RUN chezmoi init https://github.com/marchdf/dotfiles.git \
5353
--promptBool test_machine=f,"Use ZSH_ROOT_DIR for tmux shell"=f \
54-
--promptString email="marchdf@docker-container.com" \
54+
--promptString email="marchdf@docker-container.com",scratch_root="" \
5555
&& chezmoi apply
5656

5757
# Pre-initialize zinit by running zsh once (this downloads all plugins)

docker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ docker compose run --rm ubuntu-test
2424
# Inside container - first time setup:
2525
chezmoi init --source /dotfiles-source \
2626
--promptBool test_machine=f,"Use ZSH_ROOT_DIR for tmux shell"=f \
27-
--promptString email="test@docker.com"
27+
--promptString email="marchdf@docker.com",scratch_root=""
2828
chezmoi apply
2929

3030
# Iterating on changes (edit files on host, then in container):

dot_local/share/zinit/plugins/hpc/hpc.plugin.zsh.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Plugins[PERSONAL_DIR]="${0:h}"
2222
# Custom for NREL HPC machines
2323

2424
# Set scratch
25-
if [ -d "/scratch/${USER}" ]; then
26-
export SCRATCH="/scratch/${USER}"
25+
if [ -d "{{ .scratch_root }}" ]; then
26+
export SCRATCH="{{ .scratch_root }}"
2727
fi
2828

2929
# Set the modules

dot_zshrc.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export COMBUSTION_DIR="${HOME}/combustion"
8181
export MASA_HOME="${COMBUSTION_DIR}/install/MASA"
8282

8383
# pyenv
84-
export PYENV_ROOT="${HOME}/.local/${ARCH}/pyenv"
84+
export PYENV_ROOT="{{ .scratch_root }}/.local/${ARCH}/pyenv"
8585
if [ -d "${PYENV_ROOT}" ]; then
8686
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
8787
eval "$(pyenv init -)"
@@ -109,7 +109,7 @@ if [[ -x "$(command -v claude)" ]]; then
109109
export CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS=50000
110110
fi
111111

112-
export WORKON_HOME="${HOME}/.local/${ARCH}/virtualenvs"
112+
export WORKON_HOME="{{ .scratch_root }}/.local/${ARCH}/virtualenvs"
113113

114114
{{- if eq .chezmoi.os "darwin" }}
115115

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@ set -e
55
PYTHON_VERSION="3.12.9"
66

77
ARCH=$(uname -m)
8-
export PYENV_ROOT="${HOME}/.local/${ARCH}/pyenv"
9-
export WORKON_HOME="${HOME}/.local/${ARCH}/virtualenvs"
8+
9+
# Ensure scratch directory is writable
10+
if [[ ! -d "{{ .scratch_root }}/.local/${ARCH}" ]]; then
11+
if ! mkdir -p "{{ .scratch_root }}/.local/${ARCH}" 2>/dev/null; then
12+
echo "ERROR: Cannot create {{ .scratch_root }}/.local/${ARCH}"
13+
echo "Check that scratch filesystem is mounted"
14+
exit 1
15+
fi
16+
fi
17+
18+
export PYENV_ROOT="{{ .scratch_root }}/.local/${ARCH}/pyenv"
19+
export WORKON_HOME="{{ .scratch_root }}/.local/${ARCH}/virtualenvs"
1020

1121
# Install pyenv if not present
1222
if [[ ! -x "$(command -v pyenv)" ]] && [[ ! -d "${PYENV_ROOT}" ]]; then

run_before_install-packages-linux.sh.tmpl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ ARCH=$(uname -m)
55
ARCH_BIN="${HOME}/.local/${ARCH}/bin"
66
mkdir -p "${ARCH_BIN}"
77

8-
export PYENV_ROOT="${HOME}/.local/${ARCH}/pyenv"
8+
# Ensure scratch directory is writable
9+
if [[ ! -d "{{ .scratch_root }}/.local/${ARCH}" ]]; then
10+
if ! mkdir -p "{{ .scratch_root }}/.local/${ARCH}" 2>/dev/null; then
11+
echo "ERROR: Cannot create {{ .scratch_root }}/.local/${ARCH}"
12+
echo "Check that scratch filesystem is mounted"
13+
exit 1
14+
fi
15+
fi
16+
17+
export PYENV_ROOT="{{ .scratch_root }}/.local/${ARCH}/pyenv"
918
if [[ ! -x "$(command -v pyenv)" ]] && [[ ! -d "${PYENV_ROOT}" ]]; then
1019
curl https://pyenv.run | bash
1120
fi

0 commit comments

Comments
 (0)