Repair /nix removal test (#320)

* Repair /nix removal test

* Iron out the logic better

* Repair nix flake check

* Remove extra sandbox=false flag

* Add ubuntu 16.04 test
This commit is contained in:
Ana Hobden 2023-03-10 15:28:04 -08:00 committed by GitHub
parent 32dca2e846
commit e0080d1262
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 145 additions and 53 deletions

View file

@ -11,14 +11,42 @@ let
check = '' check = ''
set -ex set -ex
dir /nix
dir /nix/store
ls -lah /nix/var/nix/profiles/per-user
ls -lah /nix/var/nix/daemon-socket
if systemctl is-active nix-daemon.socket; then if systemctl is-active nix-daemon.socket; then
echo "nix-daemon.socket was active" echo "nix-daemon.socket was active"
else else
echo "nix-daemon.socket was not active, should be" echo "nix-daemon.socket was not active, should be"
exit 1 exit 1
fi fi
if systemctl is-failed nix-daemon.socket; then
echo "nix-daemon.socket is failed"
exit 1
fi
if systemctl is-failed nix-daemon.service; then
echo "nix-daemon.service is failed"
exit 1
fi
if !(sudo systemctl start nix-daemon.service); then
echo "nix-daemon.service failed to start"
exit 1
fi
if !(sudo systemctl stop nix-daemon.service); then
echo "nix-daemon.service failed to stop"
exit 1
fi
sudo -i nix store ping --store daemon
nix store ping --store daemon
sudo -i nix-env --version
nix-env --version nix-env --version
sudo -i nix --extra-experimental-features nix-command store ping
nix --extra-experimental-features nix-command store ping nix --extra-experimental-features nix-command store ping
out=$(nix-build --no-substitute -E 'derivation { name = "foo"; system = "x86_64-linux"; builder = "/bin/sh"; args = ["-c" "echo foobar > $out"]; }') out=$(nix-build --no-substitute -E 'derivation { name = "foo"; system = "x86_64-linux"; builder = "/bin/sh"; args = ["-c" "echo foobar > $out"]; }')
@ -75,16 +103,16 @@ let
install = install-default.install; install = install-default.install;
check = install-default.check; check = install-default.check;
}; };
# install-preexisting-self-broken-no-nix-path = { install-preexisting-self-broken-no-nix-path = {
# preinstall = '' preinstall = ''
# NIX_PATH=$(readlink -f nix.tar.xz) NIX_PATH=$(readlink -f nix.tar.xz)
# RUST_BACKTRACE="full" ./nix-installer install --nix-package-url "file://$NIX_PATH" --no-confirm RUST_BACKTRACE="full" ./nix-installer install --nix-package-url "file://$NIX_PATH" --no-confirm
# sudo mv /nix/receipt.json /nix/old-receipt.json sudo mv /nix/receipt.json /nix/old-receipt.json
# sudo rm -rf /nix/ sudo rm -rf /nix/
# ''; '';
# install = install-default.install; install = install-default.install;
# check = install-default.check; check = install-default.check;
# }; };
install-preexisting-self-broken-missing-users = { install-preexisting-self-broken-missing-users = {
preinstall = '' preinstall = ''
NIX_PATH=$(readlink -f nix.tar.xz) NIX_PATH=$(readlink -f nix.tar.xz)
@ -367,10 +395,10 @@ vm-tests // rec {
name = "all"; name = "all";
constituents = pkgs.lib.mapAttrsToList (name: value: value."x86_64-linux".install-preexisting-self-working) vm-tests; constituents = pkgs.lib.mapAttrsToList (name: value: value."x86_64-linux".install-preexisting-self-working) vm-tests;
}); });
# all."x86_64-linux".install-preexisting-self-broken-no-nix-path = (with (forSystem "x86_64-linux" ({ system, pkgs, ... }: pkgs)); pkgs.releaseTools.aggregate { all."x86_64-linux".install-preexisting-self-broken-no-nix-path = (with (forSystem "x86_64-linux" ({ system, pkgs, ... }: pkgs)); pkgs.releaseTools.aggregate {
# name = "all"; name = "all";
# constituents = pkgs.lib.mapAttrsToList (name: value: value."x86_64-linux".install-preexisting-self-broken-no-nix-path) vm-tests; constituents = pkgs.lib.mapAttrsToList (name: value: value."x86_64-linux".install-preexisting-self-broken-no-nix-path) vm-tests;
# }); });
all."x86_64-linux".install-preexisting-self-broken-missing-users = (with (forSystem "x86_64-linux" ({ system, pkgs, ... }: pkgs)); pkgs.releaseTools.aggregate { all."x86_64-linux".install-preexisting-self-broken-missing-users = (with (forSystem "x86_64-linux" ({ system, pkgs, ... }: pkgs)); pkgs.releaseTools.aggregate {
name = "all"; name = "all";
constituents = pkgs.lib.mapAttrsToList (name: value: value."x86_64-linux".install-preexisting-self-broken-missing-users) vm-tests; constituents = pkgs.lib.mapAttrsToList (name: value: value."x86_64-linux".install-preexisting-self-broken-missing-users) vm-tests;
@ -398,7 +426,7 @@ vm-tests // rec {
all."x86_64-linux".install-no-start-daemon all."x86_64-linux".install-no-start-daemon
all."x86_64-linux".install-daemonless all."x86_64-linux".install-daemonless
all."x86_64-linux".install-preexisting-self-working all."x86_64-linux".install-preexisting-self-working
# all."x86_64-linux".install-preexisting-self-broken-no-nix-path all."x86_64-linux".install-preexisting-self-broken-no-nix-path
all."x86_64-linux".install-preexisting-self-broken-missing-users all."x86_64-linux".install-preexisting-self-broken-missing-users
all."x86_64-linux".install-preexisting-self-broken-missing-users-and-group all."x86_64-linux".install-preexisting-self-broken-missing-users-and-group
all."x86_64-linux".install-preexisting-self-broken-daemon-disabled all."x86_64-linux".install-preexisting-self-broken-daemon-disabled

View file

@ -184,6 +184,28 @@ impl Action for ConfigureInitService {
}, },
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
InitSystem::Systemd => { InitSystem::Systemd => {
execute_command(
Command::new("systemctl")
.process_group(0)
.arg("daemon-reload")
.stdin(std::process::Stdio::null()),
)
.await?;
// The goal state is the `socket` enabled and active, the service not enabled and stopped (it activates via socket activation)
let socket_was_active = if is_enabled("nix-daemon.socket").await? {
disable("nix-daemon.socket", true).await?;
true
} else if is_active("nix-daemon.socket").await? {
stop("nix-daemon.socket").await?;
false
} else {
false
};
if is_enabled("nix-daemon.service").await? {
let now = is_active("nix-daemon.socket").await?;
disable("nix-daemon.service", now).await?;
};
tracing::trace!(src = TMPFILES_SRC, dest = TMPFILES_DEST, "Symlinking"); tracing::trace!(src = TMPFILES_SRC, dest = TMPFILES_DEST, "Symlinking");
if !Path::new(TMPFILES_DEST).exists() { if !Path::new(TMPFILES_DEST).exists() {
tokio::fs::symlink(TMPFILES_SRC, TMPFILES_DEST) tokio::fs::symlink(TMPFILES_SRC, TMPFILES_DEST)
@ -210,7 +232,6 @@ impl Action for ConfigureInitService {
// cli, interactively ask for permission to remove the file // cli, interactively ask for permission to remove the file
Self::check_if_systemd_unit_exists(SERVICE_SRC, SERVICE_DEST).await?; Self::check_if_systemd_unit_exists(SERVICE_SRC, SERVICE_DEST).await?;
if !Path::new(SERVICE_DEST).exists() {
tokio::fs::symlink(SERVICE_SRC, SERVICE_DEST) tokio::fs::symlink(SERVICE_SRC, SERVICE_DEST)
.await .await
.map_err(|e| { .map_err(|e| {
@ -220,10 +241,8 @@ impl Action for ConfigureInitService {
e, e,
) )
})?; })?;
}
Self::check_if_systemd_unit_exists(SOCKET_SRC, SOCKET_DEST).await?; Self::check_if_systemd_unit_exists(SOCKET_SRC, SOCKET_DEST).await?;
if !Path::new(SOCKET_DEST).exists() {
tokio::fs::symlink(SOCKET_SRC, SOCKET_DEST) tokio::fs::symlink(SOCKET_SRC, SOCKET_DEST)
.await .await
.map_err(|e| { .map_err(|e| {
@ -233,9 +252,7 @@ impl Action for ConfigureInitService {
e, e,
) )
})?; })?;
}
if *start_daemon {
execute_command( execute_command(
Command::new("systemctl") Command::new("systemctl")
.process_group(0) .process_group(0)
@ -244,14 +261,10 @@ impl Action for ConfigureInitService {
) )
.await?; .await?;
execute_command( if *start_daemon || socket_was_active {
Command::new("systemctl") enable(SOCKET_SRC, true).await?;
.process_group(0) } else {
.arg("enable") enable(SOCKET_SRC, false).await?;
.arg("--now")
.arg(SOCKET_SRC),
)
.await?;
} }
}, },
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
@ -389,6 +402,57 @@ pub enum ConfigureNixDaemonServiceError {
InitNotSupported, InitNotSupported,
} }
#[cfg(target_os = "linux")]
async fn stop(unit: &str) -> Result<(), ActionError> {
let mut command = Command::new("systemctl");
command.arg("stop");
command.arg(unit);
let output = command
.output()
.await
.map_err(|e| ActionError::command(&command, e))?;
match output.status.success() {
true => Ok(()),
false => Err(ActionError::command_output(&command, output)),
}
}
#[cfg(target_os = "linux")]
async fn enable(unit: &str, now: bool) -> Result<(), ActionError> {
let mut command = Command::new("systemctl");
command.arg("enable");
command.arg(unit);
if now {
command.arg("--now");
}
let output = command
.output()
.await
.map_err(|e| ActionError::command(&command, e))?;
match output.status.success() {
true => Ok(()),
false => Err(ActionError::command_output(&command, output)),
}
}
#[cfg(target_os = "linux")]
async fn disable(unit: &str, now: bool) -> Result<(), ActionError> {
let mut command = Command::new("systemctl");
command.arg("disable");
command.arg(unit);
if now {
command.arg("--now");
}
let output = command
.output()
.await
.map_err(|e| ActionError::command(&command, e))?;
match output.status.success() {
true => Ok(()),
false => Err(ActionError::command_output(&command, output)),
}
}
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
async fn is_active(unit: &str) -> Result<bool, ActionError> { async fn is_active(unit: &str) -> Result<bool, ActionError> {
let mut command = Command::new("systemctl"); let mut command = Command::new("systemctl");