detached d57f4db

fix(repos): reorder chaotic-aur setup and add extra packages installation

- Install Chaotic-AUR keyring and mirrorlist BEFORE adding to pacman.conf
- Separate multilib and chaotic-aur configuration steps for clarity
- Add loadExtraPackages function to read and install packages from extra.packages file
- Install extra packages after repo setup with --needed flag to avoid duplication
- Fix setup order to prevent pacman errors when chaotic-aur not yet configured
commit
d57f4dbe20a76ccde105577fcc141145b85033a6
author
brice · · 2026-01-25 18:00 UTC
parent
9ecc46f
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +62 -10
M internal/application/handlers/repos_handler.go +62 -10
@@ -1,6 +1,7 @@
11 package handlers
22
33 import (
4+ "bufio"
45 "context"
56 "fmt"
67 "path/filepath"
@@ -8,6 +9,7 @@ import (
89
910 "github.com/bnema/archup/internal/application/commands"
1011 "github.com/bnema/archup/internal/application/dto"
12+ "github.com/bnema/archup/internal/config"
1113 "github.com/bnema/archup/internal/domain/packages"
1214 "github.com/bnema/archup/internal/domain/ports"
1315 )
@@ -60,25 +62,20 @@ func (h *ReposHandler) Handle(ctx context.Context, cmd commands.SetupRepositorie
6062 "aurHelper", repo.AURHelper())
6163
6264 pacmanConfPath := filepath.Join(cmd.MountPoint, "etc", "pacman.conf")
63- if repo.EnableMultilib() || repo.EnableChaotic() {
65+
66+ // Enable multilib first (doesn't require external files)
67+ if repo.EnableMultilib() {
6468 confBytes, err := h.fs.ReadFile(pacmanConfPath)
6569 if err != nil {
6670 return fail("Failed to read pacman.conf", err)
6771 }
68-
69- conf := string(confBytes)
70- if repo.EnableMultilib() {
71- conf = enableMultilibSection(conf)
72- }
73- if repo.EnableChaotic() {
74- conf = ensureChaoticRepo(conf)
75- }
76-
72+ conf := enableMultilibSection(string(confBytes))
7773 if err := h.fs.WriteFile(pacmanConfPath, []byte(conf), 0644); err != nil {
7874 return fail("Failed to write pacman.conf", err)
7975 }
8076 }
8177
78+ // For chaotic-aur: install keyring and mirrorlist BEFORE adding to pacman.conf
8279 if repo.EnableChaotic() {
8380 if _, err := h.chrExec.ExecuteInChroot(ctx, cmd.MountPoint, "pacman-key", "--recv-key", "3056513887B78AEB", "--keyserver", "keyserver.ubuntu.com"); err != nil {
8481 return fail("Failed to receive Chaotic-AUR key", err)
@@ -93,8 +90,19 @@ func (h *ReposHandler) Handle(ctx context.Context, cmd commands.SetupRepositorie
9390 "https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst"); err != nil {
9491 return fail("Failed to install Chaotic-AUR keyring", err)
9592 }
93+
94+ // Now that mirrorlist exists, add chaotic-aur to pacman.conf
95+ confBytes, err := h.fs.ReadFile(pacmanConfPath)
96+ if err != nil {
97+ return fail("Failed to read pacman.conf", err)
98+ }
99+ conf := ensureChaoticRepo(string(confBytes))
100+ if err := h.fs.WriteFile(pacmanConfPath, []byte(conf), 0644); err != nil {
101+ return fail("Failed to write pacman.conf", err)
102+ }
96103 }
97104
105+ // Sync repos after all config changes
98106 if repo.EnableMultilib() || repo.EnableChaotic() {
99107 if _, err := h.chrExec.ExecuteInChroot(ctx, cmd.MountPoint, "pacman", "-Sy", "--noconfirm"); err != nil {
100108 return fail("Failed to sync pacman repositories", err)
@@ -107,6 +115,19 @@ func (h *ReposHandler) Handle(ctx context.Context, cmd commands.SetupRepositorie
107115 }
108116 }
109117
118+ // Install extra packages from extra.packages file
119+ extraPkgs, err := h.loadExtraPackages()
120+ if err != nil {
121+ h.logger.Warn("Could not load extra.packages", "error", err)
122+ } else if len(extraPkgs) > 0 {
123+ h.logger.Info("Installing extra packages", "count", len(extraPkgs))
124+ args := append([]string{"-S", "--noconfirm", "--needed"}, extraPkgs...)
125+ if _, err := h.chrExec.ExecuteInChroot(ctx, cmd.MountPoint, "pacman", args...); err != nil {
126+ return fail("Failed to install extra packages", err)
127+ }
128+ h.logger.Info("Extra packages installed successfully")
129+ }
130+
110131 result.Success = true
111132 result.AURHelper = repo.AURHelper().String()
112133
@@ -114,6 +135,37 @@ func (h *ReposHandler) Handle(ctx context.Context, cmd commands.SetupRepositorie
114135 return result, nil
115136 }
116137
138+// loadExtraPackages reads the extra package list from file
139+func (h *ReposHandler) loadExtraPackages() ([]string, error) {
140+ packageFile := filepath.Join(config.DefaultInstallDir, config.ExtraPackagesFile)
141+
142+ content, err := h.fs.ReadFile(packageFile)
143+ if err != nil {
144+ return nil, fmt.Errorf("failed to read %s: %w", packageFile, err)
145+ }
146+
147+ var pkgs []string
148+ scanner := bufio.NewScanner(strings.NewReader(string(content)))
149+
150+ for scanner.Scan() {
151+ line := strings.TrimSpace(scanner.Text())
152+
153+ // Skip comments and empty lines
154+ if line == "" || strings.HasPrefix(line, "#") {
155+ continue
156+ }
157+
158+ pkgs = append(pkgs, line)
159+ }
160+
161+ if err := scanner.Err(); err != nil {
162+ return nil, fmt.Errorf("error reading package file: %w", err)
163+ }
164+
165+ h.logger.Info("Loaded extra packages from file", "file", packageFile, "count", len(pkgs))
166+ return pkgs, nil
167+}
168+
117169 func enableMultilibSection(conf string) string {
118170 lines := strings.Split(conf, "\n")
119171 inSection := false
@@ -1,6 +1,7 @@
1 package handlers1 package handlers
2 2
3 import (3 import (
4+ "bufio"
4 "context"5 "context"
5 "fmt"6 "fmt"
6 "path/filepath"7 "path/filepath"
@@ -8,6 +9,7 @@ import (
8 9
9 "github.com/bnema/archup/internal/application/commands"10 "github.com/bnema/archup/internal/application/commands"
10 "github.com/bnema/archup/internal/application/dto"11 "github.com/bnema/archup/internal/application/dto"
12+ "github.com/bnema/archup/internal/config"
11 "github.com/bnema/archup/internal/domain/packages"13 "github.com/bnema/archup/internal/domain/packages"
12 "github.com/bnema/archup/internal/domain/ports"14 "github.com/bnema/archup/internal/domain/ports"
13 )15 )
@@ -60,25 +62,20 @@ func (h *ReposHandler) Handle(ctx context.Context, cmd commands.SetupRepositorie
60 "aurHelper", repo.AURHelper())62 "aurHelper", repo.AURHelper())
61 63
62 pacmanConfPath := filepath.Join(cmd.MountPoint, "etc", "pacman.conf")64 pacmanConfPath := filepath.Join(cmd.MountPoint, "etc", "pacman.conf")
63- if repo.EnableMultilib() || repo.EnableChaotic() {65+
66+ // Enable multilib first (doesn't require external files)
67+ if repo.EnableMultilib() {
64 confBytes, err := h.fs.ReadFile(pacmanConfPath)68 confBytes, err := h.fs.ReadFile(pacmanConfPath)
65 if err != nil {69 if err != nil {
66 return fail("Failed to read pacman.conf", err)70 return fail("Failed to read pacman.conf", err)
67 }71 }
68-72+ conf := enableMultilibSection(string(confBytes))
69- conf := string(confBytes)
70- if repo.EnableMultilib() {
71- conf = enableMultilibSection(conf)
72- }
73- if repo.EnableChaotic() {
74- conf = ensureChaoticRepo(conf)
75- }
76-
77 if err := h.fs.WriteFile(pacmanConfPath, []byte(conf), 0644); err != nil {73 if err := h.fs.WriteFile(pacmanConfPath, []byte(conf), 0644); err != nil {
78 return fail("Failed to write pacman.conf", err)74 return fail("Failed to write pacman.conf", err)
79 }75 }
80 }76 }
81 77
78+ // For chaotic-aur: install keyring and mirrorlist BEFORE adding to pacman.conf
82 if repo.EnableChaotic() {79 if repo.EnableChaotic() {
83 if _, err := h.chrExec.ExecuteInChroot(ctx, cmd.MountPoint, "pacman-key", "--recv-key", "3056513887B78AEB", "--keyserver", "keyserver.ubuntu.com"); err != nil {80 if _, err := h.chrExec.ExecuteInChroot(ctx, cmd.MountPoint, "pacman-key", "--recv-key", "3056513887B78AEB", "--keyserver", "keyserver.ubuntu.com"); err != nil {
84 return fail("Failed to receive Chaotic-AUR key", err)81 return fail("Failed to receive Chaotic-AUR key", err)
@@ -93,8 +90,19 @@ func (h *ReposHandler) Handle(ctx context.Context, cmd commands.SetupRepositorie
93 "https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst"); err != nil {90 "https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst"); err != nil {
94 return fail("Failed to install Chaotic-AUR keyring", err)91 return fail("Failed to install Chaotic-AUR keyring", err)
95 }92 }
93+
94+ // Now that mirrorlist exists, add chaotic-aur to pacman.conf
95+ confBytes, err := h.fs.ReadFile(pacmanConfPath)
96+ if err != nil {
97+ return fail("Failed to read pacman.conf", err)
98+ }
99+ conf := ensureChaoticRepo(string(confBytes))
100+ if err := h.fs.WriteFile(pacmanConfPath, []byte(conf), 0644); err != nil {
101+ return fail("Failed to write pacman.conf", err)
102+ }
96 }103 }
97 104
105+ // Sync repos after all config changes
98 if repo.EnableMultilib() || repo.EnableChaotic() {106 if repo.EnableMultilib() || repo.EnableChaotic() {
99 if _, err := h.chrExec.ExecuteInChroot(ctx, cmd.MountPoint, "pacman", "-Sy", "--noconfirm"); err != nil {107 if _, err := h.chrExec.ExecuteInChroot(ctx, cmd.MountPoint, "pacman", "-Sy", "--noconfirm"); err != nil {
100 return fail("Failed to sync pacman repositories", err)108 return fail("Failed to sync pacman repositories", err)
@@ -107,6 +115,19 @@ func (h *ReposHandler) Handle(ctx context.Context, cmd commands.SetupRepositorie
107 }115 }
108 }116 }
109 117
118+ // Install extra packages from extra.packages file
119+ extraPkgs, err := h.loadExtraPackages()
120+ if err != nil {
121+ h.logger.Warn("Could not load extra.packages", "error", err)
122+ } else if len(extraPkgs) > 0 {
123+ h.logger.Info("Installing extra packages", "count", len(extraPkgs))
124+ args := append([]string{"-S", "--noconfirm", "--needed"}, extraPkgs...)
125+ if _, err := h.chrExec.ExecuteInChroot(ctx, cmd.MountPoint, "pacman", args...); err != nil {
126+ return fail("Failed to install extra packages", err)
127+ }
128+ h.logger.Info("Extra packages installed successfully")
129+ }
130+
110 result.Success = true131 result.Success = true
111 result.AURHelper = repo.AURHelper().String()132 result.AURHelper = repo.AURHelper().String()
112 133
@@ -114,6 +135,37 @@ func (h *ReposHandler) Handle(ctx context.Context, cmd commands.SetupRepositorie
114 return result, nil135 return result, nil
115 }136 }
116 137
138+// loadExtraPackages reads the extra package list from file
139+func (h *ReposHandler) loadExtraPackages() ([]string, error) {
140+ packageFile := filepath.Join(config.DefaultInstallDir, config.ExtraPackagesFile)
141+
142+ content, err := h.fs.ReadFile(packageFile)
143+ if err != nil {
144+ return nil, fmt.Errorf("failed to read %s: %w", packageFile, err)
145+ }
146+
147+ var pkgs []string
148+ scanner := bufio.NewScanner(strings.NewReader(string(content)))
149+
150+ for scanner.Scan() {
151+ line := strings.TrimSpace(scanner.Text())
152+
153+ // Skip comments and empty lines
154+ if line == "" || strings.HasPrefix(line, "#") {
155+ continue
156+ }
157+
158+ pkgs = append(pkgs, line)
159+ }
160+
161+ if err := scanner.Err(); err != nil {
162+ return nil, fmt.Errorf("error reading package file: %w", err)
163+ }
164+
165+ h.logger.Info("Loaded extra packages from file", "file", packageFile, "count", len(pkgs))
166+ return pkgs, nil
167+}
168+
117 func enableMultilibSection(conf string) string {169 func enableMultilibSection(conf string) string {
118 lines := strings.Split(conf, "\n")170 lines := strings.Split(conf, "\n")
119 inSection := false171 inSection := false

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 0

    ↑↓ moveenter openesc close