disko/disko2

33 lines
1.1 KiB
Text
Raw Normal View History

#!/usr/bin/env nu
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
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 08:32:59 +00:00
if not ($mode in (modes)) {
{
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
}
if not ($flake != null xor $disko_file != null) {
{ success: false, messages: [ { code: ERR_MISSING_ARGUMENTS } ] } | exit-on-error "validate arguments"
}
let config = if $disko_file != null {
2024-10-25 08:32:59 +00:00
$disko_file | eval-disko-file | exit-on-error "evaluate config"
} else {
2024-10-25 08:32:59 +00:00
$flake | eval-flake | exit-on-error "evaluate flake"
}
$config | to json | print-info
}