forked from lix-project/lix-installer
Default to systemd, refer to documentation if systemd is not available (#336)
This commit is contained in:
parent
8e27adcf98
commit
96d8870902
15
README.md
15
README.md
|
@ -147,6 +147,21 @@ jobs:
|
||||||
run: nix build .
|
run: nix build .
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Without systemd (Linux only)
|
||||||
|
|
||||||
|
> **Warning**
|
||||||
|
> When installed this way, _only_ `root` or users who can elevate to `root` privileges can run Nix:
|
||||||
|
>
|
||||||
|
> ```bash
|
||||||
|
> sudo -i nix run nixpkgs#hello
|
||||||
|
> ```
|
||||||
|
|
||||||
|
If you don't use [systemd], you can still install Nix by explicitly specifying the `linux` plan and `--init none`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install linux --init none
|
||||||
|
```
|
||||||
|
|
||||||
## In a container
|
## In a container
|
||||||
|
|
||||||
In Docker/Podman containers or WSL2 instances where an init (like `systemd`) is not present, pass `--init none`.
|
In Docker/Podman containers or WSL2 instances where an init (like `systemd`) is not present, pass `--init none`.
|
||||||
|
|
|
@ -75,6 +75,13 @@ impl ConfigureInitService {
|
||||||
},
|
},
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
InitSystem::Systemd => {
|
InitSystem::Systemd => {
|
||||||
|
// If /run/systemd/system exists, we can be reasonably sure the machine is booted
|
||||||
|
// with systemd: https://www.freedesktop.org/software/systemd/man/sd_booted.html
|
||||||
|
if !(Path::new("/run/systemd/system").exists() || which::which("systemctl").is_ok())
|
||||||
|
{
|
||||||
|
return Err(ActionError::SystemdMissing);
|
||||||
|
}
|
||||||
|
|
||||||
Self::check_if_systemd_unit_exists(SERVICE_SRC, SERVICE_DEST).await?;
|
Self::check_if_systemd_unit_exists(SERVICE_SRC, SERVICE_DEST).await?;
|
||||||
Self::check_if_systemd_unit_exists(SOCKET_SRC, SOCKET_DEST).await?;
|
Self::check_if_systemd_unit_exists(SOCKET_SRC, SOCKET_DEST).await?;
|
||||||
},
|
},
|
||||||
|
|
|
@ -462,6 +462,11 @@ pub enum ActionError {
|
||||||
MissingGroupDeletionCommand,
|
MissingGroupDeletionCommand,
|
||||||
#[error("Could not find a supported command to remove users from groups in PATH; please install `gpasswd` or `deluser`")]
|
#[error("Could not find a supported command to remove users from groups in PATH; please install `gpasswd` or `deluser`")]
|
||||||
MissingRemoveUserFromGroupCommand,
|
MissingRemoveUserFromGroupCommand,
|
||||||
|
#[error("\
|
||||||
|
Could not detect systemd; you may be able to get up and running without systemd with `nix-installer install linux --init none`.\n\
|
||||||
|
See https://github.com/DeterminateSystems/nix-installer#without-systemd-linux-only for documentation on usage and drawbacks.\
|
||||||
|
")]
|
||||||
|
SystemdMissing,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActionError {
|
impl ActionError {
|
||||||
|
|
|
@ -339,13 +339,11 @@ impl CommonSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
async fn linux_detect_init() -> (InitSystem, bool) {
|
async fn linux_detect_systemd_started() -> bool {
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
|
|
||||||
let mut detected = InitSystem::None;
|
|
||||||
let mut started = false;
|
let mut started = false;
|
||||||
if std::path::Path::new("/run/systemd/system").exists() {
|
if std::path::Path::new("/run/systemd/system").exists() {
|
||||||
detected = InitSystem::Systemd;
|
|
||||||
started = if tokio::process::Command::new("systemctl")
|
started = if tokio::process::Command::new("systemctl")
|
||||||
.arg("status")
|
.arg("status")
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
|
@ -364,7 +362,7 @@ async fn linux_detect_init() -> (InitSystem, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Other inits
|
// TODO: Other inits
|
||||||
(detected, started)
|
started
|
||||||
}
|
}
|
||||||
|
|
||||||
// Builder Pattern
|
// Builder Pattern
|
||||||
|
@ -464,33 +462,26 @@ pub struct InitSettings {
|
||||||
impl InitSettings {
|
impl InitSettings {
|
||||||
/// The default settings for the given Architecture & Operating System
|
/// The default settings for the given Architecture & Operating System
|
||||||
pub async fn default() -> Result<Self, InstallSettingsError> {
|
pub async fn default() -> Result<Self, InstallSettingsError> {
|
||||||
let init;
|
|
||||||
let start_daemon;
|
|
||||||
|
|
||||||
use target_lexicon::{Architecture, OperatingSystem};
|
use target_lexicon::{Architecture, OperatingSystem};
|
||||||
match (Architecture::host(), OperatingSystem::host()) {
|
let (init, start_daemon) = match (Architecture::host(), OperatingSystem::host()) {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
(Architecture::X86_64, OperatingSystem::Linux) => {
|
(Architecture::X86_64, OperatingSystem::Linux) => {
|
||||||
(init, start_daemon) = linux_detect_init().await;
|
(InitSystem::Systemd, linux_detect_systemd_started().await)
|
||||||
},
|
},
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
(Architecture::X86_32(_), OperatingSystem::Linux) => {
|
(Architecture::X86_32(_), OperatingSystem::Linux) => {
|
||||||
(init, start_daemon) = linux_detect_init().await;
|
(InitSystem::Systemd, linux_detect_systemd_started().await)
|
||||||
},
|
},
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
(Architecture::Aarch64(_), OperatingSystem::Linux) => {
|
(Architecture::Aarch64(_), OperatingSystem::Linux) => {
|
||||||
(init, start_daemon) = linux_detect_init().await;
|
(InitSystem::Systemd, linux_detect_systemd_started().await)
|
||||||
},
|
},
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
(Architecture::X86_64, OperatingSystem::MacOSX { .. })
|
(Architecture::X86_64, OperatingSystem::MacOSX { .. })
|
||||||
| (Architecture::X86_64, OperatingSystem::Darwin) => {
|
| (Architecture::X86_64, OperatingSystem::Darwin) => (InitSystem::Launchd, true),
|
||||||
(init, start_daemon) = (InitSystem::Launchd, true);
|
|
||||||
},
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
(Architecture::Aarch64(_), OperatingSystem::MacOSX { .. })
|
(Architecture::Aarch64(_), OperatingSystem::MacOSX { .. })
|
||||||
| (Architecture::Aarch64(_), OperatingSystem::Darwin) => {
|
| (Architecture::Aarch64(_), OperatingSystem::Darwin) => (InitSystem::Launchd, true),
|
||||||
(init, start_daemon) = (InitSystem::Launchd, true);
|
|
||||||
},
|
|
||||||
_ => {
|
_ => {
|
||||||
return Err(InstallSettingsError::UnsupportedArchitecture(
|
return Err(InstallSettingsError::UnsupportedArchitecture(
|
||||||
target_lexicon::HOST,
|
target_lexicon::HOST,
|
||||||
|
|
Loading…
Reference in a new issue