nex-pkg 0.22.0

Package manager UX for nix-darwin + homebrew
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
use std::path::PathBuf;

use clap::{Parser, Subcommand, ValueEnum};

#[derive(Parser)]
#[command(
    name = "nex",
    about = "Package manager for nix-darwin, NixOS, and homebrew"
)]
#[command(version)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Command,

    /// Path to the nix-darwin repo (overrides auto-discovery)
    #[arg(long, global = true, env = "NEX_REPO")]
    pub repo: Option<PathBuf>,

    /// Hostname for system rebuild (overrides auto-detect)
    #[arg(long, global = true, env = "NEX_HOSTNAME")]
    pub hostname: Option<String>,

    /// Show what would change without editing or switching
    #[arg(long, global = true)]
    pub dry_run: bool,
}

#[derive(Subcommand)]
pub enum Command {
    /// Set up nix-darwin + homebrew (macOS) or NixOS (Linux) on this machine
    Init {
        /// Clone an existing nix-darwin repo instead of scaffolding
        #[arg(long)]
        from: Option<String>,
    },
    /// Move a system-owned config (e.g. /etc/nixos) into a user-writable
    /// directory so nex no longer needs sudo to read or edit it.
    Relocate {
        /// Target path. Defaults to ~/nix-config.
        #[arg(long)]
        to: Option<PathBuf>,
    },
    /// Capture all installed brew packages into the nex config
    Adopt,
    /// Install packages
    Install {
        /// Force install as a Nix package (skip auto-resolution)
        #[arg(long, conflicts_with_all = ["cask", "brew"])]
        nix: bool,
        /// Install as a Homebrew cask (GUI app)
        #[arg(long, conflicts_with_all = ["nix", "brew"])]
        cask: bool,
        /// Install as a Homebrew formula
        #[arg(long, conflicts_with_all = ["nix", "cask"])]
        brew: bool,
        /// Resolve/write Armory package locks without fetching OCI payloads
        #[arg(long)]
        lock_only: bool,
        /// Package names
        packages: Vec<String>,
    },
    /// Remove packages
    Remove {
        /// Remove a Homebrew cask
        #[arg(long)]
        cask: bool,
        /// Remove a Homebrew formula
        #[arg(long)]
        brew: bool,
        /// Package names
        packages: Vec<String>,
    },
    /// Search nixpkgs and configured Armory registries for a package
    Search {
        /// Search query
        query: String,
    },
    /// Show Armory package metadata for <kind>/<id>
    Info {
        /// Armory package ref, e.g. profile/rust-shop
        package_ref: String,
    },
    /// List all declared packages
    List,
    /// Update flake inputs and switch
    Update,
    /// Rebuild and activate
    Switch,
    /// Rollback to previous generation
    Rollback,
    /// Try a package in an ephemeral nix shell
    Try {
        /// Package to try
        package: String,
    },
    /// Identify brew packages that can migrate to nix
    Migrate,
    /// Inspect and validate Nex artifact directories for Armory distribution
    Artifact {
        #[command(subcommand)]
        action: ArtifactAction,
    },
    /// Inspect and validate Nex machine profiles
    MachineProfile {
        #[command(subcommand)]
        action: MachineProfileAction,
    },
    /// Inspect and validate Nex profile fragments
    ProfileFragment {
        #[command(subcommand)]
        action: ProfileFragmentAction,
    },
    /// Manage and apply machine profiles
    #[command(
        after_help = "Note: `nex profile <source>` was renamed to `nex profile apply <source>` in v0.16.0"
    )]
    Profile {
        #[command(subcommand)]
        action: ProfileAction,
    },
    /// Build a bootable NixOS installer USB, optionally with a baked-in machine profile
    Forge {
        #[command(subcommand)]
        action: Option<ForgeAction>,

        /// Nex machine profile (GitHub user/repo) to bake in. Omit for generic styx installer.
        #[arg(value_name = "MACHINE_PROFILE")]
        profile: Option<String>,

        /// Hostname default for the target system (user can override at install time)
        #[arg(long)]
        hostname: Option<String>,

        /// Target USB device to flash (e.g. /dev/sdb, /dev/disk4). If omitted, builds bundle only.
        #[arg(long)]
        disk: Option<String>,

        /// Output directory for the bundle (default: /tmp/nex-forge)
        #[arg(long, short)]
        output: Option<PathBuf>,

        /// Target architecture (x86_64 or aarch64). Prompted interactively if omitted.
        #[arg(long)]
        arch: Option<String>,
    },
    /// Interactive NixOS installer (runs on target machine after booting from USB)
    Polymerize {
        /// Path to the bundled defaults (written by nex forge). Auto-detected from USB.
        #[arg(long)]
        bundle: Option<PathBuf>,
    },
    /// Build an OCI container image from a machine profile or Styrene package manifest
    BuildImage {
        /// Nex machine profile, local machine-profile.pkl, compatibility machine-profile.toml, or styrene package manifest
        #[arg(value_name = "SOURCE")]
        source: String,

        /// Image name (default: package image name or profile name)
        #[arg(long)]
        name: Option<String>,

        /// Image tag (default: package image tag or "latest")
        #[arg(long)]
        tag: Option<String>,
    },
    /// Enter a dev shell from a flake (wraps nix develop)
    Develop {
        /// Flake reference (e.g. github:styrene-lab/nex, ., ./path/to/flake)
        #[arg(value_name = "FLAKE")]
        flake: String,
    },
    /// Open a project with omegon AI coding agent (requires omegon)
    Dev {
        /// Project flake reference or bare name (e.g. styrene-lab/nex, omegon, .)
        #[arg(value_name = "PROJECT")]
        project: String,
    },
    /// Manage local Nex configuration
    Config {
        #[command(subcommand)]
        action: ConfigAction,
    },
    /// Manage Styrene identity (key generation, display)
    Identity {
        #[command(subcommand)]
        action: IdentityAction,
    },
    /// Manage RBAC roster (sync from hub)
    Rbac {
        #[command(subcommand)]
        action: RbacAction,
    },
    /// Check and fix common configuration issues
    Doctor {
        /// Apply supported bootstrap/root repairs
        #[arg(long)]
        fix: bool,

        /// Limit fixes to one doctor scope
        #[arg(value_enum)]
        scope: Option<DoctorScope>,
    },
    /// Refresh Armory package locks
    Lock {
        #[command(subcommand)]
        action: LockAction,
    },
    /// Update nex itself to the latest release
    SelfUpdate,
    /// Preview what would change
    Diff,
    /// Garbage collect nix store
    Gc,
}

#[derive(Subcommand)]
pub enum LockAction {
    /// Re-resolve roots from the package lock
    Refresh,
    /// Materialize locked Armory packages into the local store
    Materialize,
    /// Show Armory package lock status
    Status,
}

#[derive(Clone, Copy, Debug, ValueEnum)]
pub enum DoctorScope {
    All,
    DarwinBootstrap,
    HomebrewBootstrap,
}

#[derive(Subcommand)]
pub enum ConfigAction {
    /// Export effective local config from canonical Pkl to compatibility formats
    Export {
        /// Output format
        #[arg(long, value_name = "FORMAT", default_value = "toml")]
        format: String,

        /// Write to a file instead of stdout
        #[arg(long)]
        output: Option<PathBuf>,
    },
    /// Create canonical config.pkl from existing compatibility config.toml
    Migrate {
        /// Keep or regenerate compatibility config.toml after migration
        #[arg(long)]
        keep_toml: bool,
    },
}

#[derive(Subcommand)]
pub enum ForgeAction {
    /// Plan a forge request/template without creating artifacts or flashing disks
    Plan {
        /// Canonical Pkl request/template path. JSON is accepted as transport fallback.
        #[arg(long)]
        request: PathBuf,
    },
    /// Execute a forge request after planning and safety checks
    Run {
        /// Canonical Pkl request path. JSON is accepted as transport fallback.
        #[arg(long)]
        request: PathBuf,

        /// Emit phase/blocker/artifact events as JSON lines
        #[arg(long, value_name = "FORMAT", default_value = "human")]
        events: String,
    },
    /// Check host readiness for a forge request without building or flashing
    Preflight {
        /// Canonical Pkl request path. JSON is accepted as transport fallback.
        #[arg(long)]
        request: PathBuf,

        /// Emit a stable JSON report
        #[arg(long)]
        json: bool,
    },
    /// Validate and inspect a forge template without building or flashing anything
    Check {
        /// Canonical forge.pkl template path
        #[arg(value_name = "PATH")]
        path: PathBuf,

        /// Optional Armory forge.toml metadata path to compare against the template
        #[arg(long)]
        metadata: Option<PathBuf>,

        /// Emit a stable JSON report
        #[arg(long)]
        json: bool,

        /// Explicitly require non-executing validation mode
        #[arg(long)]
        no_execute: bool,
    },
    /// Evaluate a generated NixOS materialization workspace without building or flashing
    CheckMaterialization {
        /// Directory containing a generated flake.nix workspace. If omitted, --source is required.
        #[arg(value_name = "WORKSPACE")]
        workspace: Option<PathBuf>,

        /// Canonical Pkl machine/materialization source to scaffold into a temporary workspace; TOML is compatibility/interchange.
        #[arg(long)]
        source: Option<String>,

        /// Hostname under nixosConfigurations.<hostname>
        #[arg(long)]
        hostname: String,

        /// Materialization target to evaluate deterministically
        #[arg(long, default_value = "toplevel")]
        target: String,
    },
    /// Export a composable nixosModule from a materialization source
    BuildModule {
        /// Canonical Pkl materialization source; TOML is compatibility/interchange
        #[arg(value_name = "SOURCE")]
        source: PathBuf,

        /// nixosModules.<name> output name
        #[arg(long)]
        name: String,

        /// Output directory for generated flake/module
        #[arg(long, short)]
        output: PathBuf,
    },
    /// Build a deterministic materialization output after validation
    BuildMaterialization {
        /// Canonical Pkl materialization source; TOML is compatibility/interchange
        #[arg(value_name = "SOURCE")]
        source: PathBuf,

        /// Hostname under nixosConfigurations.<hostname>
        #[arg(long)]
        hostname: String,

        /// Materialization target to build
        #[arg(long, default_value = "sd-image")]
        target: String,

        /// Output link path for nix build
        #[arg(long, short)]
        output: PathBuf,
    },
}

#[derive(Subcommand)]
pub enum IdentityAction {
    /// Generate a new Styrene identity
    Init {
        /// Path to the identity file (default: ~/.config/styrene/identity.key)
        #[arg(long)]
        path: Option<PathBuf>,
    },
    /// Display identity hash and derived public keys
    Show {
        /// Path to the identity file (default: ~/.config/styrene/identity.key)
        #[arg(long)]
        path: Option<PathBuf>,
    },
    /// Scan for all identities on this machine
    List,
    /// Export or manage SSH public keys derived from identity
    Ssh {
        /// Label for the SSH key (e.g. "github", "work")
        label: Option<String>,
        /// List all registered SSH key labels
        #[arg(long, conflicts_with = "label")]
        list: bool,
        /// Register a new SSH key label
        #[arg(long, conflicts_with_all = ["label", "list"])]
        add: Option<String>,
    },
    /// Configure git commit signing with identity
    Git {
        /// Show current git signing configuration
        #[arg(long)]
        show: bool,
    },
    /// Export WireGuard key pair derived from identity
    Wg,
    /// Export age encryption identity/recipient derived from identity
    Age,
    /// Link this identity to a Signum hub for SSO
    Link {
        /// Signum instance URL (e.g. https://signum.styrene.io)
        url: String,
        /// Enrollment invite code (if required by the hub)
        #[arg(long)]
        code: Option<String>,
        /// Path to the identity file (default: ~/.config/styrene/identity.key)
        #[arg(long)]
        path: Option<PathBuf>,
    },
}

#[derive(Subcommand)]
pub enum ArtifactAction {
    /// Validate a Nex artifact directory containing machine-profile.pkl or payload.pkl
    Check {
        /// Path to artifact directory
        #[arg(value_name = "PATH")]
        path: PathBuf,

        /// Evidence tier to validate
        #[arg(long, default_value = "evaluates")]
        evidence: String,

        /// Emit a stable JSON report
        #[arg(long)]
        json: bool,
    },
    /// Validate compatibility between a machine-profile artifact and materialization-payload artifact
    CheckRelationship {
        /// Machine-profile artifact directory
        #[arg(long)]
        profile: PathBuf,

        /// Materialization-payload artifact directory
        #[arg(long)]
        payload: PathBuf,

        /// Emit a stable JSON report
        #[arg(long)]
        json: bool,
    },
}

#[derive(Subcommand)]
pub enum MachineProfileAction {
    /// Validate a machine-profile.pkl manifest
    Validate {
        /// Path to machine-profile.pkl or a directory containing it; TOML is compatibility/interchange
        #[arg(value_name = "PATH")]
        path: PathBuf,
    },
    /// Inspect a machine-profile.pkl manifest
    Inspect {
        /// Path to machine-profile.pkl or a directory containing it; TOML is compatibility/interchange
        #[arg(value_name = "PATH")]
        path: PathBuf,

        /// Emit stable JSON metadata after validation
        #[arg(long)]
        json: bool,
    },
}

#[derive(Subcommand)]
pub enum ProfileFragmentAction {
    /// Validate a profile fragment TOML file or directory of fragments
    Validate {
        /// Path to a fragment TOML file or a directory containing fragments
        #[arg(value_name = "PATH")]
        path: PathBuf,
    },
    /// Inspect a profile fragment TOML file
    Inspect {
        /// Path to a fragment TOML file
        #[arg(value_name = "PATH")]
        path: PathBuf,

        /// Emit stable JSON metadata after validation
        #[arg(long)]
        json: bool,
    },
}

#[derive(Subcommand)]
pub enum ProfileAction {
    /// Apply a machine profile to this machine
    Apply {
        /// GitHub repo (user/repo), URL, or local path
        #[arg(value_name = "SOURCE")]
        source: String,
        /// Verify the machine profile signature before applying (local .signed.toml files only)
        #[arg(long)]
        verify: bool,
    },
    /// Sign a machine profile with your Styrene identity
    Sign {
        /// GitHub repo (user/repo) or local path to machine-profile.pkl; TOML is compatibility/interchange
        #[arg(value_name = "SOURCE")]
        source: String,
        /// Write signature to a detached .sig file instead of embedding in [meta]
        #[arg(long)]
        detached: bool,
    },
    /// Verify a signed machine profile
    Verify {
        /// GitHub repo (user/repo) or local path to machine-profile.pkl; TOML is compatibility/interchange
        #[arg(value_name = "SOURCE")]
        source: String,
    },
}

#[derive(Subcommand)]
pub enum RbacAction {
    /// Sync RBAC roster entries from a Signum hub
    Sync {
        /// Hub URL (e.g. https://signum.styrene.io)
        #[arg(value_name = "HUB_URL")]
        hub_url: String,
        /// Fetch only a specific identity's entry
        #[arg(long)]
        identity: Option<String>,
        /// Admin token for full roster access (single-identity fetch is public)
        #[arg(long, env = "SIGNUM_ADMIN_TOKEN")]
        token: Option<String>,
        /// Output path for the TOML config (default: ~/.config/styrene/config.toml)
        #[arg(long, short)]
        output: Option<PathBuf>,
    },
}