Compare commits
2 commits
27795f7998
...
15cc9ec58c
| Author | SHA1 | Date | |
|---|---|---|---|
| 15cc9ec58c | |||
| ab7408cdcf |
7 changed files with 354 additions and 31 deletions
|
|
@ -10,9 +10,12 @@ It is deliberately concrete: follow it rather than rediscovering the project.
|
||||||
|
|
||||||
Phoebus OS is a **modern, stable, Gentoo-based workstation operating system**:
|
Phoebus OS is a **modern, stable, Gentoo-based workstation operating system**:
|
||||||
systemd, Wayland-first, PipeWire, UEFI/GPT, LUKS2, Btrfs with snapshots, a fast
|
systemd, Wayland-first, PipeWire, UEFI/GPT, LUKS2, Btrfs with snapshots, a fast
|
||||||
dwl-style desktop, Flatpak, and an optional AI administration assistant. It is
|
dwl-style desktop, Flatpak, and a built-in AI administration assistant. The AI
|
||||||
**AI-first but never AI-dependent**: the system must be fully usable without an
|
assistant and Nix are **defining, always-present subsystems**: the assistant
|
||||||
LLM, and the LLM never holds privilege.
|
ships with a **local model** so it works offline and in recovery, and Nix is a
|
||||||
|
second package lane shipped and updated through Portage. Installation requires
|
||||||
|
the network; the installed system must boot, run and recover without it. The
|
||||||
|
LLM never holds privilege (see §2.4).
|
||||||
|
|
||||||
Fastest start: run `make context` (prints repository state, the roadmap's
|
Fastest start: run `make context` (prints repository state, the roadmap's
|
||||||
immediate next steps, the rolling handoff and open markers).
|
immediate next steps, the rolling handoff and open markers).
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,11 @@ Format: Keep a Changelog. Dates are UTC.
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
- `sys` offline package commands: `sys install <name>`, `sys remove <name>`,
|
||||||
|
`sys search <query>` (plus the `remove_package`/`search_packages` typed
|
||||||
|
actions). They are deterministic Portage operations with no model involved —
|
||||||
|
`emerge` resolves a bare name or a full atom — so the system stays fully
|
||||||
|
administrable offline and without the assistant.
|
||||||
- **Debian-Live installer appliance** (`installer/live/build.sh`, no root): a
|
- **Debian-Live installer appliance** (`installer/live/build.sh`, no root): a
|
||||||
bootable Phoebus installer ISO built by overlaying the static installer, the
|
bootable Phoebus installer ISO built by overlaying the static installer, the
|
||||||
OpenCode manifest and the Debian tools the live image lacks onto a Debian-Live
|
OpenCode manifest and the Debian tools the live image lacks onto a Debian-Live
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,15 @@ Modern architecture + mature implementations
|
||||||
- **Friendly to proprietary software** (drivers, firmware, codecs, Steam,
|
- **Friendly to proprietary software** (drivers, firmware, codecs, Steam,
|
||||||
browsers) where legally distributable. No moralising warnings; respect
|
browsers) where legally distributable. No moralising warnings; respect
|
||||||
licences.
|
licences.
|
||||||
- **AI-first, never AI-dependent.** The system is fully usable without an LLM.
|
- **AI-first, built in.** The assistant and Nix are defining, always-present
|
||||||
|
subsystems, not optional add-ons. The assistant ships with a **local model**
|
||||||
|
so it works offline; remote providers are an optional upgrade. A Phoebus
|
||||||
|
system must boot, run and recover without the network.
|
||||||
|
- **Nix as a second, built-in package lane.** Portage stays authoritative for
|
||||||
|
the system (kernel, drivers, systemd, Mesa, PipeWire, core libraries, boot,
|
||||||
|
services); Nix provides developer tools, alternate versions and reproducible
|
||||||
|
per-project environments. Nix is shipped and updated **through Portage**,
|
||||||
|
never as a `curl | sh` artifact.
|
||||||
|
|
||||||
## The AI contract
|
## The AI contract
|
||||||
|
|
||||||
|
|
@ -50,12 +58,34 @@ The model never receives the user's sudo password (authentication happens
|
||||||
through sudo/polkit/PAM outside model context), and it has no code path to
|
through sudo/polkit/PAM outside model context), and it has no code path to
|
||||||
read private files: system access is not home-directory access.
|
read private files: system access is not home-directory access.
|
||||||
|
|
||||||
|
The default brain is a **local model**, so the assistant works without a network
|
||||||
|
and inside recovery. Remote providers (DeepSeek/OpenAI) are optional and only
|
||||||
|
ever receive approved, bounded system facts. Installation requires the network
|
||||||
|
(stage3, Portage, packages); the installed system must not.
|
||||||
|
|
||||||
|
The assistant is the **preferred front-end, never a gate**. The deterministic
|
||||||
|
command line is always available with no model, and a user who wants the
|
||||||
|
old-fashioned way can always use it directly:
|
||||||
|
|
||||||
|
```
|
||||||
|
sys install vim # typed broker, offline parser, no LLM
|
||||||
|
sys enable sshd
|
||||||
|
sys history
|
||||||
|
emerge www-client/firefox # Portage (the Gentoo `apt install` equivalent)
|
||||||
|
nix shell nixpkgs#nodejs # Nix development environments
|
||||||
|
flatpak install flathub org.chromium.Chromium
|
||||||
|
```
|
||||||
|
|
||||||
|
Whatever the assistant can do, a human can do without it; the assistant only
|
||||||
|
makes it easier.
|
||||||
|
|
||||||
## Non-goals
|
## Non-goals
|
||||||
|
|
||||||
- A custom init system, package manager, audio stack or compositor.
|
- A custom init system, package manager, audio stack or compositor.
|
||||||
- A giant kernel fork or a large downstream patch set.
|
- A giant kernel fork or a large downstream patch set.
|
||||||
- Bleeding-edge/experimental defaults.
|
- Bleeding-edge/experimental defaults.
|
||||||
- Making the LLM required for installation or normal operation.
|
- Making a **remote** LLM/provider required to boot, run or recover. The local
|
||||||
|
assistant must work offline, and deterministic tools remain available.
|
||||||
- Rebuilding the world on a small release VPS.
|
- Rebuilding the world on a small release VPS.
|
||||||
|
|
||||||
## Definition of a successful distribution
|
## Definition of a successful distribution
|
||||||
|
|
|
||||||
136
docs/adr/0006-package-lanes.md
Normal file
136
docs/adr/0006-package-lanes.md
Normal file
|
|
@ -0,0 +1,136 @@
|
||||||
|
# ADR 0006: Package lanes — Portage, Flatpak, and Nix (built in)
|
||||||
|
|
||||||
|
- **Status:** Proposed
|
||||||
|
- **Date:** 2026-09-20
|
||||||
|
|
||||||
|
## Context
|
||||||
|
|
||||||
|
Phoebus is built on Gentoo/Portage and must stay a thin layer over it. There is
|
||||||
|
a real need for **binary options for non-core software** (developer tooling,
|
||||||
|
alternate versions, packages awkward or slow to compile) without (a)
|
||||||
|
maintaining a private Gentoo binhost, or (b) letting a second package manager
|
||||||
|
claim ownership of the system.
|
||||||
|
|
||||||
|
The decision here is that **Nix is part of the distro by default** — the same
|
||||||
|
way the AI assistant is: always present and ready, but never authoritative and
|
||||||
|
never required. A Phoebus system must remain completely usable with Portage
|
||||||
|
alone; a user who ignores Nix must not notice it.
|
||||||
|
|
||||||
|
Options considered: a second distro via Distrobox/pacman, Nix, Homebrew, native
|
||||||
|
`-bin` ebuilds, a third-party Gentoo binhost, and Flatpak.
|
||||||
|
|
||||||
|
Relevant facts established:
|
||||||
|
|
||||||
|
- The official Gentoo binhost is a single non-systemd (hardened) baseline, so
|
||||||
|
systemd/desktop packages mostly compile from source. We will not maintain a
|
||||||
|
private binhost.
|
||||||
|
- `nix` is not in the Gentoo main tree, so Phoebus ships and manages it itself.
|
||||||
|
- Nix is strong for reproducible, multi-version developer environments and poor
|
||||||
|
for GPU/Wayland desktop apps on a non-NixOS host (`nixGL`, Electron sandbox).
|
||||||
|
- Flatpak is already designed into Phoebus and is the right fit for sandboxed
|
||||||
|
GUI apps.
|
||||||
|
|
||||||
|
## Decision
|
||||||
|
|
||||||
|
Adopt **three package lanes**, all present on a default install, with strict
|
||||||
|
ownership:
|
||||||
|
|
||||||
|
| Lane | Owns | Availability |
|
||||||
|
| ---- | ---- | ------------ |
|
||||||
|
| **Portage** (authoritative) | kernel, drivers, systemd, Mesa, PipeWire, core libraries, boot stack, system services, compilers/toolchain | always |
|
||||||
|
| **Flatpak** | graphical desktop apps (Chromium, Firefox, Spotify, Electron), sandboxed | always |
|
||||||
|
| **Nix** | developer tools, alternate versions, reproducible per-project environments, packages inconvenient in Portage | always, user-level use |
|
||||||
|
|
||||||
|
Portage's native **`-bin` ebuilds** (`google-chrome`, `steam-launcher`,
|
||||||
|
`discord-bin`, ...) remain the vendor-blob lane; no new tool is introduced for
|
||||||
|
them.
|
||||||
|
|
||||||
|
Nix is **baked in**, but "baked in" describes availability, not authority:
|
||||||
|
|
||||||
|
- the Nix toolchain and daemon are shipped and configured by the installer;
|
||||||
|
- Portage still installs and updates Nix itself, so the daemon is system-managed
|
||||||
|
rather than a stray `curl | sh` artifact;
|
||||||
|
- no core component, service, library or application depends on Nix being used;
|
||||||
|
- ignoring Nix has no effect on the system.
|
||||||
|
|
||||||
|
## How Nix is baked in without surrendering ownership
|
||||||
|
|
||||||
|
1. **Ship it as a Portage package, not the upstream installer.** Provide a
|
||||||
|
Phoebus overlay ebuild for Nix (e.g. `sys-apps/nix`) that installs the
|
||||||
|
toolchain, creates the store and `nixbld` build users, and installs a
|
||||||
|
`nix-daemon.service` unit. The installer adds the overlay and emerges it as
|
||||||
|
part of the base/desktop package set.
|
||||||
|
2. **Multi-user, system-managed.** Because it is a real package, a root
|
||||||
|
`nix-daemon` is acceptable: it is enabled like any other service, updated
|
||||||
|
through `emerge`, and audited with the rest of the system.
|
||||||
|
3. **Pinned and verified.** The ebuild pins the Nix version and verifies the
|
||||||
|
upstream release tarball by SHA-256. The upstream `curl | sh` installer is
|
||||||
|
never used. nixpkgs itself is pinned per environment (flake lock / channel
|
||||||
|
revision), not "latest".
|
||||||
|
4. **No NixOS model.** No `configuration.nix`, no system profiles, no
|
||||||
|
Nix-managed services. Nix manages user environments only.
|
||||||
|
|
||||||
|
## Rules
|
||||||
|
|
||||||
|
1. **Portage is the only authority over the running system.** Nix and Flatpak
|
||||||
|
never provide kernel, drivers, Mesa, PipeWire, systemd, core libraries or
|
||||||
|
boot.
|
||||||
|
2. **Nix is user-level in effect.** It provides developer tools and project
|
||||||
|
environments, never system components.
|
||||||
|
3. **Never required.** The system is fully functional with Portage alone; the
|
||||||
|
base image and all services work if Nix is unused or removed.
|
||||||
|
4. **GUI apps go to Flatpak, not Nix.**
|
||||||
|
5. **No arbitrary remote evaluation by default.** Nix commands run by the
|
||||||
|
assistant are bounded (no arbitrary flakes or URLs), so eval-time fetching
|
||||||
|
is not an AI-reachable supply-chain surface.
|
||||||
|
|
||||||
|
## AI integration
|
||||||
|
|
||||||
|
The differentiated use is a typed, assistant-driven action:
|
||||||
|
|
||||||
|
```
|
||||||
|
CreateDevEnvironment { name, packages[], versions[] }
|
||||||
|
```
|
||||||
|
|
||||||
|
- executed unprivileged through `Exec` (no shell, no root for the user action);
|
||||||
|
- inputs validated against a bounded set;
|
||||||
|
- never mutates the base system;
|
||||||
|
- the deterministic broker reports which lane satisfied a request.
|
||||||
|
|
||||||
|
A future `sys` chooser must prefer deterministically: system/compiler/Mesa/
|
||||||
|
drivers → Portage only; GUI → Flatpak; per-project/dev → Nix.
|
||||||
|
|
||||||
|
## Explicit non-goals
|
||||||
|
|
||||||
|
- A universal `pkg install` meta-manager that silently picks a source (deferred;
|
||||||
|
provenance and support burden).
|
||||||
|
- NixOS-style system configuration.
|
||||||
|
- A second full distro (Distrobox, pacman) — rejected: a second rootfs to
|
||||||
|
maintain with weaker isolation than Flatpak.
|
||||||
|
- A third-party Gentoo binhost — rejected: trust, signature and availability.
|
||||||
|
- Homebrew — rejected: not packaged for Gentoo, FHS prefix shadowing, and it
|
||||||
|
adds nothing over Nix for the developer lane.
|
||||||
|
|
||||||
|
## Consequences and risks
|
||||||
|
|
||||||
|
- Every install now carries the Nix toolchain, a root daemon, and a growing
|
||||||
|
`/nix` store; image and disk usage increase.
|
||||||
|
- There are now two trust/update pipelines (`gentoo` + `nixpkgs`) on every
|
||||||
|
system, each with its own CVEs and update cadence. The daemon being
|
||||||
|
Portage-managed keeps ownership clear, but the risk is real and must be
|
||||||
|
documented to users.
|
||||||
|
- GUI/GPU stays Flatpak's job, consistent with this session's finding that Nix
|
||||||
|
is a poor fit there.
|
||||||
|
- The `nix-daemon` runs as root; it is a privileged component and must be
|
||||||
|
treated as one (service hardening, update tracking).
|
||||||
|
|
||||||
|
## Next steps
|
||||||
|
|
||||||
|
1. Finish Flatpak integration: `xdg-desktop-portal` (+ `-gtk`/`-wlr` backends),
|
||||||
|
a documented app-install path, desktop integration.
|
||||||
|
2. Author the Phoebus overlay `sys-apps/nix` ebuild (+ `nix-daemon.service`),
|
||||||
|
install it from the installer, and verify in the disposable VM that a Nix
|
||||||
|
dev environment works and the base system still boots without using it.
|
||||||
|
3. Add the `CreateDevEnvironment` typed action with a bounded input set and
|
||||||
|
tests.
|
||||||
|
4. Only then consider a thin `sys`-level source chooser (not a general `pkg`).
|
||||||
|
|
@ -28,6 +28,9 @@ sys enable sshd # deterministic phrase -> typed action
|
||||||
sys disable bluetooth
|
sys disable bluetooth
|
||||||
sys history # snapshot/transaction history
|
sys history # snapshot/transaction history
|
||||||
sys what are you compiling # background update status
|
sys what are you compiling # background update status
|
||||||
|
sys install vim # Portage (bare name or category/name)
|
||||||
|
sys search firefox
|
||||||
|
sys remove vim
|
||||||
sys --action '{"action":"inspect_service","name":"ssh"}'
|
sys --action '{"action":"inspect_service","name":"ssh"}'
|
||||||
sys --action-file proposal.json # the AI path: same typed schema
|
sys --action-file proposal.json # the AI path: same typed schema
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ pub enum SystemAction {
|
||||||
DisableService { name: String },
|
DisableService { name: String },
|
||||||
InspectPackage { atom: String },
|
InspectPackage { atom: String },
|
||||||
InstallPackage { atom: String },
|
InstallPackage { atom: String },
|
||||||
|
RemovePackage { atom: String },
|
||||||
|
SearchPackages { query: String },
|
||||||
CreateSnapshot { operation: String },
|
CreateSnapshot { operation: String },
|
||||||
History,
|
History,
|
||||||
UpdateSystem,
|
UpdateSystem,
|
||||||
|
|
@ -48,6 +50,10 @@ impl SystemAction {
|
||||||
}
|
}
|
||||||
SystemAction::InspectPackage { atom } => format!("inspect package {atom}"),
|
SystemAction::InspectPackage { atom } => format!("inspect package {atom}"),
|
||||||
SystemAction::InstallPackage { atom } => format!("install package {atom}"),
|
SystemAction::InstallPackage { atom } => format!("install package {atom}"),
|
||||||
|
SystemAction::RemovePackage { atom } => format!("remove package {atom}"),
|
||||||
|
SystemAction::SearchPackages { query } => {
|
||||||
|
format!("search packages for `{query}`")
|
||||||
|
}
|
||||||
SystemAction::CreateSnapshot { operation } => {
|
SystemAction::CreateSnapshot { operation } => {
|
||||||
format!("create a Btrfs snapshot before: {operation}")
|
format!("create a Btrfs snapshot before: {operation}")
|
||||||
}
|
}
|
||||||
|
|
@ -65,14 +71,18 @@ impl SystemAction {
|
||||||
/// snapshot and/or stronger confirmation is required.
|
/// snapshot and/or stronger confirmation is required.
|
||||||
pub fn risk(&self) -> Risk {
|
pub fn risk(&self) -> Risk {
|
||||||
match self {
|
match self {
|
||||||
SystemAction::InspectService { .. } | SystemAction::InspectPackage { .. } => Risk::Low,
|
SystemAction::InspectService { .. }
|
||||||
|
| SystemAction::InspectPackage { .. }
|
||||||
|
| SystemAction::SearchPackages { .. } => Risk::Low,
|
||||||
SystemAction::History => Risk::Low,
|
SystemAction::History => Risk::Low,
|
||||||
SystemAction::InspectUpdates => Risk::Low,
|
SystemAction::InspectUpdates => Risk::Low,
|
||||||
SystemAction::PrepareUpdates => Risk::Medium,
|
SystemAction::PrepareUpdates => Risk::Medium,
|
||||||
SystemAction::EnableService { .. }
|
SystemAction::EnableService { .. }
|
||||||
| SystemAction::DisableService { .. }
|
| SystemAction::DisableService { .. }
|
||||||
| SystemAction::CreateSnapshot { .. } => Risk::Medium,
|
| SystemAction::CreateSnapshot { .. } => Risk::Medium,
|
||||||
SystemAction::InstallPackage { .. } | SystemAction::UpdateSystem => Risk::High,
|
SystemAction::InstallPackage { .. }
|
||||||
|
| SystemAction::RemovePackage { .. }
|
||||||
|
| SystemAction::UpdateSystem => Risk::High,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,6 +93,7 @@ impl SystemAction {
|
||||||
self,
|
self,
|
||||||
SystemAction::InspectService { .. }
|
SystemAction::InspectService { .. }
|
||||||
| SystemAction::InspectPackage { .. }
|
| SystemAction::InspectPackage { .. }
|
||||||
|
| SystemAction::SearchPackages { .. }
|
||||||
| SystemAction::History
|
| SystemAction::History
|
||||||
| SystemAction::InspectUpdates
|
| SystemAction::InspectUpdates
|
||||||
)
|
)
|
||||||
|
|
@ -105,15 +116,20 @@ impl SystemAction {
|
||||||
Err(format!("invalid service name: {name}"))
|
Err(format!("invalid service name: {name}"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SystemAction::InspectPackage { atom } | SystemAction::InstallPackage { atom } => {
|
SystemAction::InspectPackage { atom }
|
||||||
let ok = atom.split('/').count() == 2
|
| SystemAction::InstallPackage { atom }
|
||||||
&& atom
|
| SystemAction::RemovePackage { atom } => {
|
||||||
.chars()
|
if valid_package_spec(atom) {
|
||||||
.all(|c| c.is_ascii_alphanumeric() || "/*._+-".contains(c));
|
|
||||||
if ok {
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(format!("invalid package atom: {atom}"))
|
Err(format!("invalid package name: {atom}"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SystemAction::SearchPackages { query } => {
|
||||||
|
if valid_search_query(query) {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(format!("invalid search query: {query}"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SystemAction::CreateSnapshot { operation } => {
|
SystemAction::CreateSnapshot { operation } => {
|
||||||
|
|
@ -131,6 +147,40 @@ impl SystemAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_atom_char(c: char) -> bool {
|
||||||
|
c.is_ascii_alphanumeric() || "+._@-".contains(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A package may be a bare name (`vim`) so `emerge vim` resolves it, or a full
|
||||||
|
/// atom (`app-editors/vim`). Both are accepted; anything else is refused.
|
||||||
|
pub fn valid_package_spec(spec: &str) -> bool {
|
||||||
|
if spec.is_empty() || spec.len() > 128 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let mut parts = spec.split('/');
|
||||||
|
let Some(first) = parts.next() else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
if first.is_empty() || !first.chars().all(is_atom_char) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
match parts.next() {
|
||||||
|
None => true,
|
||||||
|
Some(second) => {
|
||||||
|
!second.is_empty() && second.chars().all(is_atom_char) && parts.next().is_none()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A bounded search query (letters, digits and a few punctuation characters).
|
||||||
|
pub fn valid_search_query(query: &str) -> bool {
|
||||||
|
!query.is_empty()
|
||||||
|
&& query.len() <= 128
|
||||||
|
&& query
|
||||||
|
.chars()
|
||||||
|
.all(|c| c.is_ascii_alphanumeric() || " ._+@/-".contains(c))
|
||||||
|
}
|
||||||
|
|
||||||
/// A small deterministic parser for common `sys` phrases.
|
/// A small deterministic parser for common `sys` phrases.
|
||||||
///
|
///
|
||||||
/// Free-form requests that do not match are left to the AI path
|
/// Free-form requests that do not match are left to the AI path
|
||||||
|
|
@ -138,18 +188,9 @@ impl SystemAction {
|
||||||
pub fn parse_natural(text: &str) -> Option<SystemAction> {
|
pub fn parse_natural(text: &str) -> Option<SystemAction> {
|
||||||
let t = text.trim().to_lowercase();
|
let t = text.trim().to_lowercase();
|
||||||
let rest = |prefix: &str| t.strip_prefix(prefix).map(|r| r.trim().to_string());
|
let rest = |prefix: &str| t.strip_prefix(prefix).map(|r| r.trim().to_string());
|
||||||
if t == "history" || t.contains("history") {
|
|
||||||
return Some(SystemAction::History);
|
// Explicit commands first, so a search/install query cannot be mistaken for
|
||||||
}
|
// one of the heuristic phrases below.
|
||||||
if t == "update" || t == "update system" || t == "sys update" {
|
|
||||||
return Some(SystemAction::UpdateSystem);
|
|
||||||
}
|
|
||||||
if t.contains("prepare") && t.contains("update") {
|
|
||||||
return Some(SystemAction::PrepareUpdates);
|
|
||||||
}
|
|
||||||
if t.contains("what are you compiling") || t.contains("update status") {
|
|
||||||
return Some(SystemAction::InspectUpdates);
|
|
||||||
}
|
|
||||||
if let Some(name) = rest("enable ") {
|
if let Some(name) = rest("enable ") {
|
||||||
if !name.is_empty() {
|
if !name.is_empty() {
|
||||||
return Some(SystemAction::EnableService { name });
|
return Some(SystemAction::EnableService { name });
|
||||||
|
|
@ -160,16 +201,42 @@ pub fn parse_natural(text: &str) -> Option<SystemAction> {
|
||||||
return Some(SystemAction::DisableService { name });
|
return Some(SystemAction::DisableService { name });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(atom) = rest("install ") {
|
if let Some(atom) = rest("install ").or_else(|| rest("add ")) {
|
||||||
if atom.contains('/') {
|
if !atom.is_empty() {
|
||||||
return Some(SystemAction::InstallPackage { atom });
|
return Some(SystemAction::InstallPackage { atom });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(atom) = rest("remove ")
|
||||||
|
.or_else(|| rest("uninstall "))
|
||||||
|
.or_else(|| rest("delete "))
|
||||||
|
{
|
||||||
|
if !atom.is_empty() {
|
||||||
|
return Some(SystemAction::RemovePackage { atom });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(query) = rest("search ").or_else(|| rest("find ")) {
|
||||||
|
if !query.is_empty() {
|
||||||
|
return Some(SystemAction::SearchPackages { query });
|
||||||
|
}
|
||||||
|
}
|
||||||
if let Some(name) = rest("inspect ") {
|
if let Some(name) = rest("inspect ") {
|
||||||
if !name.is_empty() {
|
if !name.is_empty() {
|
||||||
return Some(SystemAction::InspectService { name });
|
return Some(SystemAction::InspectService { name });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if t == "history" || t.starts_with("history ") {
|
||||||
|
return Some(SystemAction::History);
|
||||||
|
}
|
||||||
|
if t == "update" || t == "update system" || t == "sys update" {
|
||||||
|
return Some(SystemAction::UpdateSystem);
|
||||||
|
}
|
||||||
|
if t.contains("prepare") && t.contains("update") {
|
||||||
|
return Some(SystemAction::PrepareUpdates);
|
||||||
|
}
|
||||||
|
if t.contains("what are you compiling") || t.contains("update status") {
|
||||||
|
return Some(SystemAction::InspectUpdates);
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,9 +271,26 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rejects_unknown_fields_and_bad_values() {
|
fn rejects_unknown_fields_and_bad_values() {
|
||||||
assert!(parse_action(r#"{"action":"install_package","atom":"steam","extra":1}"#).is_err());
|
assert!(parse_action(r#"{"action":"install_package","atom":"vim","extra":1}"#).is_err());
|
||||||
assert!(parse_action(r#"{"action":"install_package","atom":"notanatom"}"#).is_err());
|
assert!(parse_action(r#"{"action":"install_package","atom":"bad atom"}"#).is_err());
|
||||||
|
assert!(parse_action(r#"{"action":"install_package","atom":"a/b/c"}"#).is_err());
|
||||||
assert!(parse_action(r#"{"action":"enable_service","name":"bad name"}"#).is_err());
|
assert!(parse_action(r#"{"action":"enable_service","name":"bad name"}"#).is_err());
|
||||||
|
assert!(parse_action(r#"{"action":"search_packages","query":""}"#).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn accepts_bare_package_names() {
|
||||||
|
assert_eq!(
|
||||||
|
parse_action(r#"{"action":"install_package","atom":"vim"}"#).unwrap(),
|
||||||
|
SystemAction::InstallPackage { atom: "vim".into() }
|
||||||
|
);
|
||||||
|
let remove =
|
||||||
|
parse_action(r#"{"action":"remove_package","atom":"app-editors/vim"}"#).unwrap();
|
||||||
|
assert_eq!(remove.risk(), Risk::High);
|
||||||
|
assert!(remove.is_mutating());
|
||||||
|
let search = parse_action(r#"{"action":"search_packages","query":"firefox"}"#).unwrap();
|
||||||
|
assert!(!search.is_mutating());
|
||||||
|
assert_eq!(search.risk(), Risk::Low);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -224,6 +308,25 @@ mod tests {
|
||||||
atom: "app-editors/vim".into()
|
atom: "app-editors/vim".into()
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
// The friendly, apt-like forms resolve to Portage operations.
|
||||||
|
assert_eq!(
|
||||||
|
parse_natural("install vim"),
|
||||||
|
Some(SystemAction::InstallPackage { atom: "vim".into() })
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
parse_natural("remove vim"),
|
||||||
|
Some(SystemAction::RemovePackage { atom: "vim".into() })
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
parse_natural("uninstall vim"),
|
||||||
|
Some(SystemAction::RemovePackage { atom: "vim".into() })
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
parse_natural("search firefox"),
|
||||||
|
Some(SystemAction::SearchPackages {
|
||||||
|
query: "firefox".into()
|
||||||
|
})
|
||||||
|
);
|
||||||
assert_eq!(parse_natural("why is my audio broken"), None);
|
assert_eq!(parse_natural("why is my audio broken"), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,8 +93,24 @@ pub fn execute(
|
||||||
format!("{}\n{}", out.stdout_lossy(), out.stderr_lossy())
|
format!("{}\n{}", out.stdout_lossy(), out.stderr_lossy())
|
||||||
}
|
}
|
||||||
SystemAction::InstallPackage { atom } => {
|
SystemAction::InstallPackage { atom } => {
|
||||||
|
// Portage resolves a bare name (`vim`) or a full atom.
|
||||||
exec.run(CommandSpec::new("sys", "install package", "emerge").args(["--ask=n", atom]))?;
|
exec.run(CommandSpec::new("sys", "install package", "emerge").args(["--ask=n", atom]))?;
|
||||||
format!("installed {atom}")
|
format!("installed {atom} (Portage)")
|
||||||
|
}
|
||||||
|
SystemAction::RemovePackage { atom } => {
|
||||||
|
exec.run(CommandSpec::new("sys", "remove package", "emerge").args([
|
||||||
|
"--unmerge",
|
||||||
|
"--ask=n",
|
||||||
|
atom,
|
||||||
|
]))?;
|
||||||
|
format!("removed {atom} (Portage)")
|
||||||
|
}
|
||||||
|
SystemAction::SearchPackages { query } => {
|
||||||
|
let out = exec.runner.execute(
|
||||||
|
&CommandSpec::new("sys", "search packages", "emerge")
|
||||||
|
.args(["--search", "--quiet", query]),
|
||||||
|
)?;
|
||||||
|
format!("{}\n{}", out.stdout_lossy(), out.stderr_lossy())
|
||||||
}
|
}
|
||||||
SystemAction::UpdateSystem => {
|
SystemAction::UpdateSystem => {
|
||||||
exec.run(
|
exec.run(
|
||||||
|
|
@ -235,6 +251,33 @@ mod tests {
|
||||||
assert!(matches!(err, ExecError::Core(_)), "got {err}");
|
assert!(matches!(err, ExecError::Core(_)), "got {err}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn remove_package_builds_unmerge() {
|
||||||
|
let runner = RecordingRunner::new();
|
||||||
|
let exec = make_exec(runner.clone());
|
||||||
|
let auth = crate::auth::authorize(&crate::auth::AutoConfirm, "p", "f").unwrap();
|
||||||
|
let action = SystemAction::RemovePackage { atom: "vim".into() };
|
||||||
|
execute(&exec, &action, Some(&auth), Path::new(&exec.root)).unwrap();
|
||||||
|
let spec = &runner.recorded()[0];
|
||||||
|
assert_eq!(spec.program, "emerge");
|
||||||
|
assert!(spec.args.contains(&"--unmerge".to_string()));
|
||||||
|
assert!(spec.args.contains(&"vim".to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn search_packages_builds_emerge_search() {
|
||||||
|
let runner = RecordingRunner::new();
|
||||||
|
let exec = make_exec(runner.clone());
|
||||||
|
let action = SystemAction::SearchPackages {
|
||||||
|
query: "firefox".into(),
|
||||||
|
};
|
||||||
|
execute(&exec, &action, None, Path::new(&exec.root)).unwrap();
|
||||||
|
let spec = &runner.recorded()[0];
|
||||||
|
assert_eq!(spec.program, "emerge");
|
||||||
|
assert!(spec.args.contains(&"--search".to_string()));
|
||||||
|
assert!(spec.args.contains(&"firefox".to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn enable_builds_separate_arguments() {
|
fn enable_builds_separate_arguments() {
|
||||||
let runner = RecordingRunner::new();
|
let runner = RecordingRunner::new();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue