-
Notifications
You must be signed in to change notification settings - Fork 0
Add dnf Home Manager module for toolbox package management
#3
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
Draft
thrix-bot
wants to merge
1
commit into
main
Choose a base branch
from
dnf-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| { | ||
| config, | ||
| lib, | ||
| ... | ||
| }: let | ||
| cfg = config.dnf; | ||
|
|
||
| installScript = '' | ||
| test -f /run/.toolboxenv || exit | ||
|
|
||
| FEDORA_RELEASE=$(. /etc/os-release && echo "$VERSION_ID") | ||
|
|
||
| INSTALL="${lib.concatStringsSep " " cfg.install}" | ||
|
|
||
| ${lib.concatStrings (lib.mapAttrsToList (release: items: '' | ||
| if [ "$FEDORA_RELEASE" = "${release}" ]; then | ||
| INSTALL="$INSTALL ${lib.concatStringsSep " " items}" | ||
| fi | ||
| '') | ||
| cfg.releaseInstall)} | ||
|
|
||
| # Helper: run command with gum spinner if available, fallback to echo | ||
| _dnf_run() { | ||
| local title="$1"; shift | ||
| if command -v gum &>/dev/null; then | ||
| gum spin --spinner dot --title "$title" -- "$@" | ||
| else | ||
| echo -e "\e[32m$title\e[0m" | ||
| "$@" | ||
| fi | ||
| } | ||
|
|
||
| # Install items (dnf handles already-installed items gracefully) | ||
| if [ -n "$INSTALL" ]; then | ||
| _dnf_run "DNF: installing $INSTALL" /usr/bin/sudo dnf -y install $INSTALL | ||
| fi | ||
|
|
||
| # Upgrade all packages | ||
| ${lib.optionalString cfg.upgradeAll '' | ||
| _dnf_run "DNF: upgrading all packages" /usr/bin/sudo dnf -y upgrade | ||
| ''} | ||
| ''; | ||
| in { | ||
| options.dnf = { | ||
| enable = lib.mkEnableOption "DNF package management in toolbox containers"; | ||
|
|
||
| install = lib.mkOption { | ||
| type = lib.types.listOf lib.types.str; | ||
| default = []; | ||
| example = ["krb5-workstation" "@development-tools" "/path/to/local.rpm"]; | ||
| description = '' | ||
| Items to install via `dnf install`. Accepts anything dnf supports: | ||
| package names, group names (@group), paths, URLs, provides, etc. | ||
| Installed regardless of Fedora release version. | ||
| ''; | ||
| }; | ||
|
|
||
| releaseInstall = lib.mkOption { | ||
| type = lib.types.attrsOf (lib.types.listOf lib.types.str); | ||
| default = {}; | ||
| example = { | ||
| "41" = ["some-f41-pkg"]; | ||
| "42" = ["some-f42-pkg"]; | ||
| }; | ||
| description = '' | ||
| Per-Fedora-release items to install. Keys are VERSION_ID strings | ||
| (e.g. "41", "42"). Items are only installed when that release is | ||
| detected via /etc/os-release. | ||
| ''; | ||
| }; | ||
|
|
||
| upgradeAll = lib.mkOption { | ||
| type = lib.types.bool; | ||
| default = false; | ||
| description = "When true, run `dnf -y upgrade` (all packages) on every activation."; | ||
| }; | ||
| }; | ||
|
|
||
| config = lib.mkIf cfg.enable { | ||
| home.activation = { | ||
| dnfInstall = lib.hm.dag.entryAfter ["reloadSystemd"] installScript; | ||
| }; | ||
| }; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Hardcoding
/usr/bin/sudomay break on images without sudo or with it in a different path.In minimal or toolbox containers
sudomay be missing or not at/usr/bin/sudo, causing_dnf_runto fail even thoughdnfis present. Consider either detectingsudoand falling back to directdnfwhen absent, or just callingsudo dnf ...and relying on$PATHinstead of a hardcoded path.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sourcery-ai well, tbh if we want to make it right, we should rather check fi the user is not root, and if not require sudo ...