Skip to content

Commit b5cab2e

Browse files
committed
feat: NixOS support
1 parent 649dd02 commit b5cab2e

File tree

11 files changed

+290
-38
lines changed

11 files changed

+290
-38
lines changed

app/Actions/Server/CheckUpdates.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public function handle(Server $server)
5656
case 'fedora-asahi-remix':
5757
$osType = 'fedora';
5858
break;
59+
case 'nixos':
60+
$osType = 'nixos';
61+
break;
5962
default:
6063
$osType = $osId;
6164
}
@@ -67,6 +70,7 @@ public function handle(Server $server)
6770
'ubuntu', 'debian', 'raspbian' => 'apt',
6871
'centos', 'fedora', 'rhel', 'ol', 'rocky', 'almalinux', 'amzn' => 'dnf',
6972
'sles', 'opensuse-leap', 'opensuse-tumbleweed' => 'zypper',
73+
'nixos' => 'nixos',
7074
default => null
7175
};
7276

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

100+
return $out;
101+
case 'nixos':
102+
instant_remote_process(['nix-channel --update nixos'], $server);
103+
$output = instant_remote_process(['nixos-rebuild dry-build 2>&1'], $server);
104+
105+
$out = $this->parseNixosOutput($output);
106+
$out['osId'] = $osId;
107+
$out['package_manager'] = $packageManager;
108+
96109
return $out;
97110
default:
98111
return [
@@ -219,4 +232,59 @@ private function parseAptOutput(string $output): array
219232
'updates' => $updates,
220233
];
221234
}
235+
236+
private function parseNixosOutput(string $output): array
237+
{
238+
$updates = [];
239+
$lines = explode("\n", $output);
240+
241+
foreach ($lines as $line) {
242+
if (str_contains($line, 'these') && str_contains($line, 'paths will be fetched')) {
243+
if (preg_match('/these (\d+) paths will be fetched/', $line, $matches)) {
244+
$packageCount = (int) $matches[1];
245+
246+
$updates[] = [
247+
'package' => 'nixos-system',
248+
'new_version' => 'latest-channel',
249+
'current_version' => 'current-channel',
250+
'architecture' => 'system',
251+
'repository' => 'nixos-channel',
252+
'is_system_update' => true,
253+
'package_count' => $packageCount,
254+
'description' => 'NixOS system rebuild with '.$packageCount.' updated packages',
255+
];
256+
}
257+
break;
258+
}
259+
}
260+
261+
if (empty($updates)) {
262+
$hasChanges = false;
263+
foreach ($lines as $line) {
264+
if (str_contains($line, 'building') || str_contains($line, 'fetching') || str_contains($line, 'unpacking')) {
265+
$hasChanges = true;
266+
break;
267+
}
268+
}
269+
270+
if ($hasChanges) {
271+
$updates[] = [
272+
'package' => 'nixos-system',
273+
'new_version' => 'latest-channel',
274+
'current_version' => 'current-channel',
275+
'architecture' => 'system',
276+
'repository' => 'nixos-channel',
277+
'is_system_update' => true,
278+
'package_count' => 'unknown',
279+
'description' => 'NixOS system rebuild with updates available',
280+
];
281+
}
282+
}
283+
284+
return [
285+
'total_updates' => count($updates),
286+
'updates' => $updates,
287+
'is_nixos' => true,
288+
];
289+
}
222290
}

app/Actions/Server/InstallDocker.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ public function handle(Server $server)
9696
'command -v git >/dev/null || zypper install -y git',
9797
'command -v jq >/dev/null || zypper install -y jq',
9898
]);
99+
} elseif ($supported_os_type->contains('nixos')) {
100+
$command = $command->merge([
101+
"echo 'Checking NixOS Docker configuration...'",
102+
'command -v docker >/dev/null || echo "Docker not found. Please add Docker to your NixOS configuration."',
103+
'command -v git >/dev/null || echo "Git not found. Please add git to your NixOS configuration."',
104+
'command -v jq >/dev/null || echo "jq not found. Please add jq to your NixOS configuration."',
105+
]);
99106
} else {
100107
throw new \Exception('Unsupported OS');
101108
}
@@ -109,6 +116,8 @@ public function handle(Server $server)
109116
$command = $command->merge([$this->getRhelDockerInstallCommand()]);
110117
} elseif ($supported_os_type->contains('sles')) {
111118
$command = $command->merge([$this->getSuseDockerInstallCommand()]);
119+
} elseif ($supported_os_type->contains('nixos')) {
120+
$command = $command->merge([$this->getNixosDockerInstallCommand()]);
112121
} else {
113122
$command = $command->merge([$this->getGenericDockerInstallCommand()]);
114123
}
@@ -181,4 +190,30 @@ private function getGenericDockerInstallCommand(): string
181190
{
182191
return "curl https://releases.rancher.com/install-docker/{$this->dockerVersion}.sh | sh || curl https://get.docker.com | sh -s -- --version {$this->dockerVersion}";
183192
}
193+
194+
private function getNixosDockerInstallCommand(): string
195+
{
196+
return "echo 'NixOS Docker Configuration Guide:' && ".
197+
"echo '' && ".
198+
"echo 'To use Coolify with NixOS, you need to add Docker to your configuration.nix file:' && ".
199+
"echo '' && ".
200+
"echo 'virtualisation.docker = {' && ".
201+
"echo ' enable = true;' && ".
202+
"echo ' enableOnBoot = true;' && ".
203+
"echo ' autoPrune.enable = true;' && ".
204+
"echo '};' && ".
205+
"echo '' && ".
206+
"echo 'Also add these packages to your environment.systemPackages:' && ".
207+
"echo ' [' && ".
208+
"echo ' docker' && ".
209+
"echo ' docker-compose' && ".
210+
"echo ' git' && ".
211+
"echo ' jq' && ".
212+
"echo ' ]' && ".
213+
"echo '' && ".
214+
"echo 'After updating your configuration.nix, run:' && ".
215+
"echo ' sudo nixos-rebuild switch' && ".
216+
"echo '' && ".
217+
"echo 'Then click the \"Retry\" button in Coolify to continue validation.'";
218+
}
184219
}

app/Actions/Server/UpdatePackage.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public function handle(Server $server, string $osId, ?string $package = null, ?s
3333
$commandAll = 'apt update && apt upgrade -y';
3434
$commandInstall = 'apt install -y '.$package;
3535
break;
36+
case 'nixos':
37+
$commandAll = 'nix-channel --update nixos && nixos-rebuild switch';
38+
$commandInstall = 'nix-channel --update nixos && nixos-rebuild switch';
39+
break;
3640
default:
3741
return [
3842
'error' => 'OS not supported',

app/Livewire/Server/ValidateAndInstall.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ public function validateOS()
103103

104104
return;
105105
}
106+
107+
if ($this->supported_os_type->contains('nixos')) {
108+
$this->error = 'NixOS detected! Please ensure Docker is configured in your NixOS configuration before continuing. See the Docker installation step for detailed instructions.';
109+
$this->server->update([
110+
'validation_logs' => $this->error,
111+
]);
112+
}
113+
106114
$this->dispatch('validateDockerEngine');
107115
}
108116

@@ -113,7 +121,11 @@ public function validateDockerEngine()
113121
if (! $this->docker_installed || ! $this->docker_compose_installed) {
114122
if ($this->install) {
115123
if ($this->number_of_tries == $this->max_tries) {
116-
$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>.';
124+
if ($this->supported_os_type && $this->supported_os_type->contains('nixos')) {
125+
$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".';
126+
} else {
127+
$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>.';
128+
}
117129
$this->server->update([
118130
'validation_logs' => $this->error,
119131
]);
@@ -129,7 +141,11 @@ public function validateDockerEngine()
129141
return;
130142
}
131143
} else {
132-
$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>.';
144+
if ($this->supported_os_type && $this->supported_os_type->contains('nixos')) {
145+
$this->error = 'Docker is not installed on your NixOS system. Please configure Docker in your configuration.nix file and run `sudo nixos-rebuild switch`.';
146+
} else {
147+
$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>.';
148+
}
133149
$this->server->update([
134150
'validation_logs' => $this->error,
135151
]);

bootstrap/helpers/constants.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
'sles opensuse-leap opensuse-tumbleweed',
6464
'arch',
6565
'alpine',
66+
'nixos',
6667
];
6768

6869
const SHARED_VARIABLE_TYPES = ['team', 'project', 'environment'];

package-lock.json

Lines changed: 9 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)