Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add chezmoi service #3

Merged
merged 8 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion files/scripts/01-main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@
set -ouex pipefail

systemctl enable libvirtd.service
systemctl --global enable xfconf-profile.service

# This profile will not actually be used by xfconf-profile. We are
# only moving it to the chezmoi target state because we want to apply
# chezmoi changes if this file changes
mkdir -p /usr/share/winblues/chezmoi/dot_local/share/xfconf-profile
cp /usr/share/xfconf-profile/default.json \
/usr/share/winblues/chezmoi/dot_local/share/winblues-blue95.json

systemctl --global preset-all
4 changes: 4 additions & 0 deletions files/scripts/90-finalize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -ouex pipefail

systemctl --global preset-all
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable flatpak-user-update.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable winblues-chezmoi.service
10 changes: 10 additions & 0 deletions files/system/usr/lib/systemd/user/winblues-chezmoi.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Update user-level configs managed by winblues
After=default.target

[Service]
Type=oneshot
ExecStart=/usr/libexec/winblues-chezmoi

[Install]
WantedBy=default.target
11 changes: 0 additions & 11 deletions files/system/usr/lib/systemd/user/xfconf-profile.service

This file was deleted.

80 changes: 80 additions & 0 deletions files/system/usr/libexec/winblues-chezmoi
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

set -xeuo pipefail

state_dir=${XDG_STATE_HOME:-$HOME/.local/state}/winblues/chezmoi

user_chezmoi_ignore=${XDG_CONFIG_HOME:-$HOME/.config}/winblues/chezmoiignore
user_env_file=$(mktemp -p /tmp winblues-chezmoi-env.XXXX)

# Save current user environment so we can reload it in chezmoi run_*.sh scripts
echo "export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}" >"${user_env_file}"
echo "export XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}" >>"${user_env_file}"
echo "export XDG_STATE_HOME=${XDG_STATE_HOME:-$HOME/.local/state}" >>"${user_env_file}"
echo "export XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}" >>"${user_env_file}"
export WINBLUES_CHEZMOI_ORIGINAL_ENV_FILE="${user_env_file}"

# Use our own chezmoi directories so we don't interfere with the user's chezmoi
export XDG_CONFIG_HOME="${state_dir}/.config"
export XDG_DATA_HOME="${state_dir}/.local/share"
export XDG_STATE_HOME="${state_dir}/.local/state"
export XDG_CACHE_HOME="${state_dir}/.cache"

if [ ! -d "$state_dir" ]; then
echo "First run of $0"
mkdir -p "$state_dir"
chezmoi init
chezmoi git -- checkout -b main
fi

# Copy the booted image's chezmoi source to the user's state
winblues_chezmoi_data_home="${XDG_DATA_HOME}/chezmoi"
winblues_chezmoi_source=/usr/share/winblues/chezmoi

cd $winblues_chezmoi_data_home/..
rsync -aP $winblues_chezmoi_source .
cd $winblues_chezmoi_data_home

if [[ -z "$(git status --porcelain)" ]]; then
echo "No changes needed"
exit 0
fi

# At this point, we know that we need to run chezmoi apply to update
# our managed files

git config --local user.name "Winblues User"
git config --local user.email "user@blues.win"
git add .

booted_image_version=$(rpm-ostree status --json | jq '.deployments[] | select(.booted == true) | .version' | tr -d '"')
booted_image=$(rpm-ostree status --json | jq '.deployments[] | select(.booted == true) | ."container-image-reference"' | tr -d '"')

git commit -m "bump: $booted_image_version of $booted_image"

# Check if user has changes to files we're managing. Save them in a branch and rollback
# to a known-good state.
if [[ ! -z "$(chezmoi diff --script-contents=false)" ]]; then
echo "Dirty state of managed files. Creating a branch to preserve user's changes."
if git rev-parse "rollback" >/dev/null 2>&1; then
git tag -d rollback
fi

git checkout -b "rollback-$(date +%Y%m%d-%H%M%S)"
chezmoi re-add
git add .
git commit --allow-empty -m "changes to managed files"
git tag rollback
else
echo "No user-modified managed files"
fi

git checkout main

# Allow users to ignore updates to certain files
if [[ -f $user_chezmoi_ignore ]]; then
cp $user_chezmoi_ignore $winblues_chezmoi_data_home/.chezmoiignore
fi

chezmoi apply --force
rm -f $winblues_chezmoi_data_home/.chezmoiignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -euo pipefail

. "${WINBLUES_CHEZMOI_ORIGINAL_ENV_FILE}"

xfconf-profile sync
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* NOTE: this file is managed by Winblues using chezmoi. Any changes to this
* file will be overwritten the next time you log in. To configure chezmoi to
* not manage this file, run the following:
* mkdir -p ~/.config/winblues
* echo ".config/gtk-3.0/gtk.css" >> ~/.config/winblues/chezmoiignore
*/

/* GTK 3.24 Theme Override for the Chicago95 theme.
* REMOVE THIS FILE WHEN USING OTHER GTK THEMES! */

/* XFCE APP: Color Profiles
* Add a background colour since the color profile app overrides the GTK theme. */
.color-profiles {
background-color: @bg_color; }

/* XFCE APP: XFCE Session logout dialogue
* Add a border to the logout dialogue. */
.xfsm-logout-dialog {
border-left: 1px solid @border_bright;
border-top: 1px solid @border_bright;
border-bottom: 1px solid @border_dark;
border-right: 1px solid @border_dark;
box-shadow: inset -1px -1px @border_shade, inset 1px 1px @border_light; }

/* XFCE APP: Thunar
* Add a border effect to areas where Thunar will attempt to override. */
.thunar .sidebar {
border-right: 2px solid @border_color; }
.thunar notebook .standard-view {
padding: 0px;
border-left: 2px solid @border_color;
border-right: 2px solid @border_color; }

/* GNOME APP: GNOME Disks
* This is a fix for the GNOME Disks application grid style. */
.gnome-disk-utility-grid {
background-color: @bg_shade;
color: @font_bright;
border-radius: 0px;
outline-color: @border_bright; }
.gnome-disk-utility-grid:backdrop {
background-color: @bg_shade; }


3 changes: 3 additions & 0 deletions files/system/usr/share/xfconf-profile/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
},
"xfwm4": {
"/general/theme": "Chicago95"
},
"xfce4-keyboard-shortcuts": {
"/commands/custom/Super_L": "/usr/bin/xfce4-popup-whiskermenu"
}
}