Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions app/Actions/Server/CheckUpdates.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public function handle(Server $server)
case 'fedora-asahi-remix':
$osType = 'fedora';
break;
case 'nixos':
$osType = 'nixos';
break;
default:
$osType = $osId;
}
Expand All @@ -67,6 +70,7 @@ public function handle(Server $server)
'ubuntu', 'debian', 'raspbian' => 'apt',
'centos', 'fedora', 'rhel', 'ol', 'rocky', 'almalinux', 'amzn' => 'dnf',
'sles', 'opensuse-leap', 'opensuse-tumbleweed' => 'zypper',
'nixos' => 'nixos',
default => null
};

Expand All @@ -93,6 +97,15 @@ public function handle(Server $server)
$out['osId'] = $osId;
$out['package_manager'] = $packageManager;

return $out;
case 'nixos':
instant_remote_process(['nix-channel --update nixos'], $server);
$output = instant_remote_process(['nixos-rebuild dry-build 2>&1'], $server);

$out = $this->parseNixosOutput($output);
$out['osId'] = $osId;
$out['package_manager'] = $packageManager;

return $out;
default:
return [
Expand Down Expand Up @@ -219,4 +232,59 @@ private function parseAptOutput(string $output): array
'updates' => $updates,
];
}

private function parseNixosOutput(string $output): array
{
$updates = [];
$lines = explode("\n", $output);

foreach ($lines as $line) {
if (str_contains($line, 'these') && str_contains($line, 'paths will be fetched')) {
if (preg_match('/these (\d+) paths will be fetched/', $line, $matches)) {
$packageCount = (int) $matches[1];

$updates[] = [
'package' => 'nixos-system',
'new_version' => 'latest-channel',
'current_version' => 'current-channel',
'architecture' => 'system',
'repository' => 'nixos-channel',
'is_system_update' => true,
'package_count' => $packageCount,
'description' => 'NixOS system rebuild with '.$packageCount.' updated packages',
];
}
break;
}
}

if (empty($updates)) {
$hasChanges = false;
foreach ($lines as $line) {
if (str_contains($line, 'building') || str_contains($line, 'fetching') || str_contains($line, 'unpacking')) {
$hasChanges = true;
break;
}
}

if ($hasChanges) {
$updates[] = [
'package' => 'nixos-system',
'new_version' => 'latest-channel',
'current_version' => 'current-channel',
'architecture' => 'system',
'repository' => 'nixos-channel',
'is_system_update' => true,
'package_count' => 'unknown',
'description' => 'NixOS system rebuild with updates available',
];
}
}

return [
'total_updates' => count($updates),
'updates' => $updates,
'is_nixos' => true,
];
}
}
35 changes: 35 additions & 0 deletions app/Actions/Server/InstallDocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public function handle(Server $server)
'command -v git >/dev/null || zypper install -y git',
'command -v jq >/dev/null || zypper install -y jq',
]);
} elseif ($supported_os_type->contains('nixos')) {
$command = $command->merge([
"echo 'Checking NixOS Docker configuration...'",
'command -v docker >/dev/null || echo "Docker not found. Please add Docker to your NixOS configuration."',
'command -v git >/dev/null || echo "Git not found. Please add git to your NixOS configuration."',
'command -v jq >/dev/null || echo "jq not found. Please add jq to your NixOS configuration."',
]);
} else {
throw new \Exception('Unsupported OS');
}
Expand All @@ -109,6 +116,8 @@ public function handle(Server $server)
$command = $command->merge([$this->getRhelDockerInstallCommand()]);
} elseif ($supported_os_type->contains('sles')) {
$command = $command->merge([$this->getSuseDockerInstallCommand()]);
} elseif ($supported_os_type->contains('nixos')) {
$command = $command->merge([$this->getNixosDockerInstallCommand()]);
} else {
$command = $command->merge([$this->getGenericDockerInstallCommand()]);
}
Expand Down Expand Up @@ -181,4 +190,30 @@ private function getGenericDockerInstallCommand(): string
{
return "curl https://releases.rancher.com/install-docker/{$this->dockerVersion}.sh | sh || curl https://get.docker.com | sh -s -- --version {$this->dockerVersion}";
}

private function getNixosDockerInstallCommand(): string
{
return "echo 'NixOS Docker Configuration Guide:' && ".
"echo '' && ".
"echo 'To use Coolify with NixOS, you need to add Docker to your configuration.nix file:' && ".
"echo '' && ".
"echo 'virtualisation.docker = {' && ".
"echo ' enable = true;' && ".
"echo ' enableOnBoot = true;' && ".
"echo ' autoPrune.enable = true;' && ".
"echo '};' && ".
"echo '' && ".
"echo 'Also add these packages to your environment.systemPackages:' && ".
"echo ' [' && ".
"echo ' docker' && ".
"echo ' docker-compose' && ".
"echo ' git' && ".
"echo ' jq' && ".
"echo ' ]' && ".
"echo '' && ".
"echo 'After updating your configuration.nix, run:' && ".
"echo ' sudo nixos-rebuild switch' && ".
"echo '' && ".
"echo 'Then click the \"Retry\" button in Coolify to continue validation.'";
}
}
4 changes: 4 additions & 0 deletions app/Actions/Server/UpdatePackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public function handle(Server $server, string $osId, ?string $package = null, ?s
$commandAll = 'apt update && apt upgrade -y';
$commandInstall = 'apt install -y '.$package;
break;
case 'nixos':
$commandAll = 'nix-channel --update nixos && nixos-rebuild switch';
$commandInstall = 'nix-channel --update nixos && nixos-rebuild switch';
break;
default:
return [
'error' => 'OS not supported',
Expand Down
20 changes: 18 additions & 2 deletions app/Livewire/Server/ValidateAndInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ public function validateOS()

return;
}

if ($this->supported_os_type->contains('nixos')) {
$this->error = 'NixOS detected! Please ensure Docker is configured in your NixOS configuration before continuing. See the Docker installation step for detailed instructions.';
$this->server->update([
'validation_logs' => $this->error,
]);
}

$this->dispatch('validateDockerEngine');
}

Expand All @@ -113,7 +121,11 @@ public function validateDockerEngine()
if (! $this->docker_installed || ! $this->docker_compose_installed) {
if ($this->install) {
if ($this->number_of_tries == $this->max_tries) {
$this->error = 'Docker Engine could not be installed. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
if ($this->supported_os_type && $this->supported_os_type->contains('nixos')) {
$this->error = 'Docker is not installed on your NixOS system. Please follow the NixOS Docker configuration guide shown in the installation logs, then run `sudo nixos-rebuild switch` and click "Retry".';
} else {
$this->error = 'Docker Engine could not be installed. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
}
$this->server->update([
'validation_logs' => $this->error,
]);
Expand All @@ -129,7 +141,11 @@ public function validateDockerEngine()
return;
}
} else {
$this->error = 'Docker Engine is not installed. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
if ($this->supported_os_type && $this->supported_os_type->contains('nixos')) {
$this->error = 'Docker is not installed on your NixOS system. Please configure Docker in your configuration.nix file and run `sudo nixos-rebuild switch`.';
} else {
$this->error = 'Docker Engine is not installed. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
}
$this->server->update([
'validation_logs' => $this->error,
]);
Expand Down
1 change: 1 addition & 0 deletions bootstrap/helpers/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
'sles opensuse-leap opensuse-tumbleweed',
'arch',
'alpine',
'nixos',
];

const SHARED_VARIABLE_TYPES = ['team', 'project', 'environment'];
22 changes: 9 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading