Skip to content

Commit

Permalink
refactor: combine asus and surface builds with nvidia
Browse files Browse the repository at this point in the history
This is a WIP commit which shows has the first steps of asus/surface
main images mostly working in a Containerfile and skipping main/main.

The nvidia parts will be built in a second target.

Github workflows have not yet been touched.
  • Loading branch information
bsherman committed Mar 27, 2024
1 parent 3f93913 commit 3b0ab1b
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 33 deletions.
51 changes: 38 additions & 13 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,51 @@
ARG IMAGE_NAME="${IMAGE_NAME:-silverblue}"
ARG BASE_IMAGE="ghcr.io/ublue-os/${IMAGE_NAME}-main"
ARG SOURCE_IMAGE="${SOURCE_IMAGE:-silverblue-main}"
ARG SOURCE_ORG="${SOURCE_ORG:-ublue-os}"
ARG BASE_IMAGE="ghcr.io/${SOURCE_ORG}/${SOURCE_IMAGE}"
ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-39}"

FROM ${BASE_IMAGE}:${FEDORA_MAJOR_VERSION} AS nvidia
FROM ${BASE_IMAGE}:${FEDORA_MAJOR_VERSION} AS main

ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-39}"
ARG HWE_FLAVOR="{HWE_FLAVOR:-main}"
ARG IMAGE_NAME="${IMAGE_NAME:-silverblue}"
ARG IMAGE_VENDOR="ublue-os"
ARG IMAGE_FLAVOR="${IMAGE_FLAVOR:-nvidia}"
ARG IMAGE_VENDOR="${IMAGE_VENDOR:-ublue-os}"
ARG RPMFUSION_MIRROR=""

COPY *.sh /tmp/
COPY ${HWE_FLAVOR}/ /tmp/

RUN mkdir -p /var/lib/alternatives && \
IMAGE_FLAVOR=main /tmp/image-info.sh && \
/tmp/install.sh && \
mv /var/lib/alternatives /staged-alternatives && \
rm -rf /tmp/* /var/* && \
ostree container commit && \
mkdir -p /var/lib && mv /staged-alternatives /var/lib/alternatives && \
mkdir -p /tmp /var/tmp && \
chmod -R 1777 /tmp /var/tmp

FROM main AS nvidia

ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-39}"
ARG HWE_FLAVOR="{HWE_FLAVOR:-main}"
ARG IMAGE_NAME="${IMAGE_NAME:-silverblue}"
ARG IMAGE_VENDOR="${IMAGE_VENDOR:-ublue-os}"
ARG NVIDIA_MAJOR_VERSION="${NVIDIA_MAJOR_VERSION:-550}"
ARG RPMFUSION_MIRROR=""

COPY image-info.sh /tmp/image-info.sh
COPY install.sh /tmp/install.sh
COPY post-install.sh /tmp/post-install.sh
COPY --from=ghcr.io/ublue-os/akmods-nvidia:${HWE_FLAVOR}-${FEDORA_MAJOR_VERSION}-${NVIDIA_MAJOR_VERSION} /rpms /tmp/akmods-rpms

COPY --from=ghcr.io/ublue-os/akmods-nvidia:main-${FEDORA_MAJOR_VERSION}-${NVIDIA_MAJOR_VERSION} /rpms /tmp/akmods-rpms
COPY image-info.sh /tmp/
COPY nvidia/*.sh /tmp/

RUN /tmp/image-info.sh && \
RUN mkdir -p /var/lib/alternatives && \
IMAGE_FLAVOR=nvidia /tmp/image-info.sh && \
/tmp/install.sh && \
/tmp/post-install.sh && \
rm -rf /tmp/* /var/*

RUN ostree container commit && \
mkdir -p /var/tmp && chmod -R 1777 /tmp /var/tmp
mv /var/lib/alternatives /staged-alternatives && \
rm -rf /tmp/* /var/* && \
ostree container commit && \
mkdir -p /var/lib && mv /staged-alternatives /var/lib/alternatives && \
mkdir -p /tmp /var/tmp && \
chmod -R 1777 /tmp /var/tmp
14 changes: 14 additions & 0 deletions asus/packages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"all": {
"include": {
"all": [
"asusctl",
"asusctl-rog-gui",
"fprintd"
]
},
"exclude": {
"all": []
}
}
}
89 changes: 69 additions & 20 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/sh
#!/bin/bash

set -ouex pipefail

if [[ "${FEDORA_MAJOR_VERSION}" -le 38 ]]; then
sed -i 's@enabled=1@enabled=0@g' /etc/yum.repos.d/fedora-{cisco-openh264,modular,updates-modular}.repo
else
sed -i 's@enabled=1@enabled=0@g' /etc/yum.repos.d/fedora-cisco-openh264.repo
RELEASE="$(rpm -E %fedora)"

if [ "${HWE_FLAVOR}" = "main" ]; then
# HWE_FLAVOR is main, no need to do anything
exit 0
fi

if [ -n "${RPMFUSION_MIRROR}" ]; then
Expand All @@ -19,27 +20,75 @@ if [ -n "${RPMFUSION_MIRROR}" ]; then
fi
fi

rpm-ostree install \
/tmp/akmods-rpms/ublue-os/ublue-os-nvidia-addons-*.rpm
# do HWE specific things
if [ "${HWE_FLAVOR}" = "asus" ]; then
echo "install.sh: steps for HWE_FLAVOR: ${HWE_FLAVOR}"
# Install Asus kernel
wget https://copr.fedorainfracloud.org/coprs/lukenukem/asus-linux/repo/fedora-${RELEASE}/lukenukem-asus-linux-fedora-${RELEASE}.repo -O /etc/yum.repos.d/_copr_lukenukem-asus-linux.repo
wget https://copr.fedorainfracloud.org/coprs/lukenukem/asus-kernel/repo/fedora-${RELEASE}/lukenukem-asus-kernel-fedora-${RELEASE}repo -O /etc/yum.repos.d/_copr_lukenukem-asus-kernel.repo
rpm-ostree cliwrap install-to-root /
rpm-ostree override replace \
--experimental \
--from repo=copr:copr.fedorainfracloud.org:lukenukem:asus-kernel \
kernel \
kernel-core \
kernel-modules \
kernel-modules-core \
kernel-modules-extra
git clone https://gitlab.com/asus-linux/firmware.git --depth 1 /tmp/asus-firmware
cp -rf /tmp/asus-firmware/* /usr/lib/firmware/
rm -rf /tmp/asus-firmware
elif [ "${HWE_FLAVOR}" = "surface" ]; then
echo "install.sh: steps for HWE_FLAVOR: ${HWE_FLAVOR}"
# Install Surface kernel
wget https://pkg.surfacelinux.com/fedora/linux-surface.repo -P /etc/yum.repos.d
wget https://github.com/linux-surface/linux-surface/releases/download/silverblue-20201215-1/kernel-20201215-1.x86_64.rpm -O /tmp/surface-kernel.rpm
rpm-ostree cliwrap install-to-root /
rpm-ostree override replace /tmp/surface-kernel.rpm \
--remove kernel-core \
--remove kernel-modules \
--remove kernel-modules-extra \
--remove libwacom \
--remove libwacom-data \
--install kernel-surface \
--install iptsd \
--install libwacom-surface \
--install libwacom-surface-data
else
echo "install.sh: steps for unexpected HWE_FLAVOR: ${HWE_FLAVOR}"
fi

source /tmp/akmods-rpms/kmods/nvidia-vars.${NVIDIA_MAJOR_VERSION}
# copy any shared sys files
if [ -d "/tmp/system_files/shared" ]; then
rsync -rvK /tmp/system_files/shared/ /
fi

if [[ "${IMAGE_NAME}" == "kinoite" ]]; then
VARIANT_PKGS="supergfxctl-plasmoid supergfxctl"
elif [[ "${IMAGE_NAME}" == "silverblue" ]]; then
VARIANT_PKGS="gnome-shell-extension-supergfxctl-gex supergfxctl"
else
VARIANT_PKGS=""
# copy any flavor specific files, eg silverblue
if [ -d "/tmp/system_files/${IMAGE_NAME}" ]; then
rsync -rvK /tmp/system_files/"${IMAGE_NAME}"/ /
fi

rpm-ostree install \
xorg-x11-drv-${NVIDIA_PACKAGE_NAME}-{,cuda-,devel-,kmodsrc-,power-}${NVIDIA_FULL_VERSION} \
xorg-x11-drv-${NVIDIA_PACKAGE_NAME}-libs.i686 \
nvidia-container-toolkit nvidia-vaapi-driver ${VARIANT_PKGS} \
/tmp/akmods-rpms/kmods/kmod-${NVIDIA_PACKAGE_NAME}-${KERNEL_VERSION}-${NVIDIA_AKMOD_VERSION}.fc${RELEASE}.rpm
# install any packages from packages.json
if [ -f "/tmp/packages.json" ]; then
/tmp/packages.sh /tmp/packages.json
fi

# do HWE specific post-install things
if [ "${HWE_FLAVOR}" = "asus" ]; then
echo "install.sh: post-install for: ${HWE_FLAVOR}"
elif [ "${HWE_FLAVOR}" = "surface" ]; then
echo "install.sh: post-install for: ${HWE_FLAVOR}"
if grep -q "silverblue" <<< "${IMAGE_NAME}"; then
systemctl enable dconf-update
fi
systemctl enable fprintd
systemctl enable surface-hardware-setup
else
echo "install.sh: post-install for unexpected HWE_FLAVOR: ${HWE_FLAVOR}"
fi

if [ -n "${RPMFUSION_MIRROR}" ]; then
# reset forced use of single rpmfusion mirror
echo "Revert from single rpmfusion mirror: ${RPMFUSION_MIRROR}"
rename -v .repo.bak .repo /etc/yum.repos.d/rpmfusion-*repo.bak
fi
fi
Empty file added main/.gitkeep
Empty file.
45 changes: 45 additions & 0 deletions nvidia/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh

set -ouex pipefail

if [[ "${FEDORA_MAJOR_VERSION}" -le 38 ]]; then
sed -i 's@enabled=1@enabled=0@g' /etc/yum.repos.d/fedora-{cisco-openh264,modular,updates-modular}.repo
else
sed -i 's@enabled=1@enabled=0@g' /etc/yum.repos.d/fedora-cisco-openh264.repo
fi

if [ -n "${RPMFUSION_MIRROR}" ]; then
# force use of single rpmfusion mirror
echo "Using single rpmfusion mirror: ${RPMFUSION_MIRROR}"
sed -i.bak "s%^metalink=%#metalink=%" /etc/yum.repos.d/rpmfusion-*.repo
sed -i "s%^#baseurl=http://download1.rpmfusion.org%baseurl=${RPMFUSION_MIRROR}%" /etc/yum.repos.d/rpmfusion-*.repo
# after F40 launches, bump to 41
if [[ "${FEDORA_MAJOR_VERSION}" -ge 40 ]]; then
sed -i "s%free/fedora/releases%free/fedora/development%" /etc/yum.repos.d/rpmfusion-*.repo
fi
fi

rpm-ostree install \
/tmp/akmods-rpms/ublue-os/ublue-os-nvidia-addons-*.rpm

source /tmp/akmods-rpms/kmods/nvidia-vars.${NVIDIA_MAJOR_VERSION}

if [[ "${IMAGE_NAME}" == "kinoite" ]]; then
VARIANT_PKGS="supergfxctl-plasmoid supergfxctl"
elif [[ "${IMAGE_NAME}" == "silverblue" ]]; then
VARIANT_PKGS="gnome-shell-extension-supergfxctl-gex supergfxctl"
else
VARIANT_PKGS=""
fi

rpm-ostree install \
xorg-x11-drv-${NVIDIA_PACKAGE_NAME}-{,cuda-,devel-,kmodsrc-,power-}${NVIDIA_FULL_VERSION} \
xorg-x11-drv-${NVIDIA_PACKAGE_NAME}-libs.i686 \
nvidia-container-toolkit nvidia-vaapi-driver ${VARIANT_PKGS} \
/tmp/akmods-rpms/kmods/kmod-${NVIDIA_PACKAGE_NAME}-${KERNEL_VERSION}-${NVIDIA_AKMOD_VERSION}.fc${RELEASE}.rpm

if [ -n "${RPMFUSION_MIRROR}" ]; then
# reset forced use of single rpmfusion mirror
echo "Revert from single rpmfusion mirror: ${RPMFUSION_MIRROR}"
rename -v .repo.bak .repo /etc/yum.repos.d/rpmfusion-*repo.bak
fi
File renamed without changes.
53 changes: 53 additions & 0 deletions packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

set -ouex pipefail

RELEASE="$(rpm -E %fedora)"

# build list of all packages requested for inclusion
INCLUDED_PACKAGES=($(jq -r "[(.all.include | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[]), \
(select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_VERSION\".include | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[])] \
| sort | unique[]" /tmp/packages.json))

# build list of all packages requested for exclusion
EXCLUDED_PACKAGES=($(jq -r "[(.all.exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[]), \
(select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_VERSION\".exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[])] \
| sort | unique[]" /tmp/packages.json))


# ensure exclusion list only contains packages already present on image
if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then
EXCLUDED_PACKAGES=($(rpm -qa --queryformat='%{NAME} ' ${EXCLUDED_PACKAGES[@]}))
fi

# simple case to install where no packages need excluding
if [[ "${#INCLUDED_PACKAGES[@]}" -gt 0 && "${#EXCLUDED_PACKAGES[@]}" -eq 0 ]]; then
rpm-ostree install \
${INCLUDED_PACKAGES[@]}

# install/excluded packages both at same time
elif [[ "${#INCLUDED_PACKAGES[@]}" -gt 0 && "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then
rpm-ostree override remove \
${EXCLUDED_PACKAGES[@]} \
$(printf -- "--install=%s " ${INCLUDED_PACKAGES[@]})

else
echo "No packages to install."

fi

# check if any excluded packages are still present
# (this can happen if an included package pulls in a dependency)
EXCLUDED_PACKAGES=($(jq -r "[(.all.exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[]), \
(select(.\"$FEDORA_MAJOR_VERSION\" != null).\"$FEDORA_MAJOR_VERSION\".exclude | (.all, select(.\"$IMAGE_NAME\" != null).\"$IMAGE_NAME\")[])] \
| sort | unique[]" /tmp/packages.json))

if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then
EXCLUDED_PACKAGES=($(rpm -qa --queryformat='%{NAME} ' ${EXCLUDED_PACKAGES[@]}))
fi

# remove any excluded packages which are still present on image
if [[ "${#EXCLUDED_PACKAGES[@]}" -gt 0 ]]; then
rpm-ostree override remove \
${EXCLUDED_PACKAGES[@]}
fi
12 changes: 12 additions & 0 deletions surface/packages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"all": {
"include": {
"all": [
"fprintd"
]
},
"exclude": {
"all": []
}
}
}

0 comments on commit 3b0ab1b

Please sign in to comment.