From 7e33425ca057f499a9249c0faacc5c8afa74eb76 Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 22 Sep 2024 17:00:44 +0300 Subject: [PATCH 01/38] feat: initial draft of default-flatpaks v2 this version just sets up the config file but nothing to read it and install the flatpaks after boot --- .../default-flatpaks/v2/default-flatpaks.sh | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 modules/default-flatpaks/v2/default-flatpaks.sh diff --git a/modules/default-flatpaks/v2/default-flatpaks.sh b/modules/default-flatpaks/v2/default-flatpaks.sh new file mode 100644 index 00000000..584b16c7 --- /dev/null +++ b/modules/default-flatpaks/v2/default-flatpaks.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env nu + +const flathubURL = "https://dl.flathub.org/repo/flathub.flatpakrepo" + +const defaultInstallation = { + notify: true + scope: user + repo: { + url: $flathubURL + name: "flathub" + title: "Flathub" + } + install: [] +} +const configPath = '/usr/share/bluebuild/default-flatpaks/configuration.json' + +def main [configStr: string] { + let config = $configStr | from json + + let installations = $config.installations | each {|installation| + mut merged = $defaultInstallation | merge $installation + $merged.repo = $defaultInstallation.repo | merge $merged.repo # make sure all repo properties exist + + print $"(ansi blue)Validating installation of(ansi reset) (ansi default_italic)($merged.install | length)(ansi reset) (ansi blue)Flatpaks from(ansi reset) (ansi default_italic)($merged.repo.title)(ansi reset)" + + if (not ($merged.scope == "system" or $merged.scope == "user")) { + print $"(ansi red_bold)Scope must be either(ansi reset) (ansi blue_italic)system(ansi reset) (ansi red_bold)or(ansi reset) (ansi blue_italic)user(ansi reset)" + print $"(ansi blue)Your input:(ansi reset) ($merged.scope)" + exit 1 + } + if (not ($merged.notify == true or $merged.notify == false)) { + print $"(ansi red_bold)Notify must be either(ansi reset) (ansi blue_italic)true(ansi reset) (ansi red_bold)or(ansi reset) (ansi blue_italic)false(ansi reset)" + print $"(ansi blue)Your input:(ansi reset) ($merged.notify)" + exit 1 + } + if ($merged.repo.url == $flathubURL) { + checkFlathub $merged.install + } + + print $"(ansi green_bold)Validation successful!(ansi reset)" + + $merged + } + + + if (not ($configPath | path exists)) { + mkdir ($configPath | path dirname) + '[]'| save $configPath + } + + open $configPath + | append $installations + | to json | save -f $configPath + + print $"(ansi green_bold)Generated following installations:(ansi reset)" + print ($installations | to yaml) +} + +def checkFlathub [packages: list] { + $packages | each { |package| + print $"(ansi blue)Checking if package(ansi reset) (ansi default_italic)($package)(ansi reset) (ansi blue)exists on Flathub.(ansi reset)" + try { + let _ = http get $"https://flathub.org/apps/($package)" + } catch { + print $"(ansi red_bold)Package(ansi reset) (ansi default_italic)($package)(ansi reset) (ansi red_bold)does not exist on Flathub, which is the specified repository for it to be installed from.(ansi reset)" + exit 1 + } + print $"(ansi green)Package found!(ansi reset)" + } +} \ No newline at end of file From 851ecfdae54bd2e3fc989792dd15e2aaa6642e3e Mon Sep 17 00:00:00 2001 From: xyny Date: Thu, 26 Sep 2024 16:10:14 +0300 Subject: [PATCH 02/38] chore: streamline logging --- modules/default-flatpaks/v2/default-flatpaks.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/default-flatpaks/v2/default-flatpaks.sh b/modules/default-flatpaks/v2/default-flatpaks.sh index 584b16c7..339a84d9 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.sh +++ b/modules/default-flatpaks/v2/default-flatpaks.sh @@ -21,7 +21,7 @@ def main [configStr: string] { mut merged = $defaultInstallation | merge $installation $merged.repo = $defaultInstallation.repo | merge $merged.repo # make sure all repo properties exist - print $"(ansi blue)Validating installation of(ansi reset) (ansi default_italic)($merged.install | length)(ansi reset) (ansi blue)Flatpaks from(ansi reset) (ansi default_italic)($merged.repo.title)(ansi reset)" + print $"Validating installation of (ansi default_italic)($merged.install | length)(ansi reset) Flatpaks from (ansi default_italic)($merged.repo.title)(ansi reset)" if (not ($merged.scope == "system" or $merged.scope == "user")) { print $"(ansi red_bold)Scope must be either(ansi reset) (ansi blue_italic)system(ansi reset) (ansi red_bold)or(ansi reset) (ansi blue_italic)user(ansi reset)" @@ -37,7 +37,7 @@ def main [configStr: string] { checkFlathub $merged.install } - print $"(ansi green_bold)Validation successful!(ansi reset)" + print $"Validation successful!" $merged } @@ -52,19 +52,18 @@ def main [configStr: string] { | append $installations | to json | save -f $configPath - print $"(ansi green_bold)Generated following installations:(ansi reset)" + print $"(ansi green_bold)Successfully generated following installations:(ansi reset)" print ($installations | to yaml) } def checkFlathub [packages: list] { + print "Checking if configured packages exist on Flathub..." $packages | each { |package| - print $"(ansi blue)Checking if package(ansi reset) (ansi default_italic)($package)(ansi reset) (ansi blue)exists on Flathub.(ansi reset)" try { let _ = http get $"https://flathub.org/apps/($package)" } catch { print $"(ansi red_bold)Package(ansi reset) (ansi default_italic)($package)(ansi reset) (ansi red_bold)does not exist on Flathub, which is the specified repository for it to be installed from.(ansi reset)" exit 1 } - print $"(ansi green)Package found!(ansi reset)" } } \ No newline at end of file From 2cd4439cdec717febbcb9598afac71df6ba925bf Mon Sep 17 00:00:00 2001 From: xyny Date: Thu, 26 Sep 2024 16:13:07 +0300 Subject: [PATCH 03/38] chore: replace json with yaml as generated config format --- modules/default-flatpaks/v2/default-flatpaks.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/default-flatpaks/v2/default-flatpaks.sh b/modules/default-flatpaks/v2/default-flatpaks.sh index 339a84d9..1364e060 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.sh +++ b/modules/default-flatpaks/v2/default-flatpaks.sh @@ -12,10 +12,10 @@ const defaultInstallation = { } install: [] } -const configPath = '/usr/share/bluebuild/default-flatpaks/configuration.json' +const configPath = '/usr/share/bluebuild/default-flatpaks/configuration.yaml' def main [configStr: string] { - let config = $configStr | from json + let config = $configStr | from yaml let installations = $config.installations | each {|installation| mut merged = $defaultInstallation | merge $installation @@ -50,7 +50,7 @@ def main [configStr: string] { open $configPath | append $installations - | to json | save -f $configPath + | to yaml | save -f $configPath print $"(ansi green_bold)Successfully generated following installations:(ansi reset)" print ($installations | to yaml) From a45fc97a5dceddd4516dda3ec958126bc13e42f6 Mon Sep 17 00:00:00 2001 From: xyny Date: Thu, 26 Sep 2024 17:06:34 +0300 Subject: [PATCH 04/38] feat: set up groundwork for post boot scripts --- modules/default-flatpaks/v2/default-flatpaks.sh | 16 +++++++++++++++- .../v2/post-boot/system-flatpak-setup | 1 + .../v2/post-boot/system-flatpak-setup.service | 14 ++++++++++++++ .../v2/post-boot/user-flatpak-setup | 1 + .../v2/post-boot/user-flatpak-setup.service | 14 ++++++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 modules/default-flatpaks/v2/post-boot/system-flatpak-setup create mode 100644 modules/default-flatpaks/v2/post-boot/system-flatpak-setup.service create mode 100644 modules/default-flatpaks/v2/post-boot/user-flatpak-setup create mode 100644 modules/default-flatpaks/v2/post-boot/user-flatpak-setup.service diff --git a/modules/default-flatpaks/v2/default-flatpaks.sh b/modules/default-flatpaks/v2/default-flatpaks.sh index 1364e060..4794676b 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.sh +++ b/modules/default-flatpaks/v2/default-flatpaks.sh @@ -12,7 +12,9 @@ const defaultInstallation = { } install: [] } -const configPath = '/usr/share/bluebuild/default-flatpaks/configuration.yaml' + +const usrSharePath = "/usr/share/bluebuild/default-flatpaks" +const configPath = $"($usrSharePath)/configuration.yaml" def main [configStr: string] { let config = $configStr | from yaml @@ -54,6 +56,18 @@ def main [configStr: string] { print $"(ansi green_bold)Successfully generated following installations:(ansi reset)" print ($installations | to yaml) + + print "Setting up Flatpak setup services..." + + cp -r ($"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/*" | into glob) $usrSharePath + + cp $"($usrSharePath)/system-flatpak-setup.service" /usr/lib/systemd/system/system-flatpak-setup.service + cp $"($usrSharePath)/user-flatpak-setup.service" /usr/lib/systemd/user/user-flatpak-setup.service + systemctl enable --force system-flatpak-setup.service + systemctl enable --force --global user-flatpak-setup.service + + chmod +x $"($usrSharePath)/system-flatpak-setup" + chmod +x $"($usrSharePath)/user-flatpak-setup" } def checkFlathub [packages: list] { diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup new file mode 100644 index 00000000..ee2bc1f5 --- /dev/null +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup @@ -0,0 +1 @@ +#!/usr/bin/env nu diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup.service b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup.service new file mode 100644 index 00000000..c6039a1c --- /dev/null +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup.service @@ -0,0 +1,14 @@ +[Unit] +Description=Manage system flatpaks +Wants=network-online.target +After=network-online.target + +[Service] +Type=oneshot +ExecStart=/usr/share/bluebuild/default-flatpaks/system-flatpak-setup +Restart=on-failure +RestartSec=30 +StartLimitInterval=0 + +[Install] +WantedBy=multi-user.target diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup new file mode 100644 index 00000000..ee2bc1f5 --- /dev/null +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup @@ -0,0 +1 @@ +#!/usr/bin/env nu diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup.service b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup.service new file mode 100644 index 00000000..38ec2d77 --- /dev/null +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup.service @@ -0,0 +1,14 @@ +[Unit] +Description=Configure Flatpaks for current user +Wants=network-online.target +After=system-flatpak-setup.service + +[Service] +Type=simple +ExecStart=/usr/share/bluebuild/default-flatpaks/user-flatpak-setup +Restart=on-failure +RestartSec=30 +StartLimitInterval=0 + +[Install] +WantedBy=default.target From 14158930fc710bbf41c73269bb0e6e7dbf4f8bad Mon Sep 17 00:00:00 2001 From: xyny Date: Fri, 11 Oct 2024 19:34:39 +0300 Subject: [PATCH 05/38] feat: rename installations -> configurations, initial implementation of post-boot part --- .../default-flatpaks/v2/default-flatpaks.sh | 16 ++++---- .../v2/post-boot/system-flatpak-setup | 40 +++++++++++++++++++ .../v2/post-boot/user-flatpak-setup | 33 +++++++++++++++ 3 files changed, 81 insertions(+), 8 deletions(-) diff --git a/modules/default-flatpaks/v2/default-flatpaks.sh b/modules/default-flatpaks/v2/default-flatpaks.sh index 4794676b..181d01f6 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.sh +++ b/modules/default-flatpaks/v2/default-flatpaks.sh @@ -2,7 +2,7 @@ const flathubURL = "https://dl.flathub.org/repo/flathub.flatpakrepo" -const defaultInstallation = { +const defaultConfiguration = { notify: true scope: user repo: { @@ -19,11 +19,11 @@ const configPath = $"($usrSharePath)/configuration.yaml" def main [configStr: string] { let config = $configStr | from yaml - let installations = $config.installations | each {|installation| - mut merged = $defaultInstallation | merge $installation - $merged.repo = $defaultInstallation.repo | merge $merged.repo # make sure all repo properties exist + let configurations = $config.configurations | each {|configuration| + mut merged = $defaultConfiguration | merge $configuration + $merged.repo = $defaultConfiguration.repo | merge $merged.repo # make sure all repo properties exist - print $"Validating installation of (ansi default_italic)($merged.install | length)(ansi reset) Flatpaks from (ansi default_italic)($merged.repo.title)(ansi reset)" + print $"Validating configuration of (ansi default_italic)($merged.install | length)(ansi reset) Flatpaks from (ansi default_italic)($merged.repo.title)(ansi reset)" if (not ($merged.scope == "system" or $merged.scope == "user")) { print $"(ansi red_bold)Scope must be either(ansi reset) (ansi blue_italic)system(ansi reset) (ansi red_bold)or(ansi reset) (ansi blue_italic)user(ansi reset)" @@ -51,11 +51,11 @@ def main [configStr: string] { } open $configPath - | append $installations + | append $configurations | to yaml | save -f $configPath - print $"(ansi green_bold)Successfully generated following installations:(ansi reset)" - print ($installations | to yaml) + print $"(ansi green_bold)Successfully generated following configurations:(ansi reset)" + print ($configurations | to yaml) print "Setting up Flatpak setup services..." diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup index ee2bc1f5..1fe0d8fb 100644 --- a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup @@ -1 +1,41 @@ #!/usr/bin/env nu + +const usrSharePath = "/usr/share/bluebuild/default-flatpaks" +const configPath = $"($usrSharePath)/configuration.yaml" + +def main [] { + let configFile = open $configPath + + if (flatpak remotes | str contains fedora) { + /usr/bin/gnome-software --quit + /usr/lib/fedora-third-party/fedora-third-party-opt-out + /usr/bin/fedora-third-party disable + + flatpak remote-delete --system fedora --force + flatpak remote-delete --system fedora-testing --force + + # TODO remove Fedora Flatpaks + } + + $configFile.configurations | where scope == system | each { |config| + flatpak remote-add --system --if-not-exists $config.repo.name $config.repo.url --title $config.repo.title + + if ($config.notify) { + # TODO implement notification sending + # (notify-send + # --app-name "Automatic Flatpak Installation Service" + # $"Starting automated installation of ($config.install | length) Flatpak\(s) from ($config.repo.title)..." + # ) + } + + flatpak install --system $config.repo.name ...$config.install + + if ($config.notify) { + # (notify-send + # --app-name "Automatic Flatpak Installation Service" + # $"Finished automated installation of ($config.install | length) Flatpak\(s) from ($config.repo.title)!" + # ($config.install | str join ', ') + # ) + } + } +} \ No newline at end of file diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup index ee2bc1f5..b34ae4ca 100644 --- a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup @@ -1 +1,34 @@ #!/usr/bin/env nu + +const usrSharePath = "/usr/share/bluebuild/default-flatpaks" +const configPath = $"($usrSharePath)/configuration.yaml" + +def main [] { + let configFile = open $configPath + + if (flatpak remotes | str contains fedora) { + flatpak remote-delete --user fedora --force + flatpak remote-delete --user fedora-testing --force + } + + $configFile.configurations | where scope == user | each { |config| + flatpak remote-add --user --if-not-exists $config.repo.name $config.repo.url --title $config.repo.title + + if ($config.notify) { + (notify-send + --app-name "Automatic Flatpak Installation Service" + $"Starting automated installation of ($config.install | length) Flatpak\(s) from ($config.repo.title)..." + ) + } + + flatpak install --user $config.repo.name ...$config.install + + if ($config.notify) { + (notify-send + --app-name "Automatic Flatpak Installation Service" + $"Finished automated installation of ($config.install | length) Flatpak\(s) from ($config.repo.title)!" + ($config.install | str join ', ') + ) + } + } +} \ No newline at end of file From da675a4812cebd9f861015d0108602398513e773 Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 10 Nov 2024 18:16:07 +0200 Subject: [PATCH 06/38] fix: put executable files into /usr/libexec/ --- modules/default-flatpaks/v2/default-flatpaks.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/default-flatpaks/v2/default-flatpaks.sh b/modules/default-flatpaks/v2/default-flatpaks.sh index 181d01f6..de354d63 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.sh +++ b/modules/default-flatpaks/v2/default-flatpaks.sh @@ -14,6 +14,7 @@ const defaultConfiguration = { } const usrSharePath = "/usr/share/bluebuild/default-flatpaks" +const libExecPath = "/usr/libexec/bluebuild/default-flatpaks" const configPath = $"($usrSharePath)/configuration.yaml" def main [configStr: string] { @@ -66,8 +67,10 @@ def main [configStr: string] { systemctl enable --force system-flatpak-setup.service systemctl enable --force --global user-flatpak-setup.service - chmod +x $"($usrSharePath)/system-flatpak-setup" - chmod +x $"($usrSharePath)/user-flatpak-setup" + cp $"($usrSharePath)/system-flatpak-setup" $"($libExecPath)/system-flatpak-setup" + cp $"($usrSharePath)/user-flatpak-setup" $"($libExecPath)/user-flatpak-setup" + chmod +x $"($libExecPath)/system-flatpak-setup" + chmod +x $"($libExecPath)/user-flatpak-setup" } def checkFlathub [packages: list] { From 6510afa431e19dfa02de51f1277bfaf846143356 Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 10 Nov 2024 18:52:48 +0200 Subject: [PATCH 07/38] fix: improve fedora remote detection and removal --- .../v2/post-boot/system-flatpak-setup | 11 ++++++++--- .../default-flatpaks/v2/post-boot/user-flatpak-setup | 6 +++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup index 1fe0d8fb..6811ebe1 100644 --- a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup @@ -6,13 +6,18 @@ const configPath = $"($usrSharePath)/configuration.yaml" def main [] { let configFile = open $configPath - if (flatpak remotes | str contains fedora) { + let systemRemotes = (flatpak remotes --system --columns name | split row "\n") + if ($systemRemotes | any {|remote| $remote == "fedora" or $remote == "fedora-testing"}) { /usr/bin/gnome-software --quit /usr/lib/fedora-third-party/fedora-third-party-opt-out /usr/bin/fedora-third-party disable - flatpak remote-delete --system fedora --force - flatpak remote-delete --system fedora-testing --force + if ($systemRemotes | any {|remote| $remote == "fedora"}) { + flatpak remote-delete --system fedora --force + } + if ($systemRemotes | any {|remote| $remote == "fedora-testing"}) { + flatpak remote-delete --system fedora-testing --force + } # TODO remove Fedora Flatpaks } diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup index b34ae4ca..be5c191c 100644 --- a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup @@ -6,11 +6,15 @@ const configPath = $"($usrSharePath)/configuration.yaml" def main [] { let configFile = open $configPath - if (flatpak remotes | str contains fedora) { + let userRemotes = (flatpak remotes --user --columns name | split row "\n") + if ($userRemotes | any {|remote| $remote == "fedora"}) { flatpak remote-delete --user fedora --force + } + if ($userRemotes | any {|remote| $remote == "fedora-testing"}) { flatpak remote-delete --user fedora-testing --force } + $configFile.configurations | where scope == user | each { |config| flatpak remote-add --user --if-not-exists $config.repo.name $config.repo.url --title $config.repo.title From 7185ef5b094fb81c2e2c7ef58059ef77a3df373f Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 10 Nov 2024 19:36:55 +0200 Subject: [PATCH 08/38] feat: implement notifications for system flatpak setup --- .../v2/post-boot/system-flatpak-setup | 26 ++++++++++++------- .../v2/post-boot/user-flatpak-setup | 4 +-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup index 6811ebe1..9e2c1770 100644 --- a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup @@ -26,21 +26,27 @@ def main [] { flatpak remote-add --system --if-not-exists $config.repo.name $config.repo.url --title $config.repo.title if ($config.notify) { - # TODO implement notification sending - # (notify-send - # --app-name "Automatic Flatpak Installation Service" - # $"Starting automated installation of ($config.install | length) Flatpak\(s) from ($config.repo.title)..." - # ) + (notify-send-as-user + "--app-name" "Automatic Flatpak Installation Service" + $"Starting automated installation of ($config.install | length) system Flatpak\(s) from ($config.repo.title)..." + ) } flatpak install --system $config.repo.name ...$config.install if ($config.notify) { - # (notify-send - # --app-name "Automatic Flatpak Installation Service" - # $"Finished automated installation of ($config.install | length) Flatpak\(s) from ($config.repo.title)!" - # ($config.install | str join ', ') - # ) + (notify-send-as-user + "--app-name" "Automatic Flatpak Installation Service" + $"Finished automated installation of ($config.install | length) system Flatpak\(s) from ($config.repo.title)!" + ($config.install | str join ', ') + ) } } +} + +def notify-send-as-user [...args] { + let user_name = (loginctl list-sessions --json=short | from json | get user | get 0) + let uid = (loginctl list-sessions --json=short | from json | get uid | get 0) + let xdg_runtime_path = $"/run/user/($uid)" + sudo -u $user_name DBUS_SESSION_BUS_ADDRESS=unix:path=($xdg_runtime_path)/bus DISPLAY=($env.DISPLAY) notify-send ...$args } \ No newline at end of file diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup index be5c191c..fb62dba9 100644 --- a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup @@ -21,7 +21,7 @@ def main [] { if ($config.notify) { (notify-send --app-name "Automatic Flatpak Installation Service" - $"Starting automated installation of ($config.install | length) Flatpak\(s) from ($config.repo.title)..." + $"Starting automated installation of ($config.install | length) user Flatpak\(s) from ($config.repo.title)..." ) } @@ -30,7 +30,7 @@ def main [] { if ($config.notify) { (notify-send --app-name "Automatic Flatpak Installation Service" - $"Finished automated installation of ($config.install | length) Flatpak\(s) from ($config.repo.title)!" + $"Finished automated installation of ($config.install | length) user Flatpak\(s) from ($config.repo.title)!" ($config.install | str join ', ') ) } From 28a0238ba43a433c632c650c5c684ddf3de41c47 Mon Sep 17 00:00:00 2001 From: fiftydinar <65243233+fiftydinar@users.noreply.github.com> Date: Sun, 10 Nov 2024 18:47:50 +0100 Subject: [PATCH 09/38] chore(default-flatpaks): No need to expose `DISPLAY` for notify-send --- modules/default-flatpaks/v2/post-boot/system-flatpak-setup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup index 9e2c1770..e7403826 100644 --- a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup @@ -48,5 +48,5 @@ def notify-send-as-user [...args] { let user_name = (loginctl list-sessions --json=short | from json | get user | get 0) let uid = (loginctl list-sessions --json=short | from json | get uid | get 0) let xdg_runtime_path = $"/run/user/($uid)" - sudo -u $user_name DBUS_SESSION_BUS_ADDRESS=unix:path=($xdg_runtime_path)/bus DISPLAY=($env.DISPLAY) notify-send ...$args -} \ No newline at end of file + sudo -u $user_name DBUS_SESSION_BUS_ADDRESS=unix:path=($xdg_runtime_path)/bus notify-send ...$args +} From 9498a7934f1b5a090fdeef5b6d8f3fe1201987db Mon Sep 17 00:00:00 2001 From: fiftydinar <65243233+fiftydinar@users.noreply.github.com> Date: Sun, 10 Nov 2024 18:54:59 +0100 Subject: [PATCH 10/38] chore(default-flatpaks): Update service & add timers to match v1 --- .../v2/post-boot/system-flatpak-setup.service | 8 +------- .../v2/post-boot/system-flatpak-setup.timer | 8 ++++++++ .../v2/post-boot/user-flatpak-setup.service | 10 ++-------- .../v2/post-boot/user-flatpak-setup.timer | 8 ++++++++ 4 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 modules/default-flatpaks/v2/post-boot/system-flatpak-setup.timer create mode 100644 modules/default-flatpaks/v2/post-boot/user-flatpak-setup.timer diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup.service b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup.service index c6039a1c..087b0e9c 100644 --- a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup.service +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup.service @@ -5,10 +5,4 @@ After=network-online.target [Service] Type=oneshot -ExecStart=/usr/share/bluebuild/default-flatpaks/system-flatpak-setup -Restart=on-failure -RestartSec=30 -StartLimitInterval=0 - -[Install] -WantedBy=multi-user.target +ExecStart=/usr/libexec/bluebuild/default-flatpaks/system-flatpak-setup \ No newline at end of file diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup.timer b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup.timer new file mode 100644 index 00000000..e18c3235 --- /dev/null +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Timer for system-flatpak-setup + +[Timer] +OnBootSec=30 + +[Install] +WantedBy=timers.target \ No newline at end of file diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup.service b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup.service index 38ec2d77..58d98149 100644 --- a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup.service +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup.service @@ -4,11 +4,5 @@ Wants=network-online.target After=system-flatpak-setup.service [Service] -Type=simple -ExecStart=/usr/share/bluebuild/default-flatpaks/user-flatpak-setup -Restart=on-failure -RestartSec=30 -StartLimitInterval=0 - -[Install] -WantedBy=default.target +Type=oneshot +ExecStart=/usr/libexec/bluebuild/default-flatpaks/user-flatpak-setup \ No newline at end of file diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup.timer b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup.timer new file mode 100644 index 00000000..023ea654 --- /dev/null +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Timer for user-flatpak-setup + +[Timer] +OnBootSec=30 + +[Install] +WantedBy=timers.target \ No newline at end of file From dd5ae9e4c5657d309889897b98940351754088ab Mon Sep 17 00:00:00 2001 From: fiftydinar <65243233+fiftydinar@users.noreply.github.com> Date: Sun, 10 Nov 2024 19:00:33 +0100 Subject: [PATCH 11/38] chore(default-flatpaks): Copy & enable timers instead of services --- modules/default-flatpaks/v2/default-flatpaks.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/default-flatpaks/v2/default-flatpaks.sh b/modules/default-flatpaks/v2/default-flatpaks.sh index de354d63..7eaf3bc8 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.sh +++ b/modules/default-flatpaks/v2/default-flatpaks.sh @@ -63,9 +63,11 @@ def main [configStr: string] { cp -r ($"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/*" | into glob) $usrSharePath cp $"($usrSharePath)/system-flatpak-setup.service" /usr/lib/systemd/system/system-flatpak-setup.service + cp $"($usrSharePath)/system-flatpak-setup.timer" /usr/lib/systemd/system/system-flatpak-setup.timer cp $"($usrSharePath)/user-flatpak-setup.service" /usr/lib/systemd/user/user-flatpak-setup.service - systemctl enable --force system-flatpak-setup.service - systemctl enable --force --global user-flatpak-setup.service + cp $"($usrSharePath)/user-flatpak-setup.timer" /usr/lib/systemd/system/system-flatpak-setup.timer + systemctl enable --force system-flatpak-setup.timer + systemctl enable --force --global user-flatpak-setup.timer cp $"($usrSharePath)/system-flatpak-setup" $"($libExecPath)/system-flatpak-setup" cp $"($usrSharePath)/user-flatpak-setup" $"($libExecPath)/user-flatpak-setup" @@ -83,4 +85,4 @@ def checkFlathub [packages: list] { exit 1 } } -} \ No newline at end of file +} From ed42c96920726195d0ed5ec05d4272efbe377df8 Mon Sep 17 00:00:00 2001 From: fiftydinar <65243233+fiftydinar@users.noreply.github.com> Date: Sun, 10 Nov 2024 19:01:19 +0100 Subject: [PATCH 12/38] chore(default-flatpaks): Fix typo for copying `user-flatpak-setup` timer --- modules/default-flatpaks/v2/default-flatpaks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/default-flatpaks/v2/default-flatpaks.sh b/modules/default-flatpaks/v2/default-flatpaks.sh index 7eaf3bc8..54d9a7eb 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.sh +++ b/modules/default-flatpaks/v2/default-flatpaks.sh @@ -65,7 +65,7 @@ def main [configStr: string] { cp $"($usrSharePath)/system-flatpak-setup.service" /usr/lib/systemd/system/system-flatpak-setup.service cp $"($usrSharePath)/system-flatpak-setup.timer" /usr/lib/systemd/system/system-flatpak-setup.timer cp $"($usrSharePath)/user-flatpak-setup.service" /usr/lib/systemd/user/user-flatpak-setup.service - cp $"($usrSharePath)/user-flatpak-setup.timer" /usr/lib/systemd/system/system-flatpak-setup.timer + cp $"($usrSharePath)/user-flatpak-setup.timer" /usr/lib/systemd/system/user-flatpak-setup.timer systemctl enable --force system-flatpak-setup.timer systemctl enable --force --global user-flatpak-setup.timer From 81d210ae5a4995f0eaf9f41f90ea9f378b040f49 Mon Sep 17 00:00:00 2001 From: fiftydinar <65243233+fiftydinar@users.noreply.github.com> Date: Sun, 10 Nov 2024 19:51:07 +0100 Subject: [PATCH 13/38] chore(default-flatpaks): Copy post-boot files directly instead of placing them in `/usr/share/...` --- modules/default-flatpaks/v2/default-flatpaks.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/default-flatpaks/v2/default-flatpaks.sh b/modules/default-flatpaks/v2/default-flatpaks.sh index 54d9a7eb..440eb4d1 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.sh +++ b/modules/default-flatpaks/v2/default-flatpaks.sh @@ -62,15 +62,15 @@ def main [configStr: string] { cp -r ($"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/*" | into glob) $usrSharePath - cp $"($usrSharePath)/system-flatpak-setup.service" /usr/lib/systemd/system/system-flatpak-setup.service - cp $"($usrSharePath)/system-flatpak-setup.timer" /usr/lib/systemd/system/system-flatpak-setup.timer - cp $"($usrSharePath)/user-flatpak-setup.service" /usr/lib/systemd/user/user-flatpak-setup.service - cp $"($usrSharePath)/user-flatpak-setup.timer" /usr/lib/systemd/system/user-flatpak-setup.timer + cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/system-flatpak-setup.service" /usr/lib/systemd/system/system-flatpak-setup.service + cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/system-flatpak-setup.timer" /usr/lib/systemd/system/system-flatpak-setup.timer + cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/user-flatpak-setup.service" /usr/lib/systemd/user/user-flatpak-setup.service + cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/user-flatpak-setup.timer" /usr/lib/systemd/system/user-flatpak-setup.timer systemctl enable --force system-flatpak-setup.timer systemctl enable --force --global user-flatpak-setup.timer - cp $"($usrSharePath)/system-flatpak-setup" $"($libExecPath)/system-flatpak-setup" - cp $"($usrSharePath)/user-flatpak-setup" $"($libExecPath)/user-flatpak-setup" + cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/system-flatpak-setup" $"($libExecPath)/system-flatpak-setup" + cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/user-flatpak-setup" $"($libExecPath)/user-flatpak-setup" chmod +x $"($libExecPath)/system-flatpak-setup" chmod +x $"($libExecPath)/user-flatpak-setup" } From d83856db5f30afafa7b8a9429a7873adab77a06d Mon Sep 17 00:00:00 2001 From: fiftydinar <65243233+fiftydinar@users.noreply.github.com> Date: Sun, 10 Nov 2024 19:52:25 +0100 Subject: [PATCH 14/38] chore(default-flatpaks): Forgot to remove copying step of post-boot files to `/usr/share/...` --- modules/default-flatpaks/v2/default-flatpaks.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/default-flatpaks/v2/default-flatpaks.sh b/modules/default-flatpaks/v2/default-flatpaks.sh index 440eb4d1..1ef665e0 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.sh +++ b/modules/default-flatpaks/v2/default-flatpaks.sh @@ -60,8 +60,6 @@ def main [configStr: string] { print "Setting up Flatpak setup services..." - cp -r ($"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/*" | into glob) $usrSharePath - cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/system-flatpak-setup.service" /usr/lib/systemd/system/system-flatpak-setup.service cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/system-flatpak-setup.timer" /usr/lib/systemd/system/system-flatpak-setup.timer cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/user-flatpak-setup.service" /usr/lib/systemd/user/user-flatpak-setup.service From 97fea2115589e516e04ee4795161531d65b1e9c4 Mon Sep 17 00:00:00 2001 From: xyny Date: Mon, 6 Jan 2025 12:02:35 +0200 Subject: [PATCH 15/38] chore: update to be in accordance with cli support for nushell --- .../v2/{default-flatpaks.sh => default-flatpaks.nu} | 2 +- modules/default-flatpaks/v2/post-boot/system-flatpak-setup | 2 +- modules/default-flatpaks/v2/post-boot/user-flatpak-setup | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename modules/default-flatpaks/v2/{default-flatpaks.sh => default-flatpaks.nu} (99%) diff --git a/modules/default-flatpaks/v2/default-flatpaks.sh b/modules/default-flatpaks/v2/default-flatpaks.nu similarity index 99% rename from modules/default-flatpaks/v2/default-flatpaks.sh rename to modules/default-flatpaks/v2/default-flatpaks.nu index 1ef665e0..9b0245c4 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.sh +++ b/modules/default-flatpaks/v2/default-flatpaks.nu @@ -1,4 +1,4 @@ -#!/usr/bin/env nu +#!/usr/libexec/bluebuild/nu/nu const flathubURL = "https://dl.flathub.org/repo/flathub.flatpakrepo" diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup index e7403826..d6beb572 100644 --- a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup @@ -1,4 +1,4 @@ -#!/usr/bin/env nu +#!/usr/libexec/bluebuild/nu/nu const usrSharePath = "/usr/share/bluebuild/default-flatpaks" const configPath = $"($usrSharePath)/configuration.yaml" diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup index fb62dba9..56414641 100644 --- a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup @@ -1,4 +1,4 @@ -#!/usr/bin/env nu +#!/usr/libexec/bluebuild/nu/nu const usrSharePath = "/usr/share/bluebuild/default-flatpaks" const configPath = $"($usrSharePath)/configuration.yaml" From 4b2311067e2585c179dbe0c9096e73b2e3e0aebe Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 19 Jan 2025 12:10:13 +0200 Subject: [PATCH 16/38] feat: allow usage of fedora flatpak remote, remove fedora flatpaks and runtimes --- .../v2/post-boot/system-flatpak-setup | 18 ++++++++++--- .../v2/post-boot/user-flatpak-setup | 27 ++++++++++++++----- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup index d6beb572..2b2a87df 100644 --- a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup @@ -6,12 +6,16 @@ const configPath = $"($usrSharePath)/configuration.yaml" def main [] { let configFile = open $configPath + let keepFedora = configFile.configurations | where scope == system | any {|config| + $config.repo.url == "oci+https://registry.fedoraproject.org" + } + let systemRemotes = (flatpak remotes --system --columns name | split row "\n") - if ($systemRemotes | any {|remote| $remote == "fedora" or $remote == "fedora-testing"}) { + if (not $keepFedora and $systemRemotes | any {|remote| $remote == "fedora" or $remote == "fedora-testing"}) { /usr/bin/gnome-software --quit /usr/lib/fedora-third-party/fedora-third-party-opt-out /usr/bin/fedora-third-party disable - + if ($systemRemotes | any {|remote| $remote == "fedora"}) { flatpak remote-delete --system fedora --force } @@ -19,7 +23,15 @@ def main [] { flatpak remote-delete --system fedora-testing --force } - # TODO remove Fedora Flatpaks + let fedoraApps = flatpak list --system --app --columns=origin,application | detect columns --no-headers | where column0 == fedora | get column1 + if ($fedoraApps | length > 0) { + flatpak remove --system --noninteractive ...$fedoraApps + } + + let fedoraRuntimes = flatpak list --system --runtime --columns=origin,application,arch,branch | detect columns --no-headers | where column0 == fedora | each {|i| $"($i.column1)/($i.column2)/($i.column3)" } + if ($fedoraRuntimes | length > 0) { + flatpak remove --system --noninteractive ...$fedoraRuntimes + } } $configFile.configurations | where scope == system | each { |config| diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup index 56414641..d630fc9f 100644 --- a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup @@ -6,14 +6,29 @@ const configPath = $"($usrSharePath)/configuration.yaml" def main [] { let configFile = open $configPath - let userRemotes = (flatpak remotes --user --columns name | split row "\n") - if ($userRemotes | any {|remote| $remote == "fedora"}) { - flatpak remote-delete --user fedora --force - } - if ($userRemotes | any {|remote| $remote == "fedora-testing"}) { - flatpak remote-delete --user fedora-testing --force + let keepFedora = configFile.configurations | where scope == user | any {|config| + $config.repo.url == "oci+https://registry.fedoraproject.org" } + let userRemotes = (flatpak remotes --user --columns name | split row "\n") + if (not $keepFedora) { + if ($userRemotes | any {|remote| $remote == "fedora"}) { + flatpak remote-delete --user fedora --force + } + if ($userRemotes | any {|remote| $remote == "fedora-testing"}) { + flatpak remote-delete --user fedora-testing --force + } + + let fedoraApps = flatpak list --user --app --columns=origin,application | detect columns --no-headers | where column0 == fedora | get column1 + if ($fedoraApps | length > 0) { + flatpak remove --user --noninteractive ...$fedoraApps + } + + let fedoraRuntimes = flatpak list --user --runtime --columns=origin,application,arch,branch | detect columns --no-headers | where column0 == fedora | each {|i| $"($i.column1)/($i.column2)/($i.column3)" } + if ($fedoraRuntimes | length > 0) { + flatpak remove --user --noninteractive ...$fedoraRuntimes + } + } $configFile.configurations | where scope == user | each { |config| flatpak remote-add --user --if-not-exists $config.repo.name $config.repo.url --title $config.repo.title From 2de6e0b9ce9392066950af63043cc06bf46d4e9e Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 19 Jan 2025 12:20:51 +0200 Subject: [PATCH 17/38] feat: refactor schema to support multiple versions of the module --- modules/default-flatpaks/default-flatpaks.tsp | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/modules/default-flatpaks/default-flatpaks.tsp b/modules/default-flatpaks/default-flatpaks.tsp index 4254cbee..4d4ade6d 100644 --- a/modules/default-flatpaks/default-flatpaks.tsp +++ b/modules/default-flatpaks/default-flatpaks.tsp @@ -2,11 +2,16 @@ import "@typespec/json-schema"; using TypeSpec.JsonSchema; @jsonSchema("/modules/default-flatpaks.json") -model DefaultFlatpaksModule { +union DefaultFlatpaksModule { + DefaultFlatpaksV1; + DefaultFlatpaksV2; +} + +model DefaultFlatpaksV1 { /** The default-flatpaks module can be used to install or uninstall flatpaks from a configurable remote on every boot. * https://blue-build.org/reference/modules/default-flatpaks/ - */ - type: "default-flatpaks"; + */ + type: "default-flatpaks@v1"; /** Whether to send a notification after the install/uninstall is finished. */ notify?: boolean = false; @@ -46,4 +51,34 @@ model DefaultFlatpaksModule { /** List of Flatpak IDs to remove. */ remove?: Array; }; +} + +model DefaultFlatpaksV2 { + /** The default-flatpaks module can be used to install Flatpaks from a configurable remote on every boot. + * https://blue-build.org/reference/modules/default-flatpaks/ + */ + type: "default-flatpaks@v2" | "default-flatpaks@latest" | "default-flatpaks"; + + configurations: Array<{ + /** Whether to notify users about Flatpak installation (default: true). */ + notify?: boolean; + + /** Whether to perform this configuration for system-wide or separately for each user (default: user). */ + scope?: "system" | "user"; + + /** Details of the Flatpak repository to set up. (default: flathub) */ + repo?: { + /** Flatpak repository URL (default: https://dl.flathub.org/repo/flathub.flatpakrepo). */ + url?: string; + + /** Flatpak repository name (default: flathub). */ + name?: string; + + /** Flatpak repository formatted title (default: Flathub). */ + title?: string; + }; + + /** List of Flatpak IDs to install from the repo. */ + install?: Array; + }>; } \ No newline at end of file From 56fa5551c0b2fbd362ce3f1371da9f4acdd9fbbd Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 19 Jan 2025 12:43:40 +0200 Subject: [PATCH 18/38] docs: separate docs for separate module versions --- modules/default-flatpaks/module.yml | 86 +++++++++++++-------- modules/default-flatpaks/{ => v1}/README.md | 0 modules/default-flatpaks/v2/README.md | 5 ++ 3 files changed, 57 insertions(+), 34 deletions(-) rename modules/default-flatpaks/{ => v1}/README.md (100%) create mode 100644 modules/default-flatpaks/v2/README.md diff --git a/modules/default-flatpaks/module.yml b/modules/default-flatpaks/module.yml index f9fffb55..c14c0f0b 100644 --- a/modules/default-flatpaks/module.yml +++ b/modules/default-flatpaks/module.yml @@ -1,37 +1,55 @@ name: default-flatpaks shortdesc: The default-flatpaks module can be used to install or uninstall flatpaks from a configurable remote on every boot. -example: | - modules: # configured multiple times to highlight how options are overridden - - type: default-flatpaks - notify: true # Send notification after install/uninstall is finished (true/false) - system: - # If no repo information is specified, Flathub will be used by default - repo-url: https://dl.flathub.org/repo/flathub.flatpakrepo - repo-name: flathub - repo-title: "Flathub (system-wide)" # Optional; this sets the remote's user-facing name in graphical frontends like GNOME Software - install: - - org.gnome.Loupe - - one.ablaze.floorp//lightning # This is an example of flatpak which has multiple branches in selection (flatpak//branch). - # Flatpak runtimes are not supported (like org.winehq.Wine//stable-23.08). - # Only normal flatpak applications are (like Floorp Lightning web browser in this example). - # Multiple install of same flatpaks with different branches is not supported. - remove: - - org.gnome.eog - # A flatpak repo can also be added without having to install flatpaks, - # as long as one of the repo- fields is present - user: - repo-name: flathub +versions: + - version: v1 + example: | + modules: # configured multiple times to highlight how options are overridden + - type: default-flatpaks + notify: true # Send notification after install/uninstall is finished (true/false) + system: + # If no repo information is specified, Flathub will be used by default + repo-url: https://dl.flathub.org/repo/flathub.flatpakrepo + repo-name: flathub + repo-title: "Flathub (system-wide)" # Optional; this sets the remote's user-facing name in graphical frontends like GNOME Software + install: + - org.gnome.Loupe + - one.ablaze.floorp//lightning # This is an example of flatpak which has multiple branches in selection (flatpak//branch). + # Flatpak runtimes are not supported (like org.winehq.Wine//stable-23.08). + # Only normal flatpak applications are (like Floorp Lightning web browser in this example). + # Multiple install of same flatpaks with different branches is not supported. + remove: + - org.gnome.eog + # A flatpak repo can also be added without having to install flatpaks, + # as long as one of the repo- fields is present + user: + repo-name: flathub - # Assuming that the above example is configured first in a recipe, - # a subsequent usage might look like this: - - type: default-flatpaks - system: - # If the repo-* fields are omitted on the subsequent usage, - # the module will use the previously configured repo. - # Otherwise, it will overwrite the repo configuration. - install: - - org.kde.kdenlive # this Flatpak is appended to the install list - user: - # repo-name will overwrite the previously-configured repo-name for the user remote - repo-name: flathub-user - repo-title: "Flathub (User) + # Assuming that the above example is configured first in a recipe, + # a subsequent usage might look like this: + - type: default-flatpaks + system: + # If the repo-* fields are omitted on the subsequent usage, + # the module will use the previously configured repo. + # Otherwise, it will overwrite the repo configuration. + install: + - org.kde.kdenlive # this Flatpak is appended to the install list + user: + # repo-name will overwrite the previously-configured repo-name for the user remote + repo-name: flathub-user + repo-title: "Flathub (User + - version: v2 + example: | + - type: default-flatpaks + configurations: + - notify: true + scope: user + repo: + title: Flathub (user) + install: + - io.gitlab.leesonwai.Sums + - io.github.nokse22.minitext + - notify: true + scope: system + install: + - xyz.splashmapper.Splash + - xyz.safeworlds.hiit diff --git a/modules/default-flatpaks/README.md b/modules/default-flatpaks/v1/README.md similarity index 100% rename from modules/default-flatpaks/README.md rename to modules/default-flatpaks/v1/README.md diff --git a/modules/default-flatpaks/v2/README.md b/modules/default-flatpaks/v2/README.md new file mode 100644 index 00000000..e3a757c2 --- /dev/null +++ b/modules/default-flatpaks/v2/README.md @@ -0,0 +1,5 @@ +# `default-flatpaks` + +The `default-flatpaks` module can be used to install Flatpaks from a configurable remote on every boot. + +This documentation page is a draft. \ No newline at end of file From fefcde555b518dcfd9c77fd6e638fc7f918ce71f Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 19 Jan 2025 12:49:15 +0200 Subject: [PATCH 19/38] fix: copy user-flatpak-setup.timer to correct directory --- modules/default-flatpaks/v2/default-flatpaks.nu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/default-flatpaks/v2/default-flatpaks.nu b/modules/default-flatpaks/v2/default-flatpaks.nu index 9b0245c4..d8aa9ce6 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.nu +++ b/modules/default-flatpaks/v2/default-flatpaks.nu @@ -63,7 +63,7 @@ def main [configStr: string] { cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/system-flatpak-setup.service" /usr/lib/systemd/system/system-flatpak-setup.service cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/system-flatpak-setup.timer" /usr/lib/systemd/system/system-flatpak-setup.timer cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/user-flatpak-setup.service" /usr/lib/systemd/user/user-flatpak-setup.service - cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/user-flatpak-setup.timer" /usr/lib/systemd/system/user-flatpak-setup.timer + cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/user-flatpak-setup.timer" /usr/lib/systemd/user/user-flatpak-setup.timer systemctl enable --force system-flatpak-setup.timer systemctl enable --force --global user-flatpak-setup.timer From 44fb9061a7a4a49294dce102545ccffdd5b40434 Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 19 Jan 2025 12:56:08 +0200 Subject: [PATCH 20/38] chore: correctly document default values in schema --- modules/default-flatpaks/default-flatpaks.tsp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/default-flatpaks/default-flatpaks.tsp b/modules/default-flatpaks/default-flatpaks.tsp index 4d4ade6d..1cff698e 100644 --- a/modules/default-flatpaks/default-flatpaks.tsp +++ b/modules/default-flatpaks/default-flatpaks.tsp @@ -60,22 +60,22 @@ model DefaultFlatpaksV2 { type: "default-flatpaks@v2" | "default-flatpaks@latest" | "default-flatpaks"; configurations: Array<{ - /** Whether to notify users about Flatpak installation (default: true). */ - notify?: boolean; + /** Whether to notify users about Flatpak installation. */ + notify?: boolean = true; - /** Whether to perform this configuration for system-wide or separately for each user (default: user). */ - scope?: "system" | "user"; + /** Whether to perform this configuration for system-wide or separately for each user. */ + scope?: "system" | "user" = "user"; - /** Details of the Flatpak repository to set up. (default: flathub) */ + /** Details of the Flatpak repository to set up. If omitted, Flathub will be used by default. */ repo?: { - /** Flatpak repository URL (default: https://dl.flathub.org/repo/flathub.flatpakrepo). */ - url?: string; + /** Flatpak repository URL. */ + url?: string = "https://dl.flathub.org/repo/flathub.flatpakrepo"; - /** Flatpak repository name (default: flathub). */ - name?: string; + /** Flatpak repository name. */ + name?: string = "flathub"; - /** Flatpak repository formatted title (default: Flathub). */ - title?: string; + /** Flatpak repository formatted title. */ + title?: string = "Flathub"; }; /** List of Flatpak IDs to install from the repo. */ From aa741300f3a038576256ec54d5b635a0f0011d89 Mon Sep 17 00:00:00 2001 From: xyny Date: Tue, 18 Feb 2025 15:54:29 +0200 Subject: [PATCH 21/38] fix: better flathub package checking - use API url - check everything before erroring out --- modules/default-flatpaks/v2/default-flatpaks.nu | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/default-flatpaks/v2/default-flatpaks.nu b/modules/default-flatpaks/v2/default-flatpaks.nu index d8aa9ce6..d3def4f5 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.nu +++ b/modules/default-flatpaks/v2/default-flatpaks.nu @@ -75,12 +75,18 @@ def main [configStr: string] { def checkFlathub [packages: list] { print "Checking if configured packages exist on Flathub..." - $packages | each { |package| + let unavailablePackages = $packages | each { |package| try { - let _ = http get $"https://flathub.org/apps/($package)" + http get $"https://flathub.org/api/v2/stats/($package)" } catch { - print $"(ansi red_bold)Package(ansi reset) (ansi default_italic)($package)(ansi reset) (ansi red_bold)does not exist on Flathub, which is the specified repository for it to be installed from.(ansi reset)" - exit 1 + $package + } + } + if ($unavailablePackages | length) > 0 { + print $"(ansi red_bold)The following packages are not available on Flathub, which is the specified repository for them to be installed from:(ansi reset) " + for package in $unavailablePackages { + print $"(ansi default_italic)($package)(ansi reset)" } + exit 1 } } From b42d1e4521b04479de6d1bd4f38309d5eb9404df Mon Sep 17 00:00:00 2001 From: xyny Date: Tue, 18 Feb 2025 16:05:29 +0200 Subject: [PATCH 22/38] feat: warn users when giving this module v1 configuration --- modules/default-flatpaks/v2/default-flatpaks.nu | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/default-flatpaks/v2/default-flatpaks.nu b/modules/default-flatpaks/v2/default-flatpaks.nu index d3def4f5..42f35281 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.nu +++ b/modules/default-flatpaks/v2/default-flatpaks.nu @@ -19,6 +19,13 @@ const configPath = $"($usrSharePath)/configuration.yaml" def main [configStr: string] { let config = $configStr | from yaml + + let columns = $config | columns + if ($columns | where $it == "system" | length) > 0 or ($columns | where $it == "user" | length) > 0 { + print $"(ansi yellow_reverse)HINT(ansi reset) It seems like you are trying to run the new (ansi default_italic)default-flatpaks@v2(ansi reset) module with configuration made for the older version." + print $"You can read the docs to migrate to the new and improved module, or just change your configuration to use (ansi default_italic)default-flatpaks@v1(ansi reset) instead." + exit 1 + } let configurations = $config.configurations | each {|configuration| mut merged = $defaultConfiguration | merge $configuration From 5c032d2f97cc49294da73116379469bfaa81eac6 Mon Sep 17 00:00:00 2001 From: xyny Date: Tue, 18 Feb 2025 17:00:46 +0200 Subject: [PATCH 23/38] fix: prevent addition of http get result into unavailablePackages list --- modules/default-flatpaks/v2/default-flatpaks.nu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/default-flatpaks/v2/default-flatpaks.nu b/modules/default-flatpaks/v2/default-flatpaks.nu index 42f35281..96aff79b 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.nu +++ b/modules/default-flatpaks/v2/default-flatpaks.nu @@ -84,7 +84,7 @@ def checkFlathub [packages: list] { print "Checking if configured packages exist on Flathub..." let unavailablePackages = $packages | each { |package| try { - http get $"https://flathub.org/api/v2/stats/($package)" + let _ = http get $"https://flathub.org/api/v2/stats/($package)" } catch { $package } From ab7db0d0cc5ef6fb62bf20e5404c306db46a8bc9 Mon Sep 17 00:00:00 2001 From: xyny Date: Tue, 18 Feb 2025 17:09:15 +0200 Subject: [PATCH 24/38] fix: mkdir before cp --- modules/default-flatpaks/v2/default-flatpaks.nu | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/default-flatpaks/v2/default-flatpaks.nu b/modules/default-flatpaks/v2/default-flatpaks.nu index 96aff79b..6d81dc80 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.nu +++ b/modules/default-flatpaks/v2/default-flatpaks.nu @@ -67,13 +67,16 @@ def main [configStr: string] { print "Setting up Flatpak setup services..." + mkdir /usr/lib/systemd/system/ cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/system-flatpak-setup.service" /usr/lib/systemd/system/system-flatpak-setup.service cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/system-flatpak-setup.timer" /usr/lib/systemd/system/system-flatpak-setup.timer + mkdir /usr/lib/systemd/user/ cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/user-flatpak-setup.service" /usr/lib/systemd/user/user-flatpak-setup.service cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/user-flatpak-setup.timer" /usr/lib/systemd/user/user-flatpak-setup.timer systemctl enable --force system-flatpak-setup.timer systemctl enable --force --global user-flatpak-setup.timer + mkdir ($libExecPath) cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/system-flatpak-setup" $"($libExecPath)/system-flatpak-setup" cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/user-flatpak-setup" $"($libExecPath)/user-flatpak-setup" chmod +x $"($libExecPath)/system-flatpak-setup" From 0083dce5f4e1e193a73a5db00969ef43a623a28e Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 15 Jun 2025 16:50:32 +0300 Subject: [PATCH 25/38] chore: fix () semantics problems highlighted by debugger --- modules/default-flatpaks/v2/post-boot/system-flatpak-setup | 6 +++--- modules/default-flatpaks/v2/post-boot/user-flatpak-setup | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup index 2b2a87df..4f1f25ed 100644 --- a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup @@ -11,7 +11,7 @@ def main [] { } let systemRemotes = (flatpak remotes --system --columns name | split row "\n") - if (not $keepFedora and $systemRemotes | any {|remote| $remote == "fedora" or $remote == "fedora-testing"}) { + if (not $keepFedora and ($systemRemotes | any {|remote| $remote == "fedora" or $remote == "fedora-testing"})) { /usr/bin/gnome-software --quit /usr/lib/fedora-third-party/fedora-third-party-opt-out /usr/bin/fedora-third-party disable @@ -24,12 +24,12 @@ def main [] { } let fedoraApps = flatpak list --system --app --columns=origin,application | detect columns --no-headers | where column0 == fedora | get column1 - if ($fedoraApps | length > 0) { + if (($fedoraApps | length) > 0) { flatpak remove --system --noninteractive ...$fedoraApps } let fedoraRuntimes = flatpak list --system --runtime --columns=origin,application,arch,branch | detect columns --no-headers | where column0 == fedora | each {|i| $"($i.column1)/($i.column2)/($i.column3)" } - if ($fedoraRuntimes | length > 0) { + if (($fedoraRuntimes | length) > 0) { flatpak remove --system --noninteractive ...$fedoraRuntimes } } diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup index d630fc9f..7a241826 100644 --- a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup @@ -20,12 +20,12 @@ def main [] { } let fedoraApps = flatpak list --user --app --columns=origin,application | detect columns --no-headers | where column0 == fedora | get column1 - if ($fedoraApps | length > 0) { + if (($fedoraApps | length) > 0) { flatpak remove --user --noninteractive ...$fedoraApps } let fedoraRuntimes = flatpak list --user --runtime --columns=origin,application,arch,branch | detect columns --no-headers | where column0 == fedora | each {|i| $"($i.column1)/($i.column2)/($i.column3)" } - if ($fedoraRuntimes | length > 0) { + if (($fedoraRuntimes | length) > 0) { flatpak remove --user --noninteractive ...$fedoraRuntimes } } From ffd8d5acdd80b66a2d55f03a425d3d42d57082ed Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 15 Jun 2025 17:48:46 +0300 Subject: [PATCH 26/38] feat: bluebuild-flatpak-manager CLI --- .../default-flatpaks/v2/default-flatpaks.nu | 3 + .../v2/post-boot/bluebuild-flatpak-manager | 97 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 modules/default-flatpaks/v2/post-boot/bluebuild-flatpak-manager diff --git a/modules/default-flatpaks/v2/default-flatpaks.nu b/modules/default-flatpaks/v2/default-flatpaks.nu index 6d81dc80..d35dce8e 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.nu +++ b/modules/default-flatpaks/v2/default-flatpaks.nu @@ -81,6 +81,9 @@ def main [configStr: string] { cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/user-flatpak-setup" $"($libExecPath)/user-flatpak-setup" chmod +x $"($libExecPath)/system-flatpak-setup" chmod +x $"($libExecPath)/user-flatpak-setup" + + cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/bluebuild-flatpak-manager" "/usr/bin/bluebuild-flatpak-manager" + chmod +x "/usr/bin/bluebuild-flatpak-manager" } def checkFlathub [packages: list] { diff --git a/modules/default-flatpaks/v2/post-boot/bluebuild-flatpak-manager b/modules/default-flatpaks/v2/post-boot/bluebuild-flatpak-manager new file mode 100644 index 00000000..4b9f5e8e --- /dev/null +++ b/modules/default-flatpaks/v2/post-boot/bluebuild-flatpak-manager @@ -0,0 +1,97 @@ +#!/usr/libexec/bluebuild/nu/nu + +def main [] { + print "A CLI tool to manage the installation and setup of Flatpaks by the default-flatpaks BlueBuild module" + print + print $"(ansi default_underline)(ansi default_bold)Usage:(ansi reset) bluebuild-flatpak-manager [command] " + print + print $"(ansi default_underline)(ansi default_bold)Commands:(ansi reset)" + print $" (ansi default_bold)show:(ansi reset) Print out all changes configured to be done by the default-flatpaks module" + print $" (ansi default_bold)apply :(ansi reset) Manually initiate the setup of Flatpaks" + print $" (ansi default_bold)disable :(ansi reset) Disable the automatic setup of Flatpaks" + print $" (ansi default_bold)enable :(ansi reset) Enable the automatic setup of Flatpaks" +} + +def "main show" [] { + let configurations = open "/usr/share/bluebuild/default-flatpaks/configuration.yaml" + print $"Found (ansi default_italic)($configurations | length)(ansi reset) configuration\(s)" + + for config in $configurations { + print + print $" ($config.install | length) (ansi default_italic)($config.scope)(ansi reset) Flatpak\(s\) from (ansi default_italic)($config.repo.title)(ansi reset) \((ansi default_italic)($config.repo.url)(ansi reset)\)" + if ($config.notify) { + print $" (ansi default_italic)Installer will notify user(ansi reset)" + } else { + print $" (ansi default_italic)Installer will not notify user(ansi reset)" + } + print $" Flatpak\(s) to be installed:" + $config.install | each {|package| + print $" ($package)" + } + + } +} + +def "main apply" [] { + print $"(ansi default_underline)(ansi default_bold)Usage:(ansi reset)" + print $" (ansi default_italic)bluebuild-flatpak-manager apply all(ansi reset): install and setup both system and user Flatpaks" + print $" (ansi default_italic)bluebuild-flatpak-manager apply user(ansi reset): install and setup user Flatpaks" + print $" (ansi default_italic)bluebuild-flatpak-manager apply system(ansi reset): install and setup system Flatpaks" +} + +def "main apply user" [] { + /usr/libexec/bluebuild/default-flatpaks/user-flatpak-setup +} + +def "main apply system" [] { + /usr/libexec/bluebuild/default-flatpaks/system-flatpak-setup +} + +def "main apply all" [] { + main apply user + main apply system +} + +def "main disable" [] { + print $"(ansi default_underline)(ansi default_bold)Usage:(ansi reset)" + print $" (ansi default_italic)bluebuild-flatpak-manager disable all(ansi reset): disable automatic setup for both system Flatpaks and user Flatpaks" + print $" (ansi default_italic)bluebuild-flatpak-manager disable user(ansi reset): disable automatic setup for user Flatpaks" + print $" (ansi default_italic)bluebuild-flatpak-manager disable system(ansi reset): disable automatic setup for system Flatpaks" +} + +def "main disable user" [] { + print $"Running: (ansi default_italic)run0 systemctl disable --global user-flatpak-setup.timer(ansi reset)" + run0 systemctl disable --global user-flatpak-setup.timer +} + +def "main disable system" [] { + print $"Running: (ansi default_italic)systemctl disable --now system-flatpak-setup.timer(ansi reset)" + systemctl disable --now system-flatpak-setup.timer +} + +def "main disable all" [] { + main disable system + main disable user +} + +def "main enable" [] { + print $"(ansi default_underline)(ansi default_bold)Usage:(ansi reset)" + print $" (ansi default_italic)bluebuild-flatpak-manager enable all(ansi reset): enable automatic setup for both system Flatpaks and user Flatpaks" + print $" (ansi default_italic)bluebuild-flatpak-manager enable user(ansi reset): enable automatic setup for user Flatpaks" + print $" (ansi default_italic)bluebuild-flatpak-manager enable system(ansi reset): enable automatic setup for system Flatpaks" +} + +def "main enable user" [] { + print $"Running: (ansi default_italic)run0 systemctl enable --global user-flatpak-setup.timer(ansi reset)" + run0 systemctl enable --global user-flatpak-setup.timer +} + +def "main enable system" [] { + print $"Running: (ansi default_italic)systemctl enable --now system-flatpak-setup.timer(ansi reset)" + systemctl enable --now system-flatpak-setup.timer +} + +def "main enable all" [] { + main enable system + main enable user +} \ No newline at end of file From 993d5c67fba3bc83d62622bcae57eaa2431b32ac Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 15 Jun 2025 18:09:02 +0300 Subject: [PATCH 27/38] feat: alert user when trying to use module with old configuration --- modules/default-flatpaks/default-flatpaks.tsp | 4 +++- modules/default-flatpaks/v2/default-flatpaks.nu | 13 +++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/default-flatpaks/default-flatpaks.tsp b/modules/default-flatpaks/default-flatpaks.tsp index 1cff698e..e3e994c3 100644 --- a/modules/default-flatpaks/default-flatpaks.tsp +++ b/modules/default-flatpaks/default-flatpaks.tsp @@ -9,9 +9,10 @@ union DefaultFlatpaksModule { model DefaultFlatpaksV1 { /** The default-flatpaks module can be used to install or uninstall flatpaks from a configurable remote on every boot. + * using version: v1 * https://blue-build.org/reference/modules/default-flatpaks/ */ - type: "default-flatpaks@v1"; + type: "default-flatpaks@v1" | "default-flatpaks"; /** Whether to send a notification after the install/uninstall is finished. */ notify?: boolean = false; @@ -55,6 +56,7 @@ model DefaultFlatpaksV1 { model DefaultFlatpaksV2 { /** The default-flatpaks module can be used to install Flatpaks from a configurable remote on every boot. + * using version: v2 * https://blue-build.org/reference/modules/default-flatpaks/ */ type: "default-flatpaks@v2" | "default-flatpaks@latest" | "default-flatpaks"; diff --git a/modules/default-flatpaks/v2/default-flatpaks.nu b/modules/default-flatpaks/v2/default-flatpaks.nu index d35dce8e..f04d38d2 100644 --- a/modules/default-flatpaks/v2/default-flatpaks.nu +++ b/modules/default-flatpaks/v2/default-flatpaks.nu @@ -19,14 +19,15 @@ const configPath = $"($usrSharePath)/configuration.yaml" def main [configStr: string] { let config = $configStr | from yaml - - let columns = $config | columns - if ($columns | where $it == "system" | length) > 0 or ($columns | where $it == "user" | length) > 0 { - print $"(ansi yellow_reverse)HINT(ansi reset) It seems like you are trying to run the new (ansi default_italic)default-flatpaks@v2(ansi reset) module with configuration made for the older version." - print $"You can read the docs to migrate to the new and improved module, or just change your configuration to use (ansi default_italic)default-flatpaks@v1(ansi reset) instead." + + if ('user' in $config or 'system' in $config) { + print $"(ansi red_bold)CONFIGURATION ERROR(ansi reset)" + print $"(ansi yellow_reverse)HINT(ansi reset): the default-flatpaks module has been updated with breaking changes!" + print $"It seems like you are trying to run the new (ansi default_italic)default-flatpaks@v2(ansi reset) module with configuration made for the older version." + print $"You can read the docs to migrate to the new and improved module, or just change switch back to the old module like this (ansi default_italic)type: default-flatpaks@v1(ansi reset)" exit 1 } - + let configurations = $config.configurations | each {|configuration| mut merged = $defaultConfiguration | merge $configuration $merged.repo = $defaultConfiguration.repo | merge $merged.repo # make sure all repo properties exist From 8f790b835c80185d2cc75e2bc8c15a445dbf0fce Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 15 Jun 2025 19:21:25 +0300 Subject: [PATCH 28/38] docs: write basic documentation page and rewrite example --- modules/default-flatpaks/module.yml | 21 ++++++++------- modules/default-flatpaks/v2/README.md | 37 +++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/modules/default-flatpaks/module.yml b/modules/default-flatpaks/module.yml index c14c0f0b..64a51fe8 100644 --- a/modules/default-flatpaks/module.yml +++ b/modules/default-flatpaks/module.yml @@ -4,7 +4,7 @@ versions: - version: v1 example: | modules: # configured multiple times to highlight how options are overridden - - type: default-flatpaks + - type: default-flatpaks@v1 notify: true # Send notification after install/uninstall is finished (true/false) system: # If no repo information is specified, Flathub will be used by default @@ -41,15 +41,18 @@ versions: example: | - type: default-flatpaks configurations: - - notify: true - scope: user + - scope: user repo: + # you can override the title to make inclusion of both system and user repos clearer title: Flathub (user) - install: - - io.gitlab.leesonwai.Sums - - io.github.nokse22.minitext - notify: true scope: system - install: - - xyz.splashmapper.Splash - - xyz.safeworlds.hiit + repo: + title: Flathub (system) + install: # system flatpaks we want all users to have and not remove + - org.mozilla.firefox + - com.github.tchx84.Flatseal + - io.github.flattool.Warehouse + - io.missioncenter.MissionCenter + - com.github.rafostar.Clapper + - org.gnome.Loupe diff --git a/modules/default-flatpaks/v2/README.md b/modules/default-flatpaks/v2/README.md index e3a757c2..d0a0a2f7 100644 --- a/modules/default-flatpaks/v2/README.md +++ b/modules/default-flatpaks/v2/README.md @@ -1,5 +1,38 @@ # `default-flatpaks` -The `default-flatpaks` module can be used to install Flatpaks from a configurable remote on every boot. +The `default-flatpaks` module can be used to install Flatpaks from a configurable remote on every boot. By default the module will remove the Fedora Flatpak remote and install the Flathub remote, but you can also configure it to install other Flatpaks from other remotes. -This documentation page is a draft. \ No newline at end of file +## Features + +- System and user systemd services that based on your configuration + - Set up a Flatpak remote + - Install Flatpaks from the remote +- CLI tool `bluebuild-flatpak-manager` to + - Display the Flatpak configurations in the image + - Manually initiate the setup of Flatpaks + - Disable the automatic Flatpak setup + - Re-enable the automatic Flatpak setup + +## Configuration + +The `default-flatpaks` module configuration is based on a list of `configurations:` that each set a scope to install in (`system` or `user`), a Flatpak repository to set up, and a list of Flatpaks to install from the repository. + +Multiple configurations are supported and subsequent module calls will append new configurations to the list. Overriding previous configurations is currently not supported. + +### Scope + +The `scope:` property can be set to `system` or `user`. If omitted, the default is `user`. This property determines whether the Flatpak repository and packages are set up for the system or for each user separately. + +For a single-user system, you can safely use the `user` scope, since that will allow installation of Flatpaks from the configured repo and management of the installed Flatpaks without authentication. If you have multiple users for which you want to set up the same system Flatpaks, you should use the `system` scope. This ensures that the Flatpaks are not duplicated in each user's home directory, and that managing the Flatpaks requires admin permissions. + +### Flatpak repository + +The `repo:` property is used to configure the Flatpak repository to set up. If omitted, Flathub will be used by default. The URL should be a link to a `.flatpakrepo` file. The name and title are used to identify the repository in the Flatpak CLI, the name should be lowercase and not contain spaces, while the title can be any string. + +### Notification + +The `notify:` property can be set to `true` or `false`. If omitted, the default is `true`. This will send a notification on each boot to the user(s) when starting the Flatpak installation and when it is finished. + +### Flatpak installation + +The `install:` property is a list of the Flatpak IDs to install from the configured repository. If omitted, no Flatpaks will be installed, but the Flatpak repository will still be set up. If the repository to use is configured as Flathub, the list of Flatpaks will be validated at build time to ensure that the packages are available on Flathub. \ No newline at end of file From 24392156e84d23353219d6503dc5ae1f786f1f32 Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 15 Jun 2025 19:37:18 +0300 Subject: [PATCH 29/38] fix: attempt to use configFile variable without dollar sign --- modules/default-flatpaks/v2/post-boot/system-flatpak-setup | 2 +- modules/default-flatpaks/v2/post-boot/user-flatpak-setup | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup index 4f1f25ed..b49f3060 100644 --- a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup @@ -6,7 +6,7 @@ const configPath = $"($usrSharePath)/configuration.yaml" def main [] { let configFile = open $configPath - let keepFedora = configFile.configurations | where scope == system | any {|config| + let keepFedora = $configFile.configurations | where scope == system | any {|config| $config.repo.url == "oci+https://registry.fedoraproject.org" } diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup index 7a241826..183c5272 100644 --- a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup @@ -6,7 +6,7 @@ const configPath = $"($usrSharePath)/configuration.yaml" def main [] { let configFile = open $configPath - let keepFedora = configFile.configurations | where scope == user | any {|config| + let keepFedora = $configFile.configurations | where scope == user | any {|config| $config.repo.url == "oci+https://registry.fedoraproject.org" } From 19bd31ed88eb0e6e8358000ded48d4730fb1ad97 Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 15 Jun 2025 19:43:09 +0300 Subject: [PATCH 30/38] fix: no such things as .configurations (the file is the array) --- modules/default-flatpaks/v2/post-boot/system-flatpak-setup | 4 ++-- modules/default-flatpaks/v2/post-boot/user-flatpak-setup | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup index b49f3060..29138576 100644 --- a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup @@ -6,7 +6,7 @@ const configPath = $"($usrSharePath)/configuration.yaml" def main [] { let configFile = open $configPath - let keepFedora = $configFile.configurations | where scope == system | any {|config| + let keepFedora = $configFile | where scope == system | any {|config| $config.repo.url == "oci+https://registry.fedoraproject.org" } @@ -34,7 +34,7 @@ def main [] { } } - $configFile.configurations | where scope == system | each { |config| + $configFile | where scope == system | each { |config| flatpak remote-add --system --if-not-exists $config.repo.name $config.repo.url --title $config.repo.title if ($config.notify) { diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup index 183c5272..b5310fa3 100644 --- a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup @@ -6,7 +6,7 @@ const configPath = $"($usrSharePath)/configuration.yaml" def main [] { let configFile = open $configPath - let keepFedora = $configFile.configurations | where scope == user | any {|config| + let keepFedora = $configFile | where scope == user | any {|config| $config.repo.url == "oci+https://registry.fedoraproject.org" } @@ -30,7 +30,7 @@ def main [] { } } - $configFile.configurations | where scope == user | each { |config| + $configFile | where scope == user | each { |config| flatpak remote-add --user --if-not-exists $config.repo.name $config.repo.url --title $config.repo.title if ($config.notify) { From 41476ba404c6e15218c5252ee48b8a6a431adc12 Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 15 Jun 2025 19:43:57 +0300 Subject: [PATCH 31/38] fix: ensure no empty list is printed --- modules/default-flatpaks/v2/post-boot/system-flatpak-setup | 2 +- modules/default-flatpaks/v2/post-boot/user-flatpak-setup | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup index 29138576..a2af2a6e 100644 --- a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup @@ -34,7 +34,7 @@ def main [] { } } - $configFile | where scope == system | each { |config| + for config in ($configFile | where scope == system) { flatpak remote-add --system --if-not-exists $config.repo.name $config.repo.url --title $config.repo.title if ($config.notify) { diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup index b5310fa3..8f489043 100644 --- a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup @@ -30,7 +30,7 @@ def main [] { } } - $configFile | where scope == user | each { |config| + for config in ($configFile | where scope == user) { flatpak remote-add --user --if-not-exists $config.repo.name $config.repo.url --title $config.repo.title if ($config.notify) { From d1e48644e5d5e034dabb3ba30986c867c3442511 Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 15 Jun 2025 19:46:09 +0300 Subject: [PATCH 32/38] docs: add a quick note about learning to use the flatpak manager tool --- modules/default-flatpaks/v2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/default-flatpaks/v2/README.md b/modules/default-flatpaks/v2/README.md index d0a0a2f7..b149644c 100644 --- a/modules/default-flatpaks/v2/README.md +++ b/modules/default-flatpaks/v2/README.md @@ -12,6 +12,7 @@ The `default-flatpaks` module can be used to install Flatpaks from a configurabl - Manually initiate the setup of Flatpaks - Disable the automatic Flatpak setup - Re-enable the automatic Flatpak setup + - _run the `bluebuild-flatpak-manager` command for help and documentation_ ## Configuration From 188d0e8aab641101292f0f82435fd35a9b89a1cd Mon Sep 17 00:00:00 2001 From: xyny <60004820+xynydev@users.noreply.github.com> Date: Sun, 20 Jul 2025 15:49:02 +0000 Subject: [PATCH 33/38] fix(schema): distinquish between versions Co-authored-by: Gerald Pinder --- modules/default-flatpaks/default-flatpaks.tsp | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/default-flatpaks/default-flatpaks.tsp b/modules/default-flatpaks/default-flatpaks.tsp index ef992fe5..aac86841 100644 --- a/modules/default-flatpaks/default-flatpaks.tsp +++ b/modules/default-flatpaks/default-flatpaks.tsp @@ -2,6 +2,7 @@ import "@typespec/json-schema"; using TypeSpec.JsonSchema; @jsonSchema("/modules/default-flatpaks.json") +@oneOf union DefaultFlatpaksModule { DefaultFlatpaksV1; DefaultFlatpaksV2; From 10070cb3a861a1ac869f6f9c433c6af2f4d2f6f1 Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 20 Jul 2025 19:54:15 +0300 Subject: [PATCH 34/38] fix: add noninteractive flag to flatpak install commands --- .../default-flatpaks/v2/post-boot/system-flatpak-setup | 4 ++-- modules/default-flatpaks/v2/post-boot/user-flatpak-setup | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup index a2af2a6e..21e5f1b2 100644 --- a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup @@ -15,7 +15,7 @@ def main [] { /usr/bin/gnome-software --quit /usr/lib/fedora-third-party/fedora-third-party-opt-out /usr/bin/fedora-third-party disable - + if ($systemRemotes | any {|remote| $remote == "fedora"}) { flatpak remote-delete --system fedora --force } @@ -44,7 +44,7 @@ def main [] { ) } - flatpak install --system $config.repo.name ...$config.install + flatpak install --system --noninteractive $config.repo.name ...$config.install if ($config.notify) { (notify-send-as-user diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup index 8f489043..cdac2514 100644 --- a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup @@ -34,20 +34,20 @@ def main [] { flatpak remote-add --user --if-not-exists $config.repo.name $config.repo.url --title $config.repo.title if ($config.notify) { - (notify-send + (notify-send --app-name "Automatic Flatpak Installation Service" $"Starting automated installation of ($config.install | length) user Flatpak\(s) from ($config.repo.title)..." ) } - flatpak install --user $config.repo.name ...$config.install + flatpak install --user --noninteractive $config.repo.name ...$config.install if ($config.notify) { - (notify-send + (notify-send --app-name "Automatic Flatpak Installation Service" $"Finished automated installation of ($config.install | length) user Flatpak\(s) from ($config.repo.title)!" ($config.install | str join ', ') ) } } -} \ No newline at end of file +} From 0e173e94bc1e4801d6578d1f676a6cf4aa7f4404 Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 20 Jul 2025 20:43:21 +0300 Subject: [PATCH 35/38] fix: ensure repo to be used is enabled --- modules/default-flatpaks/v2/post-boot/system-flatpak-setup | 1 + modules/default-flatpaks/v2/post-boot/user-flatpak-setup | 1 + 2 files changed, 2 insertions(+) diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup index 21e5f1b2..e7256e0b 100644 --- a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup @@ -36,6 +36,7 @@ def main [] { for config in ($configFile | where scope == system) { flatpak remote-add --system --if-not-exists $config.repo.name $config.repo.url --title $config.repo.title + flatpak remote-modify --system --enable $config.repo.name if ($config.notify) { (notify-send-as-user diff --git a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup index cdac2514..3eb4a59c 100644 --- a/modules/default-flatpaks/v2/post-boot/user-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/user-flatpak-setup @@ -32,6 +32,7 @@ def main [] { for config in ($configFile | where scope == user) { flatpak remote-add --user --if-not-exists $config.repo.name $config.repo.url --title $config.repo.title + flatpak remote-modify --user --enable $config.repo.name if ($config.notify) { (notify-send From 2f99df4253efb04167f6bc9bd61baee7d9a8fb0e Mon Sep 17 00:00:00 2001 From: xyny Date: Sun, 20 Jul 2025 20:57:10 +0300 Subject: [PATCH 36/38] chore: ignore errors in notify wrapper just in case --- .../v2/post-boot/system-flatpak-setup | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup index e7256e0b..fc34527c 100644 --- a/modules/default-flatpaks/v2/post-boot/system-flatpak-setup +++ b/modules/default-flatpaks/v2/post-boot/system-flatpak-setup @@ -58,8 +58,12 @@ def main [] { } def notify-send-as-user [...args] { - let user_name = (loginctl list-sessions --json=short | from json | get user | get 0) - let uid = (loginctl list-sessions --json=short | from json | get uid | get 0) - let xdg_runtime_path = $"/run/user/($uid)" - sudo -u $user_name DBUS_SESSION_BUS_ADDRESS=unix:path=($xdg_runtime_path)/bus notify-send ...$args + # this works most of the time, sometimes not + # let's not let notification errors interrupt the rest of the module's function + do --ignore-errors { + let user_name = (loginctl list-sessions --json=short | from json | get user | get 0) + let uid = (loginctl list-sessions --json=short | from json | get uid | get 0) + let xdg_runtime_path = $"/run/user/($uid)" + sudo -u $user_name DBUS_SESSION_BUS_ADDRESS=unix:path=($xdg_runtime_path)/bus notify-send ...$args + } } From f62e37e2ad39e2211e98c4a73def288ec7dd6dd4 Mon Sep 17 00:00:00 2001 From: xyny Date: Sat, 26 Jul 2025 15:40:47 +0300 Subject: [PATCH 37/38] chore: add link to announcement --- modules/default-flatpaks/v2/README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/default-flatpaks/v2/README.md b/modules/default-flatpaks/v2/README.md index b149644c..30d5f997 100644 --- a/modules/default-flatpaks/v2/README.md +++ b/modules/default-flatpaks/v2/README.md @@ -1,5 +1,9 @@ # `default-flatpaks` +:::note +For instructions on migration from v1 to v2, see the [announcement blog post](/blog/default-flatpaks-v2). +::: + The `default-flatpaks` module can be used to install Flatpaks from a configurable remote on every boot. By default the module will remove the Fedora Flatpak remote and install the Flathub remote, but you can also configure it to install other Flatpaks from other remotes. ## Features @@ -16,7 +20,7 @@ The `default-flatpaks` module can be used to install Flatpaks from a configurabl ## Configuration -The `default-flatpaks` module configuration is based on a list of `configurations:` that each set a scope to install in (`system` or `user`), a Flatpak repository to set up, and a list of Flatpaks to install from the repository. +The `default-flatpaks` module configuration is based on a list of `configurations:` that each set a scope to install in (`system` or `user`), a Flatpak repository to set up, and a list of Flatpaks to install from the repository. Multiple configurations are supported and subsequent module calls will append new configurations to the list. Overriding previous configurations is currently not supported. @@ -36,4 +40,4 @@ The `notify:` property can be set to `true` or `false`. If omitted, the default ### Flatpak installation -The `install:` property is a list of the Flatpak IDs to install from the configured repository. If omitted, no Flatpaks will be installed, but the Flatpak repository will still be set up. If the repository to use is configured as Flathub, the list of Flatpaks will be validated at build time to ensure that the packages are available on Flathub. \ No newline at end of file +The `install:` property is a list of the Flatpak IDs to install from the configured repository. If omitted, no Flatpaks will be installed, but the Flatpak repository will still be set up. If the repository to use is configured as Flathub, the list of Flatpaks will be validated at build time to ensure that the packages are available on Flathub. From 2cf31c527d25c432efceea48583f2498e227716a Mon Sep 17 00:00:00 2001 From: xyny Date: Sat, 26 Jul 2025 16:04:44 +0300 Subject: [PATCH 38/38] docs: run through languagetool --- modules/default-flatpaks/v2/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/default-flatpaks/v2/README.md b/modules/default-flatpaks/v2/README.md index 30d5f997..09fc73a6 100644 --- a/modules/default-flatpaks/v2/README.md +++ b/modules/default-flatpaks/v2/README.md @@ -8,7 +8,7 @@ The `default-flatpaks` module can be used to install Flatpaks from a configurabl ## Features -- System and user systemd services that based on your configuration +- System and user systemd services that are based on your configuration - Set up a Flatpak remote - Install Flatpaks from the remote - CLI tool `bluebuild-flatpak-manager` to @@ -22,17 +22,17 @@ The `default-flatpaks` module can be used to install Flatpaks from a configurabl The `default-flatpaks` module configuration is based on a list of `configurations:` that each set a scope to install in (`system` or `user`), a Flatpak repository to set up, and a list of Flatpaks to install from the repository. -Multiple configurations are supported and subsequent module calls will append new configurations to the list. Overriding previous configurations is currently not supported. +Multiple configurations are supported, and subsequent module calls will append new configurations to the list. Overriding previous configurations is currently not supported. ### Scope The `scope:` property can be set to `system` or `user`. If omitted, the default is `user`. This property determines whether the Flatpak repository and packages are set up for the system or for each user separately. -For a single-user system, you can safely use the `user` scope, since that will allow installation of Flatpaks from the configured repo and management of the installed Flatpaks without authentication. If you have multiple users for which you want to set up the same system Flatpaks, you should use the `system` scope. This ensures that the Flatpaks are not duplicated in each user's home directory, and that managing the Flatpaks requires admin permissions. +For a single-user system, you can safely use the `user` scope, since that will allow installation of Flatpaks from the configured repo and management of the installed Flatpaks without authentication. If you have multiple users for whom you want to set up the same system Flatpaks, you should use the `system` scope. This ensures that the Flatpaks are not duplicated in each user's home directory, and that managing the Flatpaks requires admin permissions. ### Flatpak repository -The `repo:` property is used to configure the Flatpak repository to set up. If omitted, Flathub will be used by default. The URL should be a link to a `.flatpakrepo` file. The name and title are used to identify the repository in the Flatpak CLI, the name should be lowercase and not contain spaces, while the title can be any string. +The `repo:` property is used to configure the Flatpak repository to set up. If omitted, Flathub will be used by default. The URL should be a link to a `.flatpakrepo` file. The name and title are used to identify the repository in the Flatpak CLI; the name should be lowercase and not contain spaces, while the title can be any string. ### Notification