mise 2026.8.9

Dev tools, env vars, and tasks in one CLI
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
use eyre::Result;

use super::driver::{self, Action, DriverOpts};
use crate::config::{Config, Settings};
use crate::system;

#[derive(Debug, Default)]
pub(crate) struct BootstrapApplyReport {
    /// Whether top-level `mise bootstrap` should print a user follow-up item
    /// for this phase after a successful apply or dry-run.
    pub needs_follow_up: bool,
    pub skipped_reason: Option<String>,
}

/// Apply system packages from `[bootstrap.packages]`
///
/// Checks which configured packages are missing and installs them with the
/// system package manager. Built-in system managers may elevate with sudo when
/// not running as root (see `system_packages.sudo`); package plugins never do.
///
/// Packages can also be given explicitly in `manager:package` form (e.g.
/// `apk:zlib-dev`, `apt:curl`, `brew:jq`); they are installed whether or not they appear in
/// the config. Explicit packages and `--manager` scope the run to packages
/// only. `install` is accepted as an alias for this command.
#[derive(Debug, clap::Args)]
#[clap(visible_alias = "i", verbatim_doc_comment, after_long_help = AFTER_LONG_HELP)]
pub struct SystemInstall {
    /// Packages in `manager:package` form; defaults to everything configured
    /// in [bootstrap.packages]
    #[clap(value_name = "PACKAGE")]
    packages: Vec<String>,

    /// Only install packages for this built-in or plugin manager
    #[clap(long, short)]
    manager: Option<String>,

    /// Print the commands that would run without running them
    #[clap(long, short = 'n')]
    dry_run: bool,

    /// Skip the confirmation prompt
    #[clap(long, short)]
    yes: bool,

    /// Refresh package manager metadata first (apk: `--update-cache`, apt: `apt-get update`)
    #[clap(long)]
    update: bool,
}

impl SystemInstall {
    pub async fn run(self) -> Result<()> {
        let mgrs = if self.packages.is_empty() {
            let config = Config::get().await?;
            system::packages_from_config(&config)
        } else {
            let config = Config::get().await?;
            system::packages_from_specs_with_config(&self.packages, Some(&config))?
        };
        let opts = DriverOpts {
            manager: self.manager.clone(),
            explicit: !self.packages.is_empty(),
            allow_unavailable_manager: false,
            dry_run: self.dry_run,
            update: self.update,
            yes: self.yes,
        };
        driver::run(mgrs, Action::Install, &opts).await
    }
}

/// Apply `[bootstrap.macos.defaults]` entries that are unset or differ.
/// Inert off-macOS.
pub(crate) async fn apply_defaults(
    defaults: Vec<system::defaults::DefaultsRequest>,
    dry_run: bool,
    yes: bool,
) -> Result<()> {
    apply_defaults_with_report(defaults, dry_run, yes, true)
        .await
        .map(|_| ())
}

pub(crate) async fn apply_defaults_with_report(
    defaults: Vec<system::defaults::DefaultsRequest>,
    dry_run: bool,
    yes: bool,
    print_follow_up: bool,
) -> Result<BootstrapApplyReport> {
    use crate::system::defaults::{self, DefaultsState};
    if defaults.is_empty() {
        return Ok(BootstrapApplyReport::default());
    }
    if !defaults::is_available() {
        // cross-platform config: [bootstrap.macos.defaults] is simply inert off-macOS
        let reason = defaults::unavailable_reason();
        debug!("defaults: skipping, {reason}");
        return Ok(BootstrapApplyReport {
            needs_follow_up: false,
            skipped_reason: Some(reason),
        });
    }
    let statuses = defaults::status(&defaults).await?;
    let targets: Vec<_> = statuses
        .iter()
        .filter(|s| s.state != DefaultsState::Set)
        .map(|s| s.request.clone())
        .collect();
    let set = statuses.len() - targets.len();
    if set > 0 {
        info!("defaults: {set} value(s) already set");
    }
    if targets.is_empty() {
        return Ok(BootstrapApplyReport::default());
    }
    let list = targets.iter().map(|r| r.to_string()).collect::<Vec<_>>();
    if !dry_run && !yes && console::user_attended_stderr() {
        let msg = format!("defaults: write {}?", list.join(", "));
        if !crate::ui::prompt::confirm(msg)? {
            info!("defaults: skipped");
            return Ok(BootstrapApplyReport::default());
        }
    }
    defaults::apply(&targets, dry_run).await?;
    if !dry_run {
        if print_follow_up {
            info!(
                "defaults: wrote {} — some apps only pick up changes after a relaunch \
                 (e.g. `killall Dock`)",
                list.join(", ")
            );
        } else {
            info!("defaults: wrote {}", list.join(", "));
        }
    }
    Ok(BootstrapApplyReport {
        needs_follow_up: true,
        skipped_reason: None,
    })
}

/// Apply `[bootstrap.user].login_shell` when it differs for `mise bootstrap`.
/// Inert off-Unix or when `chsh` is missing.
pub(crate) fn apply_login_shell(
    request: Option<system::login_shell::LoginShellRequest>,
    dry_run: bool,
    yes: bool,
) -> Result<()> {
    apply_login_shell_with_report(request, dry_run, yes, true).map(|_| ())
}

pub(crate) fn apply_login_shell_with_report(
    request: Option<system::login_shell::LoginShellRequest>,
    dry_run: bool,
    yes: bool,
    print_follow_up: bool,
) -> Result<BootstrapApplyReport> {
    use crate::system::login_shell::{self, LoginShellState};
    let Some(request) = request else {
        return Ok(BootstrapApplyReport::default());
    };
    if !login_shell::is_available() {
        let reason = login_shell::unavailable_reason();
        debug!("login_shell: skipping, {reason}");
        return Ok(BootstrapApplyReport {
            needs_follow_up: false,
            skipped_reason: Some(reason),
        });
    }
    let status = login_shell::status(&request)?;
    if status.state == LoginShellState::Set {
        info!("login_shell: already set to {}", request.shell);
        return Ok(BootstrapApplyReport::default());
    }
    let needs_follow_up = status.state != LoginShellState::Set;
    if !dry_run && !yes && console::user_attended_stderr() {
        let msg = format!("login_shell: run `chsh -s {}`?", request.shell);
        if !crate::ui::prompt::confirm(msg)? {
            info!("login_shell: skipped");
            return Ok(BootstrapApplyReport::default());
        }
    }

    login_shell::apply(&request, dry_run)?;
    if !dry_run {
        if print_follow_up {
            info!(
                "login_shell: set to {} - start a new login session for it to take effect",
                request.shell
            );
        } else {
            info!("login_shell: set to {}", request.shell);
        }
    }
    Ok(BootstrapApplyReport {
        needs_follow_up,
        skipped_reason: None,
    })
}

/// Apply `[bootstrap.mise_shell_activate]` entries using dotfile edit blocks.
pub(crate) fn apply_shell_activation(
    config: &Config,
    requests: Vec<system::shell_activation::ShellActivationRequest>,
    dry_run: bool,
    yes: bool,
) -> Result<()> {
    if requests.is_empty() {
        return Ok(());
    }
    let edits = requests
        .into_iter()
        .map(|request| request.edit)
        .collect::<Vec<_>>();
    let opts = system::edits::ApplyOpts {
        dry_run,
        verbose: Settings::get().verbose,
        yes,
    };
    system::edits::apply(config, &edits, &opts).map(|_| ())
}

/// Apply `[bootstrap.repos]` entries that are missing or differ.
pub(crate) fn apply_repos(
    repos: Vec<system::repos::RepoRequest>,
    dry_run: bool,
    yes: bool,
) -> Result<()> {
    mutate_repos(
        repos,
        dry_run,
        yes,
        RepoMutation {
            prompt_verb: "apply",
            completed_verb: "applied",
            report_current_count: true,
            report_all_current: false,
        },
        |status| !status.state.is_current(),
        system::repos::apply_statuses,
    )
}

/// Update `[bootstrap.repos]` entries, including unpinned repos.
pub(crate) fn update_repos(
    repos: Vec<system::repos::RepoRequest>,
    dry_run: bool,
    yes: bool,
) -> Result<()> {
    mutate_repos(
        repos,
        dry_run,
        yes,
        RepoMutation {
            prompt_verb: "update",
            completed_verb: "updated",
            report_current_count: false,
            report_all_current: true,
        },
        |status| !status.state.is_current() || status.request.git_ref.is_none(),
        system::repos::update_statuses,
    )
}

struct RepoMutation {
    prompt_verb: &'static str,
    completed_verb: &'static str,
    report_current_count: bool,
    report_all_current: bool,
}

fn mutate_repos(
    repos: Vec<system::repos::RepoRequest>,
    dry_run: bool,
    yes: bool,
    mutation: RepoMutation,
    is_target: impl Fn(&system::repos::RepoStatus) -> bool,
    mutate: impl FnOnce(&[system::repos::RepoStatus], bool) -> Result<()>,
) -> Result<()> {
    use crate::system::repos;
    if repos.is_empty() {
        return Ok(());
    }
    let statuses = repos::status(&repos)?;
    repos::preflight_statuses(&statuses)?;
    let targets: Vec<_> = statuses.into_iter().filter(is_target).collect();
    let current = repos.len() - targets.len();
    if mutation.report_current_count && current > 0 {
        info!("repos: {current} repo(s) already current");
    }
    if targets.is_empty() {
        if mutation.report_all_current {
            info!("repos: all repo(s) already current");
        }
        return Ok(());
    }
    let list = targets
        .iter()
        .map(|s| s.request.to_string())
        .collect::<Vec<_>>();
    if !dry_run && !yes && console::user_attended_stderr() {
        let msg = format!("repos: {} {}?", mutation.prompt_verb, list.join(", "));
        if !crate::ui::prompt::confirm(msg)? {
            info!("repos: skipped");
            return Ok(());
        }
    }
    mutate(&targets, dry_run)?;
    if !dry_run {
        info!("repos: {} {}", mutation.completed_verb, list.join(", "));
    }
    Ok(())
}

/// Apply `[bootstrap.macos.launchd.agents]` entries that are missing, changed,
/// or not loaded. Inert off-macOS.
pub(crate) async fn apply_launchd(
    agents: Vec<system::launchd::LaunchdRequest>,
    dry_run: bool,
    yes: bool,
) -> Result<()> {
    apply_launchd_with_report(agents, dry_run, yes)
        .await
        .map(|_| ())
}

pub(crate) async fn apply_launchd_with_report(
    agents: Vec<system::launchd::LaunchdRequest>,
    dry_run: bool,
    yes: bool,
) -> Result<BootstrapApplyReport> {
    use crate::system::launchd::{self, LaunchdState};
    if agents.is_empty() {
        return Ok(BootstrapApplyReport::default());
    }
    if !launchd::is_available() {
        let reason = launchd::unavailable_reason();
        debug!("launchd: skipping, {reason}");
        return Ok(BootstrapApplyReport {
            needs_follow_up: false,
            skipped_reason: Some(reason),
        });
    }
    let statuses = launchd::status(&agents).await?;
    let targets: Vec<_> = statuses
        .iter()
        .filter(|s| s.state != LaunchdState::Loaded)
        .map(|s| s.request.clone())
        .collect();
    let loaded = statuses.len() - targets.len();
    if loaded > 0 {
        info!("launchd: {loaded} agent(s) already loaded");
    }
    if targets.is_empty() {
        return Ok(BootstrapApplyReport::default());
    }
    let list = targets.iter().map(|r| r.to_string()).collect::<Vec<_>>();
    if !dry_run && !yes && console::user_attended_stderr() {
        let msg = format!("launchd: install/load {}?", list.join(", "));
        if !crate::ui::prompt::confirm(msg)? {
            info!("launchd: skipped");
            return Ok(BootstrapApplyReport::default());
        }
    }
    launchd::apply(&targets, dry_run).await?;
    if !dry_run {
        info!("launchd: installed/loaded {}", list.join(", "));
    }
    Ok(BootstrapApplyReport {
        needs_follow_up: false,
        skipped_reason: None,
    })
}

/// Apply `[bootstrap.linux.systemd.units]` entries that are missing, changed,
/// or inactive. Inert off-Linux.
pub(crate) async fn apply_systemd(
    units: Vec<system::systemd::SystemdRequest>,
    dry_run: bool,
    yes: bool,
) -> Result<()> {
    apply_systemd_with_report(units, dry_run, yes)
        .await
        .map(|_| ())
}

pub(crate) async fn apply_systemd_with_report(
    units: Vec<system::systemd::SystemdRequest>,
    dry_run: bool,
    yes: bool,
) -> Result<BootstrapApplyReport> {
    use crate::system::systemd;
    if units.is_empty() {
        return Ok(BootstrapApplyReport::default());
    }
    if !systemd::is_available() {
        let reason = systemd::unavailable_reason();
        debug!("systemd: skipping, {reason}");
        return Ok(BootstrapApplyReport {
            needs_follow_up: false,
            skipped_reason: Some(reason),
        });
    }
    let statuses = systemd::status(&units).await?;
    let targets: Vec<_> = statuses
        .iter()
        .filter(|s| !s.is_desired())
        .map(|s| s.request.clone())
        .collect();
    let applied = statuses.len() - targets.len();
    if applied > 0 {
        info!("systemd: {applied} unit(s) already applied");
    }
    if targets.is_empty() {
        return Ok(BootstrapApplyReport::default());
    }
    let list = targets.iter().map(|r| r.to_string()).collect::<Vec<_>>();
    if !dry_run && !yes && console::user_attended_stderr() {
        let msg = format!("systemd: apply {}?", list.join(", "));
        if !crate::ui::prompt::confirm(msg)? {
            info!("systemd: skipped");
            return Ok(BootstrapApplyReport::default());
        }
    }
    systemd::apply(&targets, dry_run).await?;
    if !dry_run {
        info!("systemd: applied {}", list.join(", "));
    }
    Ok(BootstrapApplyReport {
        needs_follow_up: false,
        skipped_reason: None,
    })
}

static AFTER_LONG_HELP: &str = color_print::cstr!(
    r#"<bold><underline>Examples:</underline></bold>

    $ <bold>mise bootstrap packages apply</bold>
    $ <bold>mise bootstrap packages apply apk:zlib-dev apt:curl brew:jq brew-cask:firefox flatpak:org.mozilla.firefox flatpak-user:org.gnome.Builder mas:497799835</bold>
    $ <bold>mise bootstrap packages apply --dry-run</bold>
    $ <bold>mise bootstrap packages apply --manager apt --yes</bold>
"#
);