Unify apply script across platforms and remove build-switch
This commit is contained in:
@@ -1,15 +0,0 @@
|
|||||||
#!/usr/bin/env nu
|
|
||||||
|
|
||||||
use ../common.nu *
|
|
||||||
|
|
||||||
def main [hostname?: string, ...rest: string] {
|
|
||||||
let host = if ($hostname | is-empty) {
|
|
||||||
try { scutil --get LocalHostName | str trim } catch { hostname -s | str trim }
|
|
||||||
} else { $hostname }
|
|
||||||
|
|
||||||
print_info $"Applying configuration for ($host)"
|
|
||||||
|
|
||||||
nix run nix-darwin -- switch --flake $".#($host)" ...$rest
|
|
||||||
|
|
||||||
print_success "Configuration applied successfully"
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#!/usr/bin/env nu
|
|
||||||
|
|
||||||
use ../common.nu *
|
|
||||||
|
|
||||||
def main [hostname?: string, ...rest: string] {
|
|
||||||
let host = if ($hostname | is-empty) {
|
|
||||||
try { scutil --get LocalHostName | str trim } catch { hostname -s | str trim }
|
|
||||||
} else { $hostname }
|
|
||||||
|
|
||||||
print_info $"Building and switching configuration for ($host)"
|
|
||||||
|
|
||||||
# Build
|
|
||||||
print_info "Building configuration..."
|
|
||||||
if (nix build $".#darwinConfigurations.($host).system" --show-trace ...$rest | complete).exit_code != 0 {
|
|
||||||
print_error "Build failed"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
print_success "Build completed"
|
|
||||||
|
|
||||||
# Switch
|
|
||||||
print_info "Switching to new configuration..."
|
|
||||||
sudo ./result/sw/bin/darwin-rebuild switch --flake $".#($host)" ...$rest
|
|
||||||
|
|
||||||
if ("./result" | path exists) {
|
|
||||||
rm ./result
|
|
||||||
}
|
|
||||||
|
|
||||||
print_success "Build and switch completed successfully"
|
|
||||||
}
|
|
||||||
32
apps/apply
Executable file
32
apps/apply
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env nu
|
||||||
|
|
||||||
|
use ./common.nu *
|
||||||
|
|
||||||
|
def get-hostname [] {
|
||||||
|
if $nu.os-info.name == "macos" {
|
||||||
|
try { ^scutil --get LocalHostName | str trim } catch { ^hostname -s | str trim }
|
||||||
|
} else {
|
||||||
|
^hostname | str trim
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def main [hostname?: string, ...rest: string] {
|
||||||
|
let host = if ($hostname | is-empty) {
|
||||||
|
get-hostname
|
||||||
|
} else { $hostname }
|
||||||
|
|
||||||
|
print_info $"Applying configuration for ($host)"
|
||||||
|
|
||||||
|
if $nu.os-info.name == "macos" {
|
||||||
|
sudo nix run nix-darwin -- switch --flake $".#($host)" ...$rest
|
||||||
|
} else {
|
||||||
|
let euid = (id -u | str trim | into int)
|
||||||
|
if $euid != 0 {
|
||||||
|
sudo nixos-rebuild switch --flake $".#($host)" ...$rest
|
||||||
|
} else {
|
||||||
|
nixos-rebuild switch --flake $".#($host)" ...$rest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print_success "Configuration applied successfully"
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#!/usr/bin/env nu
|
|
||||||
|
|
||||||
use ../common.nu *
|
|
||||||
|
|
||||||
def main [hostname?: string, ...rest: string] {
|
|
||||||
let host = if ($hostname | is-empty) {
|
|
||||||
hostname | str trim
|
|
||||||
} else { $hostname }
|
|
||||||
|
|
||||||
print_info $"Applying configuration for ($host)"
|
|
||||||
|
|
||||||
let euid = (id -u | str trim | into int)
|
|
||||||
|
|
||||||
if $euid != 0 {
|
|
||||||
sudo nixos-rebuild switch --flake $".#($host)" ...$rest
|
|
||||||
} else {
|
|
||||||
nixos-rebuild switch --flake $".#($host)" ...$rest
|
|
||||||
}
|
|
||||||
|
|
||||||
print_success "Configuration applied successfully"
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#!/usr/bin/env nu
|
|
||||||
|
|
||||||
use ../common.nu *
|
|
||||||
|
|
||||||
def main [hostname?: string, ...rest: string] {
|
|
||||||
let host = if ($hostname | is-empty) {
|
|
||||||
hostname | str trim
|
|
||||||
} else { $hostname }
|
|
||||||
|
|
||||||
print_info $"Building and switching configuration for ($host)"
|
|
||||||
|
|
||||||
# Build
|
|
||||||
print_info "Building configuration..."
|
|
||||||
if (nix build $".#nixosConfigurations.($host).config.system.build.toplevel" --no-link ...$rest | complete).exit_code != 0 {
|
|
||||||
print_error "Build failed"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
print_success "Build completed"
|
|
||||||
|
|
||||||
# Switch
|
|
||||||
print_info "Switching to new configuration..."
|
|
||||||
let euid = (id -u | str trim | into int)
|
|
||||||
|
|
||||||
if $euid != 0 {
|
|
||||||
sudo nixos-rebuild switch --flake $".#($host)" ...$rest
|
|
||||||
} else {
|
|
||||||
nixos-rebuild switch --flake $".#($host)" ...$rest
|
|
||||||
}
|
|
||||||
|
|
||||||
print_success "Build and switch completed successfully"
|
|
||||||
}
|
|
||||||
@@ -7,23 +7,31 @@
|
|||||||
descriptions = {
|
descriptions = {
|
||||||
apply = "Build and apply configuration";
|
apply = "Build and apply configuration";
|
||||||
build = "Build configuration";
|
build = "Build configuration";
|
||||||
build-switch = "Build and switch configuration";
|
|
||||||
rollback = "Rollback to previous generation";
|
rollback = "Rollback to previous generation";
|
||||||
update = "Update flake inputs and regenerate flake.nix";
|
update = "Update flake inputs and regenerate flake.nix";
|
||||||
};
|
};
|
||||||
mkApp = name: {
|
mkPlatformApp = name: {
|
||||||
type = "app";
|
type = "app";
|
||||||
program = "${(pkgs.writeShellScriptBin name ''
|
program = "${(pkgs.writeShellScriptBin name ''
|
||||||
PATH=${pkgs.git}/bin:$PATH
|
PATH=${pkgs.git}/bin:$PATH
|
||||||
echo "Running ${name} for ${system}"
|
|
||||||
exec ${inputs.self}/apps/${system}/${name} "$@"
|
exec ${inputs.self}/apps/${system}/${name} "$@"
|
||||||
'')}/bin/${name}";
|
'')}/bin/${name}";
|
||||||
meta.description = descriptions.${name};
|
meta.description = descriptions.${name};
|
||||||
};
|
};
|
||||||
appNames = ["apply" "build" "build-switch" "rollback" "update"];
|
mkSharedApp = name: {
|
||||||
|
type = "app";
|
||||||
|
program = "${(pkgs.writeShellScriptBin name ''
|
||||||
|
PATH=${pkgs.git}/bin:$PATH
|
||||||
|
exec ${inputs.self}/apps/${name} "$@"
|
||||||
|
'')}/bin/${name}";
|
||||||
|
meta.description = descriptions.${name};
|
||||||
|
};
|
||||||
|
platformAppNames = ["build" "rollback" "update"];
|
||||||
|
sharedAppNames = ["apply"];
|
||||||
in {
|
in {
|
||||||
apps =
|
apps =
|
||||||
pkgs.lib.genAttrs appNames mkApp
|
pkgs.lib.genAttrs platformAppNames mkPlatformApp
|
||||||
|
// pkgs.lib.genAttrs sharedAppNames mkSharedApp
|
||||||
// {
|
// {
|
||||||
deploy = {
|
deploy = {
|
||||||
type = "app";
|
type = "app";
|
||||||
|
|||||||
Reference in New Issue
Block a user