Skip to content

Commit aeb27d1

Browse files
committed
refactor: migrate Homebrew to build-time installation
1 parent 0960956 commit aeb27d1

File tree

10 files changed

+49
-52
lines changed

10 files changed

+49
-52
lines changed

Containerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,36 @@ RUN --mount=type=cache,dst=/var/cache/libdnf5 \
3232
--mount=type=secret,id=GITHUB_TOKEN \
3333
/ctx/build_files/shared/build.sh
3434

35+
# Install Homebrew
36+
RUN --mount=type=cache,dst=/var/cache/homebrew,uid=1000,gid=1000 \
37+
set -eoux pipefail && \
38+
# Create linuxbrew user with fixed UID/GID for compatibility with first user \
39+
useradd -u 1000 -m -s /bin/bash -c "Homebrew Build User" linuxbrew && \
40+
# Create Homebrew directory structure in /var/home (persists across ostree) \
41+
mkdir -p /var/home/linuxbrew/.linuxbrew && \
42+
chown -R 1000:1000 /var/home/linuxbrew && \
43+
# Create cache directories \
44+
mkdir -p /var/cache/homebrew /var/lib/homebrew && \
45+
chown -R 1000:1000 /var/cache/homebrew /var/lib/homebrew && \
46+
# Download and run Homebrew installer as linuxbrew user \
47+
su - linuxbrew -c "bash -c ' \
48+
export NONINTERACTIVE=1 && \
49+
export HOMEBREW_BREW_GIT_REMOTE=https://github.com/Homebrew/brew && \
50+
export HOMEBREW_CORE_GIT_REMOTE=https://github.com/Homebrew/homebrew-core && \
51+
export HOMEBREW_NO_AUTO_UPDATE=1 && \
52+
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash \
53+
'" && \
54+
# Disable git auto-gc to prevent background processes \
55+
su - linuxbrew -c "git config --global gc.auto 0" && \
56+
# Verify installation \
57+
test -x /var/home/linuxbrew/.linuxbrew/bin/brew && \
58+
/var/home/linuxbrew/.linuxbrew/bin/brew --version && \
59+
test -d /var/home/linuxbrew/.linuxbrew/Homebrew && \
60+
# Clean up linuxbrew user (ownership preserved via UID/GID 1000) \
61+
userdel linuxbrew && \
62+
# Cleanup cache \
63+
dnf clean all
64+
3565
# Makes `/opt` writeable by default
3666
# Needs to be here to make the main image build strict (no /opt there)
3767
# This is for downstream images/stuff like k0s

build_files/base/04-packages.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ FEDORA_PACKAGES=(
2929
ddcutil
3030
evtest
3131
fastfetch
32+
file
3233
firewall-config
3334
fish
3435
foo2zjs

build_files/base/06-install-homebrew.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

build_files/base/20-tests.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,22 @@ for unit in "${IMPORTANT_UNITS[@]}"; do
7777
fi
7878
done
7979

80-
# Test Homebrew installation files
81-
echo "Testing Homebrew installation files..."
80+
# Test Homebrew build-time installation
81+
echo "Testing Homebrew build-time installation..."
8282

83-
# Test that the homebrew installer script exists and is executable
84-
test -f /usr/share/ublue-os/homebrew-install.sh || { echo "Missing homebrew installer script"; exit 1; }
85-
test -x /usr/share/ublue-os/homebrew-install.sh || { echo "Homebrew installer script is not executable"; exit 1; }
83+
# Test that Homebrew is actually installed
84+
test -x /var/home/linuxbrew/.linuxbrew/bin/brew || { echo "Homebrew binary not found or not executable"; exit 1; }
85+
/var/home/linuxbrew/.linuxbrew/bin/brew --version || { echo "Homebrew --version failed"; exit 1; }
86+
87+
# Verify /home -> /var/home symlink works (ostree system feature)
88+
test -d /home/linuxbrew/.linuxbrew || { echo "/home/linuxbrew not accessible (ostree /home symlink issue)"; exit 1; }
89+
90+
# Test directory ownership (should be UID/GID 1000)
91+
stat -c "%u:%g" /var/home/linuxbrew/.linuxbrew | grep -q "1000:1000" || { echo "Homebrew directory has wrong ownership"; exit 1; }
8692

8793
# Test that all systemd service files exist
94+
# Homebrew now installed at build-time
8895
HOMEBREW_SYSTEMD_FILES=(
89-
/usr/lib/systemd/system/brew-setup.service
9096
/usr/lib/systemd/system/brew-update.service
9197
/usr/lib/systemd/system/brew-update.timer
9298
/usr/lib/systemd/system/brew-upgrade.service

build_files/shared/build.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ echo "::endgroup::"
3434
# Install Overrides and Fetch Install
3535
/ctx/build_files/base/05-override-install.sh
3636

37-
# Install Homebrew
38-
/ctx/build_files/base/06-install-homebrew.sh
39-
4037
# Build GNOME Extensions from Git Submodules
4138
/ctx/build_files/shared/build-gnome-extensions.sh
4239

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
enable brew-setup.service
21
enable brew-update.timer
32
enable brew-upgrade.timer

system_files/shared/usr/lib/systemd/system/brew-setup.service

Lines changed: 0 additions & 16 deletions
This file was deleted.

system_files/shared/usr/lib/systemd/system/brew-update.service

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
Description=Auto update brew for mutable brew installs
33
After=local-fs.target
44
After=network-online.target
5-
ConditionPathIsSymbolicLink=/home/linuxbrew/.linuxbrew/bin/brew
5+
ConditionPathExists=/home/linuxbrew/.linuxbrew/bin/brew
6+
ConditionPathIsExecutable=/home/linuxbrew/.linuxbrew/bin/brew
67

78
[Service]
89
User=1000

system_files/shared/usr/lib/systemd/system/brew-upgrade.service

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
Description=Upgrade Brew packages
33
After=local-fs.target
44
After=network-online.target
5-
ConditionPathIsSymbolicLink=/home/linuxbrew/.linuxbrew/bin/brew
5+
ConditionPathExists=/home/linuxbrew/.linuxbrew/bin/brew
6+
ConditionPathIsExecutable=/home/linuxbrew/.linuxbrew/bin/brew
67

78
[Service]
89
User=1000
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Homebrew is installed at build-time to /var/home/linuxbrew
2+
# These directives ensure proper ownership for first user (UID 1000) at runtime
13
d /var/lib/homebrew 0755 1000 1000 - -
24
d /var/cache/homebrew 0755 1000 1000 - -
35
d /var/home/linuxbrew 0755 1000 1000 - -

0 commit comments

Comments
 (0)