2024-10-23 16:49:22 +00:00
|
|
|
#!/usr/bin/env nu
|
|
|
|
|
2024-10-25 21:04:10 +00:00
|
|
|
use lib [eval-disko-file eval-flake exit-on-error print-info print-help]
|
|
|
|
|
|
|
|
def modes [] { ["destroy", "format", "mount", "format,mount", "destroy,format,mount"] }
|
2024-10-25 08:32:59 +00:00
|
|
|
|
2024-10-23 16:49:22 +00:00
|
|
|
|
|
|
|
def main [
|
|
|
|
mode: string@modes, # Mode to use. Allowed values are 'destroy', 'format', 'mount', 'format,mount', 'destroy,format,mount'
|
|
|
|
disko_file?: path, # File to read the disko configuration from. Can be a .nix file or a .json file
|
|
|
|
--flake (-f): string # Flake URI to search for the disko configuration
|
2024-10-25 08:32:59 +00:00
|
|
|
]: nothing -> nothing {
|
2024-10-25 21:04:10 +00:00
|
|
|
|
2024-10-25 08:32:59 +00:00
|
|
|
if not ($mode in (modes)) {
|
2024-10-25 21:04:10 +00:00
|
|
|
{
|
|
|
|
success: false,
|
|
|
|
messages: [ { code: ERR_INVALID_MODE, details: { mode: $mode, valid_modes: (modes) } } ]
|
|
|
|
} | exit-on-error "validate mode"
|
2024-10-25 08:32:59 +00:00
|
|
|
}
|
2024-10-23 16:49:22 +00:00
|
|
|
|
|
|
|
if not ($flake != null xor $disko_file != null) {
|
2024-10-25 21:04:10 +00:00
|
|
|
{ success: false, messages: [ { code: ERR_MISSING_ARGUMENTS } ] } | exit-on-error "validate arguments"
|
2024-10-23 16:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let config = if $disko_file != null {
|
2024-10-25 08:32:59 +00:00
|
|
|
$disko_file | eval-disko-file | exit-on-error "evaluate config"
|
2024-10-23 16:49:22 +00:00
|
|
|
} else {
|
2024-10-25 08:32:59 +00:00
|
|
|
$flake | eval-flake | exit-on-error "evaluate flake"
|
2024-10-23 16:49:22 +00:00
|
|
|
}
|
|
|
|
|
2024-10-25 21:04:10 +00:00
|
|
|
$config | to json | print-info
|
2024-10-23 16:49:22 +00:00
|
|
|
}
|