Skip to content

Commit

Permalink
Merge branch 'main' into nu-flatpaks
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftydinar authored Nov 10, 2024
2 parents 28a0238 + e328da9 commit 92f501a
Show file tree
Hide file tree
Showing 16 changed files with 412 additions and 146 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ These are general guidelines for writing official bash modules and their documen

- Echo what you're doing on each step and on errors to help debugging.
- Implement error-checks for scenarios where the image-maintainer might misconfigure the module.
- Use `snake_case` for functions and variables changed by the code.
- Use `snake_case` for functions and variables changed by the code.
- Use `SCREAMING_SNAKE_CASE` for variables that are set once and stay unchanged.
- Use `"${variable_name}"` when you want to expose information from the variable & to ensure that variables are properly parsed as strings.
- If you want to insert another regular string as a suffix or prefix to the `"${variable_name}"`, you should do that in this format: `"prefix-${variable_name}-suffix"`
Expand Down Expand Up @@ -118,28 +118,28 @@ In order to keep config files easy to read & reliable to parse, standardized `.y
#### Config Directory Structure

**System config:**
`/usr/share/bluebuild/module-name/config.yml`
`/usr/share/bluebuild/module-name/configuration.yml`

**System config** is a module config which is derived from `recipe.yml` module entry. It is placed in this read-only directory location in order to avoid local-users writing to it. So it is used to inform local-users about which modifications are done in `recipe.yml`, so they can potentially proceed with modifications on their own.

**Local-user config:**
`/usr/etc/bluebuild/module-name/config.yml`
`/usr/etc/bluebuild/module-name/configuration.yml`

**Local-user config** is a module config which is derived from local-user config template. It is placed in `/usr/etc`, which is then automatically copied to `/etc`, which is writable to local-users. `/usr/etc` local-user config can be used to reset module config that is done in `/etc`.

System & local-user config is not there just for users, it is also directly utilized by the module, which reads the `config.yml` file & further parses the data to allow the module to have local config functionality.
System & local-user config is not there just for users, it is also directly utilized by the module, which reads the `configuration.yml` file & further parses the data to allow the module to have local config functionality.

#### Config Example

System config (`/usr/share/bluebuild/default-flatpaks/config.yml`):
System config (`/usr/share/bluebuild/default-flatpaks/configuration.yml`):

```yaml
# Information about the config file
#
# vendor: BlueBuild
# module: default-flatpaks
# description: System config file for `default-flatpaks` BlueBuild module, which is used to install + remove flatpak apps or modify flatpak repos.
# instructions: Read this system config in order to know what is currently configured by the system & what to potentially modify in local-user config (/etc/bluebuild/default-flatpaks/config.yml).
# instructions: Read this system config in order to know what is currently configured by the system & what to potentially modify in local-user config (/etc/bluebuild/default-flatpaks/configuration.yml).

# Configuration section
notify: true
Expand All @@ -155,7 +155,7 @@ user:
- org.gnome.World.Secrets
```
Local-user config (`/etc/bluebuild/default-flatpaks/config.yml`):
Local-user config (`/etc/bluebuild/default-flatpaks/configuration.yml`):

```yaml
# Information about the config file
Expand Down
42 changes: 28 additions & 14 deletions modules/akmods/akmods.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail

function ENABLE_MULTIMEDIA_REPO {
ENABLE_AKMODS_REPO() {
sed -i 's@enabled=0@enabled=1@g' /etc/yum.repos.d/_copr_ublue-os-akmods.repo
sed -i "0,/enabled/ s@enabled=0@enabled=1@g" /etc/yum.repos.d/negativo17-fedora-multimedia.repo
}

function DISABLE_MULTIMEDIA_REPO {
sed -i 's@enabled=1@enabled=0@g' /etc/yum.repos.d/negativo17-fedora-multimedia.repo
INSTALL_RPM_FUSION() {
if ! rpm -q rpmfusion-free-release &>/dev/null && ! rpm -q rpmfusion-nonfree-release &>/dev/null; then
rpm-ostree install \
https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-${OS_VERSION}.noarch.rpm \
https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-${OS_VERSION}.noarch.rpm
previously_not_installed_rpm_fusion=true
else
previously_not_installed_rpm_fusion=false
fi
}

function SET_HIGHER_PRIORITY_AKMODS_REPO {
echo "priority=90" >> /etc/yum.repos.d/_copr_ublue-os-akmods.repo
UNINSTALL_RPM_FUSION() {
if "${previously_not_installed_rpm_fusion}"; then
rpm-ostree uninstall rpmfusion-free-release rpmfusion-nonfree-release
fi
}

get_yaml_array INSTALL '.install[]' "$1"

if [[ ${#INSTALL[@]} -lt 1 ]]; then
echo "ERROR: You didn't specify any akmod for installation!"
exit 1
fi

INSTALL_PATH=("${INSTALL[@]/#/\/tmp/rpms/kmods/*}")
INSTALL_PATH=("${INSTALL_PATH[@]/%/*.rpm}")
INSTALL_STR=$(echo "${INSTALL_PATH[*]}" | tr -d '\n')

if [[ ${#INSTALL[@]} -gt 0 ]]; then
echo "Installing akmods"
echo "Installing: $(echo "${INSTALL[*]}" | tr -d '\n')"
SET_HIGHER_PRIORITY_AKMODS_REPO
ENABLE_MULTIMEDIA_REPO
rpm-ostree install $INSTALL_STR
DISABLE_MULTIMEDIA_REPO
fi
# Universal Blue switched from RPMFusion to negativo17 repos
# WL & V4L2Loopback akmods currently require RPMFusion repo, so we temporarily install then uninstall it

echo "Installing akmods"
echo "Installing: $(echo "${INSTALL[*]}" | tr -d '\n')"
ENABLE_AKMODS_REPO
INSTALL_RPM_FUSION
rpm-ostree install ${INSTALL_STR}
UNINSTALL_RPM_FUSION
9 changes: 7 additions & 2 deletions modules/bling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ The bling to pull in is declared under `install:`, and the code for installing t

### `dconf-update-service`

The `dconf-update-service` submodule creates a systemd unit to automatically update changes you make to [dconf](https://wiki.gnome.org/Projects/dconf) in your custom image. For an example of a dconf keyfile, see the [dconf custom defaults documentation](https://help.gnome.org/admin/system-admin-guide/stable/dconf-custom-defaults.html.en).
The `dconf-update-service` submodule creates a systemd unit to automatically update changes you make to [dconf](https://wiki.gnome.org/Projects/dconf) in your custom image.

**Unlike the `gschema-overrides` module, dconf keyfiles are not checked at compile time**
For an example of a dconf keyfile, see the [dconf custom defaults documentation](https://help.gnome.org/admin/system-admin-guide/stable/dconf-custom-defaults.html.en).

Take a note that this documentation is for local-users, not for custom image maintainers. But it serves as a good example of what dconf file looks like.
Ignore the advice about creating the `user` profile, as it's already present & just place dconfs in `/etc/dconf/db/distro.d/`, not in `local.d` folder ([Thinking like a distribution](https://blue-build.org/learn/mindset/) mindset).

**Unlike the `gschema-overrides` module, dconf keyfiles are not checked at compile time for errors.**
15 changes: 14 additions & 1 deletion modules/brew/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ if ! command -v gcc &> /dev/null; then
fi
fi

# Check if zstd is installed & install it if it's not
if ! command -v zstd &> /dev/null; then
if command -v rpm-ostree &> /dev/null; then
echo "Installing \"zstd\" package, which is necessary for Brew to function"
rpm-ostree install zstd
else
echo "ERROR: \"zstd\" package could not be found"
echo " Brew's installer depends on \"zstd\" in order to function"
echo " Please include \"zstd\" in the list of packages to install with the system package manager"
exit 1
fi
fi

# Module-specific directories and paths
MODULE_DIRECTORY="${MODULE_DIRECTORY:-/tmp/modules}"

Expand Down Expand Up @@ -196,7 +209,7 @@ if [[ ! -f "/etc/profile.d/brew.sh" ]]; then
echo "Apply brew path export fix, to solve path conflicts between system & brew programs with same name"
cat > /etc/profile.d/brew.sh <<EOF
#!/usr/bin/env bash
[[ -d /home/linuxbrew/.linuxbrew && $- == *i* ]] && eval "\$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
[[ -d /home/linuxbrew/.linuxbrew && \$- == *i* ]] && eval "\$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
EOF
fi

Expand Down
18 changes: 9 additions & 9 deletions modules/chezmoi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
The `chezmoi` module takes care of installing, initializing and updating your dotfiles.
Each feature can be enabled or disabled individually.

Installation of the `chezmoi` binary happens at build time and is done by downloading the `amd64` binary from the latest release to `/usr/bin/chezmoi`.
Installation of the `chezmoi` binary happens at build time and is done by downloading the `amd64` binary from the latest release to `/usr/bin/chezmoi`.
This can be disabled by setting `install` to false. (defaults: true)

Choose how `chezmoi` handles conflicting files with `file-conflict-policy`.
Choose how `chezmoi` handles conflicting files with `file-conflict-policy`.
The following values are valid:
`"skip"` Will not take any action if the file has changed from what is in your dotfiles repository.
This executes `chezmoi update --no-tty --keep-going` under the hood.
`"skip"` Will not take any action if the file has changed from what is in your dotfiles repository.
This executes `chezmoi update --no-tty --keep-going` under the hood.
`"replace"` Will overwrite the file if it has changed from what is in your dotfiles repository.
This executes `chezmoi update --no-tty --force` under the hood.

See `chezmoi`s documentation for [`--no-tty`](https://www.chezmoi.io/reference/command-line-flags/global/#-no-tty), [`--keep-going`](https://www.chezmoi.io/reference/command-line-flags/global/#-k-keep-going) and [`--force`](https://www.chezmoi.io/reference/command-line-flags/global/#-force) for details.

A systemd user service is installed that will initialize a `chezmoi` repository on chezmoi's default path (`~/.local/share/chezmoi`) for any user when it logs in, or at boot if it has lingering enabled.
The service will only run if `~/.local/share/chezmoi` does not exist.
Set `repository` to the URL of your dotfiles repository. (eg. `repository: https://example.org/user/dotfiles`)
Set `repository` to the URL of your dotfiles repository. (eg. `repository: https://example.org/user/dotfiles`). You can also set `branch` if you want to use a branch different than the default.
:::note
The value of `repository` will be passed directly to `chezmoi init --apply ${repository}`.
The value of `repository` and `branch` will be passed directly to `chezmoi init --apply ${repository} --branch ${branch}`.
See the [`chezmoi init` documentation](https://www.chezmoi.io/reference/commands/init/) for detailed syntax.
:::
:::
Set `disable-init` to `true` if you do not want to install the init service.

:::caution
Expand All @@ -46,10 +46,10 @@ sudo systemctl enable --user chesmoi-init.service chezmoi-update.timer
To turn on lingering for a given user, run the following command with sudo:

:::note
By default, any systemd units in a user's namespace will run after the user logs in, and will close after the user closes their last session.
By default, any systemd units in a user's namespace will run after the user logs in, and will close after the user closes their last session.
When you enable lingering for a user, that user's units will run at boot and will continue running even if the user has no active sessions.

If your dotfiles only contain things used by humans, such as cosmetic settings and aliases, you shouldn't need this.
If your dotfiles only contain things used by humans, such as cosmetic settings and aliases, you shouldn't need this.
If you understand the above implications, and decide you need this feature, you can enable it with the following command, after installation:
:::

Expand Down
13 changes: 9 additions & 4 deletions modules/chezmoi/chezmoi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ fi

# The repository with your chezmoi dotfiles. (default: null)
DOTFILE_REPOSITORY=$(echo "$1" | yq -I=0 ".repository") # (string)
# The chezmoi repository branch to use.
DOTFILE_BRANCH=$(echo "$1" | yq -I=0 ".branch")
if [[ -n ${DOTFILE_BRANCH} ]]; then
INIT_BRANCH_FLAG="--branch ${DOTFILE_BRANCH}"
else
INIT_BRANCH_FLAG=""
fi

# If true, chezmoi services will be enabled for all logged in users, and users with lingering enabled. (default: true)
# If false, chezmoi services will not be enabled for any users, but can be enabled manually, after installation.
Expand Down Expand Up @@ -85,7 +92,6 @@ if [[ (-z $DOTFILE_REPOSITORY || $DOTFILE_REPOSITORY == "null") && $DISABLE_INIT
exit 1
fi


echo "Checking if /usr/bin/chezmoi exists"
if [ -e /usr/bin/chezmoi ]; then
echo "chezmoi binary already exists, no need to redownload it"
Expand All @@ -104,18 +110,17 @@ else
fi
fi


if [[ $DISABLE_INIT == false ]]; then
# Write the service to initialize Chezmoi, and insert the repo url in the file
echo "Writing init service to user unit directory"
cat >>/usr/lib/systemd/user/chezmoi-init.service <<EOF
[Unit]
Description=Initializes Chezmoi if directory is missing
# This service will not execute for a user with an existing chezmoi directory
ConditionPathExists=!%h/.local/share/chezmoi/.git/
[Service]
ExecStart=/usr/bin/chezmoi init --apply ${DOTFILE_REPOSITORY}
ExecStart=/usr/bin/chezmoi init --apply ${DOTFILE_REPOSITORY} ${INIT_BRANCH_FLAG}
Type=oneshot
[Install]
Expand Down
7 changes: 5 additions & 2 deletions modules/chezmoi/chezmoi.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ model ChezmoiModule {
/** Git repository to initialize. */
repository: string;

/** Git branch of the chezmoi repository. */
branch?: string = "";

/** Whether to enable the modules services globally for all users, if false users need to enable services manually. */
"all-users"?: boolean = true;

Expand All @@ -19,7 +22,7 @@ model ChezmoiModule {

/** Dotfile updates will wait this long after a boot before running. */
"wait-after-boot"?: string = "5m";

/** Disable the service that initializes `repository` on users that are logged in or have linger enabled UI. */
"disable-init"?: boolean = false;

Expand All @@ -28,4 +31,4 @@ model ChezmoiModule {

/** What to do when file different that exists on your repo is has been changed or exists locally. Accepts "skip" or "replace". */
"file-conflict-policy"?: "skip" | "replace" = "skip";
}
}
7 changes: 5 additions & 2 deletions modules/default-flatpaks/v1/default-flatpaks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ cp -r "$MODULE_DIRECTORY"/default-flatpaks/system-flatpak-setup /usr/bin/system-
cp -r "$MODULE_DIRECTORY"/default-flatpaks/user-flatpak-setup /usr/bin/user-flatpak-setup
cp -r "$MODULE_DIRECTORY"/default-flatpaks/system-flatpak-setup.service /usr/lib/systemd/system/system-flatpak-setup.service
cp -r "$MODULE_DIRECTORY"/default-flatpaks/user-flatpak-setup.service /usr/lib/systemd/user/user-flatpak-setup.service
cp -r "$MODULE_DIRECTORY"/default-flatpaks/system-flatpak-setup.timer /usr/lib/systemd/system/system-flatpak-setup.timer
cp -r "$MODULE_DIRECTORY"/default-flatpaks/user-flatpak-setup.timer /usr/lib/systemd/user/user-flatpak-setup.timer


configure_flatpak_repo () {
CONFIG_FILE=$1
Expand Down Expand Up @@ -146,8 +149,8 @@ check_flatpak_id_validity_from_flathub () {
echo "Enabling flatpaks module"
mkdir -p /usr/share/bluebuild/default-flatpaks/{system,user}
mkdir -p /etc/bluebuild/default-flatpaks/{system,user}
systemctl enable -f system-flatpak-setup.service
systemctl enable -f --global user-flatpak-setup.service
systemctl enable -f system-flatpak-setup.timer
systemctl enable -f --global user-flatpak-setup.timer

# Check that `system` is present before configuring. Also copy template list files before writing Flatpak IDs.
if [[ ! $(echo "$1" | yq -I=0 ".system") == "null" ]]; then
Expand Down
Loading

0 comments on commit 92f501a

Please sign in to comment.