format + add missing profile cmd

This commit is contained in:
atagen 2025-06-25 16:37:35 +10:00
parent 1a2ca2dcbd
commit a1a0b134ad

View File

@ -10,7 +10,7 @@ let help =
FRESH - HUNT FRESH MEATS
..-A - ..ALL MEATS|}
(* \tLOOK - LOOK FOR FRESHER MEATS *)
(* \tLOOK - LOOK FOR FRESHER MEATS *)
open Sys
(* TODO rewrite all of this to use its own build and activation routines *)
@ -25,36 +25,57 @@ let pass_args () =
| _ -> ""
let do_cmd ?(args = true) cmd =
match command (if args then cmd ^ " " ^ pass_args () else cmd) with | 0 -> Ok(()) | e -> Error(e)
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 ( >>= ) = Result.bind in
let ( >|= ) = Fun.flip Result.map in
let tmpdir = Filename.temp_dir "meat-build" "" in
let build_target = Unix.getenv "MEATS" ^ "#nixosConfigurations." ^ Unix.gethostname () ^ ".config.system.build.toplevel" in
do_cmd @@ "nix build --out-link " ^ tmpdir ^ "/build " ^ build_target >>=
fun () -> do_cmd @@ "sudo " ^ tmpdir ^ "/build/bin/switch-to-configuration switch" >>=
fun () -> do_cmd @@ "sudo " ^ tmpdir ^ "/build/bin/switch-to-configuration boot" >|=
fun () -> Unix.unlink @@ tmpdir ^ "/build"
let build_target =
Unix.getenv "MEATS" ^ "#nixosConfigurations." ^ Unix.gethostname ()
^ ".config.system.build.toplevel"
in
do_cmd @@ "nix build --out-link " ^ tmpdir ^ "/build " ^ build_target
>>= fun () ->
do_cmd @@ "sudo " ^ tmpdir ^ "/build/bin/switch-to-configuration switch"
>>= fun () ->
do_cmd @@ "sudo " ^ tmpdir ^ "/build/bin/switch-to-configuration boot"
>>= fun () ->
let realpath = Unix.readlink @@ tmpdir ^ "/build" in
do_cmd @@ "sudo nix-env --profile /nix/var/nix/profiles/system --set "
^ realpath
>|= fun () -> Unix.unlink @@ tmpdir ^ "/build"
let yum () =
print_string header;
meat_print "CONSUMING DELICIOUS MEATS..";
do_build () |> function | Error _ -> print_string "FAILED TO CONSUME MEATS"; print_string footer | _ -> print_string footer
do_build () |> function
| Error _ ->
print_string "FAILED TO CONSUME MEATS";
print_string footer
| _ -> print_string footer
let cook () =
print_string header;
meat_print "PREPARING DELICIOUS MEATS..";
let build_target = Unix.getenv "MEATS" ^ "#nixosConfigurations." ^ Unix.gethostname () ^ ".config.system.build.toplevel" in
let build_target =
Unix.getenv "MEATS" ^ "#nixosConfigurations." ^ Unix.gethostname ()
^ ".config.system.build.toplevel"
in
do_cmd @@ "nix build --no-link" ^ build_target |> ignore;
print_string footer
let poke () =
print_string header;
meat_print "PREPARING SUSPICIOUS MEATS..";
let build_target = Unix.getenv "MEATS" ^ "#nixosConfigurations." ^ Unix.gethostname () ^ ".config.system.build.toplevel" in
let build_target =
Unix.getenv "MEATS" ^ "#nixosConfigurations." ^ Unix.gethostname ()
^ ".config.system.build.toplevel"
in
do_cmd @@ "nix build --no-link" ^ build_target ^ " --show-trace" |> ignore;
print_string footer
@ -66,14 +87,14 @@ let gut () =
(* TODO pending fuiska lib.. *)
(* let look () = *)
(* print_string header; *)
(* meat_print "INSPECTING MEAT.."; *)
(* meat_print "CONSUMING MEATS:"; *)
(* let meats = Unix.getenv "MEATS" in *)
(* do_cmd @@ "nix flake metadata" ^ meats |> ignore; *)
(* meat_print "PRODUCING MEATS:"; *)
(* do_cmd "nix flake show $MEATS"; *)
(* print_string footer; *)
(* print_string header; *)
(* meat_print "INSPECTING MEAT.."; *)
(* meat_print "CONSUMING MEATS:"; *)
(* let meats = Unix.getenv "MEATS" in *)
(* do_cmd @@ "nix flake metadata" ^ meats |> ignore; *)
(* meat_print "PRODUCING MEATS:"; *)
(* do_cmd "nix flake show $MEATS"; *)
(* print_string footer; *)
(* let all_flag () = Array.mem "-a" argv || Array.mem "--all" argv
let sub_flag () = Array.mem "-s" argv || Array.mem "--subflake" argv *)
@ -145,7 +166,9 @@ let fresh () =
|> iter (fun f ->
if all_low f = "meat" then meat_print "PROCESSING REAL MEAT.."
else meat_print ("PROCESSING FRESH MEAT " ^ all_caps f ^ "..");
do_cmd ~args:false @@ "nix flake update " ^ f ^ " --flake " ^ root |> ignore)
do_cmd ~args:false @@ "nix flake update " ^ f ^ " --flake "
^ root
|> ignore)
else do_cmd @@ "nix flake update --flake " ^ root |> ignore
| _, true ->
(* all flag, update all subflakes and main flake inputs *)
@ -168,8 +191,9 @@ let fresh () =
meat_print "PROCESSING FRESH MEATS..";
subflakes
|> iter (fun f ->
do_cmd ~args:false @@
"nix flake update " ^ all_low f ^ " --flake $MEATS" |> ignore)
do_cmd ~args:false @@ "nix flake update " ^ all_low f
^ " --flake $MEATS"
|> ignore)
| _ -> print_string help);
print_string footer;
print_newline ()