@@ -3,8 +3,176 @@ description: "This action sets up a nix devshell environment"
33runs :
44 using : " composite"
55 steps :
6+ # Adapted from: https://github.com/reitermarkus/dotfiles/blob/349cf6c0aff2ab8666247904779b788a14b99fa0/.github/workflows/ci.yml#L39-L190
7+ - name : Clean environment
8+ shell : bash
9+ run : |
10+ set -e
11+ set -u
12+ set -o pipefail
13+
14+ # Uninstall Gems.
15+ for gem in $(gem list --no-versions | grep -v \
16+ -e 'bigdecimal' \
17+ -e 'CFPropertyList' \
18+ -e 'cmath' \
19+ -e 'csv' \
20+ -e 'date' \
21+ -e 'dbm' \
22+ -e 'did_you_mean' \
23+ -e 'e2mmap' \
24+ -e 'etc' \
25+ -e 'fcntl' \
26+ -e 'fiddle' \
27+ -e 'fileutils' \
28+ -e 'forwardable' \
29+ -e 'io-console' \
30+ -e 'ipaddr' \
31+ -e 'irb' \
32+ -e 'json' \
33+ -e 'libxml-ruby' \
34+ -e 'logger' \
35+ -e 'matrix' \
36+ -e 'minitest' \
37+ -e 'mutex_m' \
38+ -e 'net-telnet' \
39+ -e 'nokogiri' \
40+ -e 'openssl' \
41+ -e 'ostruct' \
42+ -e 'power_assert' \
43+ -e 'prime' \
44+ -e 'psych' \
45+ -e 'rake' \
46+ -e 'rexml' \
47+ -e 'rdoc' \
48+ -e 'rss' \
49+ -e 'scanf' \
50+ -e 'shell' \
51+ -e 'sqlite3' \
52+ -e 'stringio' \
53+ -e 'strscan' \
54+ -e 'sync' \
55+ -e 'test-unit' \
56+ -e 'thwait' \
57+ -e 'tracer' \
58+ -e 'webrick' \
59+ -e 'xmlrpc' \
60+ -e 'zlib' \
61+ ); do
62+ sudo gem uninstall --force --all --ignore-dependencies --executables "$gem" || true
63+ done
64+
65+ # Uninstall Homebrew.
66+ brew update
67+ sudo rm -rf /usr/local/miniconda &
68+ rm -rf /usr/local/lib/node_modules &
69+ rm -f /usr/local/bin/terminal-notifier
70+ rm -f /usr/local/bin/change_hostname.sh
71+ rm -f /usr/local/bin/azcopy
72+
73+ if which brew &>/dev/null; then
74+ eval "$(brew list --formula | xargs -I% echo 'brew uninstall --formula --force --ignore-dependencies "%" &')"
75+ eval "$(brew list --cask | xargs -I% echo '{ brew uninstall --cask --force "%"; brew uninstall --cask --zap --force "%"; } &')"
76+ brew uninstall --cask --zap --force dotnet &
77+ brew uninstall --cask --zap --force adoptopenjdk/openjdk/adoptopenjdk8 &
78+ brew uninstall --cask --zap --force mono-mdk &
79+ brew uninstall --cask --zap --force xamarin-android &
80+ brew uninstall --cask --zap --force xamarin-ios &
81+ brew uninstall --cask --zap --force xamarin-mac &
82+ wait
83+ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" -- --force
84+ fi
85+
86+ # Clean environment.
87+ for trash in ~/.DS_Store \
88+ ~/.Trash/* \
89+ ~/.aliyun \
90+ ~/.android \
91+ ~/.azcopy \
92+ ~/.azure \
93+ ~/.bash_history \
94+ ~/.bash_profile \
95+ ~/.bash_sessions \
96+ ~/.bashrc \
97+ ~/.cabal \
98+ ~/.cache \
99+ ~/.cargo \
100+ ~/.cocoapods \
101+ ~/.composer \
102+ ~/.conda \
103+ ~/.config \
104+ ~/.dotnet \
105+ ~/.fastlane \
106+ ~/.gem \
107+ ~/.ghcup \
108+ ~/.gitconfig \
109+ ~/.gradle \
110+ ~/.local \
111+ ~/.m2 \
112+ ~/.mono \
113+ ~/.npm \
114+ ~/.npmrc \
115+ ~/.nvm \
116+ ~/.oracle_jre_usage \
117+ ~/.packer.d \
118+ ~/.rustup \
119+ ~/.sh_history \
120+ ~/.ssh \
121+ ~/.subversion \
122+ ~/.sqlite_history \
123+ ~/.vcpkg \
124+ ~/.viminfo \
125+ ~/.wget-hsts \
126+ ~/.yarn \
127+ ~/Library/Caches/Homebrew \
128+ ~/Microsoft \
129+ ~/hostedtoolcache \
130+ ~/*.txt; do
131+ if [[ -e "$trash" ]]; then
132+ mv "$trash" /tmp/trash/
133+ fi
134+ done
135+
136+ # Delete broken symlinks.
137+ for exe in /usr/local/bin/*; do
138+ if [[ -L "$exe" ]] && ! [[ -e "$exe" ]]; then
139+ rm "$exe"
140+ fi
141+ done
142+
143+ mkdir -p /tmp/trash
144+ for pkg in /var/db/receipts/*.plist; do
145+ pkg_id="$(basename "${pkg}" .plist)"
146+ volume="$(pkgutil --pkg-info "${pkg_id}" | sed -n -e 's/^volume: //p')"
147+ location="$(pkgutil --pkg-info "${pkg_id}" | sed -n -e 's/^location: //p')"
148+ pkgutil --only-files --files "${pkg_id}" | xargs -I% sudo mv -f "${volume}${location}/%" /tmp/trash/ || true
149+ pkgutil --only-dirs --files "${pkg_id}" | xargs -I% sudo rmdir -p "${volume}${location}/%" || true
150+ pkgutil --forget "${pkg_id}"
151+ done
152+
6153 - name : Setup Nix
7- uses : DeterminateSystems/nix-installer-action@e50d5f73bfe71c2dd0aa4218de8f4afa59f8f81d # v16
154+ uses : nixbuild/nix-quick-install-action@5bb6a3b3abe66fd09bbf250dce8ada94f856a703 # v30
155+
156+ - uses : nix-community/cache-nix-action@92aaf15ec4f2857ffed00023aecb6504bb4a5d3d # v6
157+ with :
158+ # restore and save a cache using this key
159+ primary-key : nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
160+ # if there's no cache hit, restore a cache by this prefix
161+ restore-prefixes-first-match : nix-${{ runner.os }}-
162+ # collect garbage until Nix store size (in bytes) is at most this number
163+ # before trying to save a new cache
164+ # 1 GB = 1073741824 B
165+ gc-max-store-size-linux : 1073741824
166+ # do purge caches
167+ purge : true
168+ # purge all versions of the cache
169+ purge-prefixes : nix-${{ runner.os }}-
170+ # created more than this number of seconds ago relative to the start of the `Post Restore` phase
171+ purge-created : 0
172+ # except the version with the `primary-key`, if it exists
173+ purge-primary-key : never
8174
9175 - name : Enter devshell
10176 uses : nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a # v1.2.1
177+ with :
178+ arguments : " .#ci"
0 commit comments