let header = "\n ----- MEAT ----------------------------------------\n" let footer = "\n ---------------------------------------------------\n" let help_text = {| YUM - CONSUME DELICIOUS MEATS COOK - ONLY PREPARE MEATS POKE - TASTE SUSPICIOUS MEATS GUT - CLEAN MEAT STORES FRESH - HUNT FRESH MEATS LOOK - LOOK FOR FRESHER MEATS HUNT - HUNT FOR MEATS IN NIXPKGS TRADE - SEND MEATS FAR AWAY ..-A - ..ALL MEATS|} open Sys let pass_args () = let len = Array.length argv and sconcat acc el = acc ^ " " ^ el in match len with | 3 -> argv.(2) | n when n > 3 -> print_int (n - 1); Array.fold_left sconcat " " (Array.sub argv 2 (n - 2)) | _ -> "" let do_cmd ?(args = true) cmd = match command (if args then cmd ^ " " ^ pass_args () else cmd) with | 0 -> Ok () | e -> Error e let meat_print text = print_endline ("\n \t" ^ text ^ "\n") let do_build () = let ( >>= ) = Result.bind in let ( >|= ) = Fun.flip Result.map in let tmpdir = Filename.temp_dir "meat-build" "" in let build_target = Unix.getenv "MEATS" ^ "/entry.nix -A nixosConfigurations." ^ Unix.gethostname () ^ ".config.system.build.toplevel" in do_cmd @@ "nix-build --log-format internal-json -v --out-link " ^ tmpdir ^ "/build " ^ build_target ^ " |& nom --json" >>= fun () -> do_cmd @@ "dix /nix/var/nix/profiles/system " ^ tmpdir ^ "/build" >>= fun () -> do_cmd @@ "sudo nix-env --set -p /nix/var/nix/profiles/system " ^ tmpdir ^ "/build && " ^ tmpdir ^ "/build/bin/switch-to-configuration switch" >|= fun () -> Unix.unlink @@ tmpdir ^ "/build" let do_remote () = meat_print "tbd"; Ok () let all_flag () = if Array.length argv >= 3 then match Array.get argv 2 with "-a" | "--all" -> true | _ -> false else false let all_caps s = s |> String.map (fun c -> Char.uppercase_ascii c) let all_low s = s |> String.map (fun c -> Char.lowercase_ascii c)