Skip to content

Commit

Permalink
Prefer launchtl's bootstrap / bootout (#1033)
Browse files Browse the repository at this point in the history
* Update the docs to not refer to linux-multi

* Use bootstrap / bootout instead of load / unload

* Use constants for the launchd domain and service target

* Fixup clippy nits

* Fixup the bootstrap / bootout syntax
  • Loading branch information
grahamc authored Jul 8, 2024
1 parent 5307845 commit 6b183fc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@ $ chmod +x nix-installer
$ ./nix-installer
```

`nix-installer` installs Nix by following a *plan* made by a *planner*. Review the available planners:
`nix-installer` installs Nix by following a _plan_ made by a _planner_. Review the available planners:

```bash
$ ./nix-installer install --help
Execute an install (possibly using an existing plan)
foo@ubuntuserver2204:~$ ./nix-installer install --help
Install Nix using a planner

To pass custom options, select a planner, for example `nix-installer install linux-multi --help`
By default, an appropriate planner is heuristically determined based on the system.

Some planners have additional options which can be set from the planner's subcommand.
Usage: nix-installer install [OPTIONS] [PLAN]
nix-installer install <COMMAND>
Commands:
linux
A planner for Linux installs
steam-deck
A planner suitable for the Valve Steam Deck running SteamOS
help
Print this message or the help of the given subcommand(s)
linux A planner for traditional, mutable Linux systems like Debian, RHEL, or Arch
steam-deck A planner for the Valve Steam Deck running SteamOS
ostree A planner suitable for immutable systems using ostree, such as Fedora Silverblue
help Print this message or the help of the given subcommand(s)
# ...
```
Expand Down Expand Up @@ -90,9 +90,9 @@ Options:
Planners can be configured via environment variable or command arguments:
```bash
$ curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | NIX_BUILD_GROUP_NAME=nixbuilder sh -s -- install linux-multi --nix-build-group-id 4000
$ curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | NIX_BUILD_GROUP_NAME=nixbuilder sh -s -- install --nix-build-group-id 4000
# Or...
$ NIX_BUILD_GROUP_NAME=nixbuilder ./nix-installer install linux-multi --nix-build-group-id 4000
$ NIX_BUILD_GROUP_NAME=nixbuilder ./nix-installer install --nix-build-group-id 4000
```
### Upgrading Nix
Expand Down
20 changes: 12 additions & 8 deletions src/action/common/configure_enterprise_edition_init_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ use crate::action::{Action, ActionDescription};
#[cfg(target_os = "macos")]
const DARWIN_ENTERPRISE_EDITION_DAEMON_DEST: &str =
"/Library/LaunchDaemons/systems.determinate.nix-daemon.plist";
#[cfg(target_os = "macos")]
const DARWIN_LAUNCHD_DOMAIN: &str = "system";
#[cfg(target_os = "macos")]
const DARWIN_LAUNCHD_SERVICE: &str = "systems.determinate.nix-daemon";
/**
Configure the init to run the Nix daemon
*/
Expand Down Expand Up @@ -52,7 +56,7 @@ impl Action for ConfigureEnterpriseEditionInitService {
let mut explanation = vec![format!("Create `{DARWIN_ENTERPRISE_EDITION_DAEMON_DEST}`")];
if self.start_daemon {
explanation.push(format!(
"Run `launchctl load {DARWIN_ENTERPRISE_EDITION_DAEMON_DEST}`"
"Run `launchctl bootstrap {DARWIN_ENTERPRISE_EDITION_DAEMON_DEST}`"
));
}

Expand All @@ -64,8 +68,8 @@ impl Action for ConfigureEnterpriseEditionInitService {
let Self { start_daemon } = self;

let daemon_file = DARWIN_ENTERPRISE_EDITION_DAEMON_DEST;
let domain = "system";
let service = "systems.determinate.nix-daemon";
let domain = DARWIN_LAUNCHD_DOMAIN;
let service = DARWIN_LAUNCHD_SERVICE;

let generated_plist = generate_plist();

Expand All @@ -86,8 +90,8 @@ impl Action for ConfigureEnterpriseEditionInitService {
execute_command(
Command::new("launchctl")
.process_group(0)
.args(["load", "-w"])
.arg(daemon_file)
.arg("bootstrap")
.args([domain, daemon_file])
.stdin(std::process::Stdio::null()),
)
.await
Expand Down Expand Up @@ -128,7 +132,7 @@ impl Action for ConfigureEnterpriseEditionInitService {
vec![ActionDescription::new(
"Unconfigure Nix daemon related settings with launchctl".to_string(),
vec![format!(
"Run `launchctl unload {DARWIN_ENTERPRISE_EDITION_DAEMON_DEST}`"
"Run `launchctl bootout {DARWIN_ENTERPRISE_EDITION_DAEMON_DEST}`"
)],
)]
}
Expand All @@ -138,8 +142,8 @@ impl Action for ConfigureEnterpriseEditionInitService {
execute_command(
Command::new("launchctl")
.process_group(0)
.arg("unload")
.arg(DARWIN_ENTERPRISE_EDITION_DAEMON_DEST),
.arg("bootout")
.arg([DARWIN_LAUNCHD_DOMAIN, DARWIN_LAUNCHD_SERVICE].join("/")),
)
.await
.map_err(Self::error)?;
Expand Down
22 changes: 14 additions & 8 deletions src/action/common/configure_init_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const DARWIN_NIX_DAEMON_DEST: &str = "/Library/LaunchDaemons/org.nixos.nix-daemo
#[cfg(target_os = "macos")]
const DARWIN_NIX_DAEMON_SOURCE: &str =
"/nix/var/nix/profiles/default/Library/LaunchDaemons/org.nixos.nix-daemon.plist";
#[cfg(target_os = "macos")]
const DARWIN_LAUNCHD_DOMAIN: &str = "system";
#[cfg(target_os = "macos")]
const DARWIN_LAUNCHD_SERVICE: &str = "org.nixos.nix-daemon";
/**
Configure the init to run the Nix daemon
*/
Expand Down Expand Up @@ -158,7 +162,9 @@ impl Action for ConfigureInitService {
"Copy `{DARWIN_NIX_DAEMON_SOURCE}` to `{DARWIN_NIX_DAEMON_DEST}`"
)];
if self.start_daemon {
explanation.push(format!("Run `launchctl load {DARWIN_NIX_DAEMON_DEST}`"));
explanation.push(format!(
"Run `launchctl bootstrap {DARWIN_NIX_DAEMON_DEST}`"
));
}
vec.push(ActionDescription::new(self.tracing_synopsis(), explanation))
},
Expand All @@ -176,8 +182,8 @@ impl Action for ConfigureInitService {
#[cfg(target_os = "macos")]
InitSystem::Launchd => {
let daemon_file = DARWIN_NIX_DAEMON_DEST;
let domain = "system";
let service = "org.nixos.nix-daemon";
let domain = DARWIN_LAUNCHD_DOMAIN;
let service = DARWIN_LAUNCHD_SERVICE;
let src = std::path::Path::new(DARWIN_NIX_DAEMON_SOURCE);

tokio::fs::copy(src, daemon_file).await.map_err(|e| {
Expand All @@ -191,8 +197,8 @@ impl Action for ConfigureInitService {
execute_command(
Command::new("launchctl")
.process_group(0)
.args(["load", "-w"])
.arg(daemon_file)
.arg("bootstrap")
.args([domain, daemon_file])
.stdin(std::process::Stdio::null()),
)
.await
Expand Down Expand Up @@ -378,7 +384,7 @@ impl Action for ConfigureInitService {
InitSystem::Launchd => {
vec![ActionDescription::new(
"Unconfigure Nix daemon related settings with launchctl".to_string(),
vec![format!("Run `launchctl unload {DARWIN_NIX_DAEMON_DEST}`")],
vec![format!("Run `launchctl bootout {DARWIN_NIX_DAEMON_DEST}`")],
)]
},
#[cfg(not(target_os = "macos"))]
Expand All @@ -397,8 +403,8 @@ impl Action for ConfigureInitService {
execute_command(
Command::new("launchctl")
.process_group(0)
.arg("unload")
.arg(DARWIN_NIX_DAEMON_DEST),
.arg("bootout")
.arg([DARWIN_LAUNCHD_DOMAIN, DARWIN_LAUNCHD_SERVICE].join("/")),
)
.await
.map_err(Self::error)?;
Expand Down
6 changes: 3 additions & 3 deletions src/planner/macos/profile_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ pub fn blocks_internal_mounting(policies: &Policies) -> Vec<TargetProfileHardDis

let MountControls { harddisk_internal } = mount_controls;

return Some(TargetProfileHardDiskInternalOpts {
Some(TargetProfileHardDiskInternalOpts {
target: target_profile_item.target,
profile: target_profile_item.profile,
opts: &harddisk_internal,
});
opts: harddisk_internal,
})
})
.filter(|TargetProfileHardDiskInternalOpts { opts, .. }| {
opts.iter().any(|x| {
Expand Down

0 comments on commit 6b183fc

Please sign in to comment.