remove reliance on nh for most things

This commit is contained in:
atagen 2025-06-20 12:54:21 +10:00
parent 56d0dc028f
commit 1a2ca2dcbd
7 changed files with 242 additions and 318 deletions

View file

@ -2,65 +2,78 @@ let header = "\n ----- MEAT ----------------------------------------\n"
let footer = "\n ---------------------------------------------------\n"
let help =
"\n\
\tYUM - CONSUME DELICIOUS MEATS\n\
\tCOOK - ONLY PREPARE MEATS\n\
\tPOKE - TASTE SUSPICIOUS MEATS\n\
\tGUT - CLEAN MEAT STORES\n\
\tLOOK - INSPECT MEAT\n\
\tFRESH - HUNT FRESH MEATS\n\
\t..N - ..MEATS OF N\n\
\t..-S N - ..SUBMEAT N\n\
\t..-A - ..ALL MEATS\n"
{|
YUM - CONSUME DELICIOUS MEATS
COOK - ONLY PREPARE MEATS
POKE - TASTE SUSPICIOUS MEATS
GUT - CLEAN MEAT STORES
FRESH - HUNT FRESH MEATS
..-A - ..ALL MEATS|}
(* \tLOOK - LOOK FOR FRESHER MEATS *)
open Sys
(* TODO rewrite all of this to use its own build and activation routines *)
(* pipe into nom for user output, then use dix at the end *)
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))
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 _ -> ()
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" ^ "#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 yum () =
print_string header;
meat_print "CONSUMING DELICIOUS MEATS..";
do_cmd "nh os switch";
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..";
do_cmd "nh os build";
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..";
do_cmd "nh os build -- --show-trace";
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
let gut () =
print_string header;
meat_print "CLEANING MEAT STORES..";
do_cmd "nh clean all";
do_cmd "nh clean all" |> ignore;
print_string footer
let look () =
print_string header;
meat_print "INSPECTING MEAT..";
meat_print "CONSUMING MEATS:";
do_cmd "nix flake metadata $NH_FLAKE";
meat_print "PRODUCING MEATS:";
do_cmd "nix flake show $NH_FLAKE";
print_string footer
(* 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; *)
(* let all_flag () = Array.mem "-a" argv || Array.mem "--all" argv
let sub_flag () = Array.mem "-s" argv || Array.mem "--subflake" argv *)
@ -114,13 +127,13 @@ let submeats s =
s
|> List.iter (fun d ->
meat_print ("PROCESSING SUBMEAT " ^ fmt_dir d ^ "..");
do_cmd ~args:false ("nix flake update --flake " ^ d))
do_cmd ~args:false @@ "nix flake update --flake " ^ d |> ignore)
let fresh () =
print_string header;
meat_print "HUNTING FRESH MEATS..";
let argv_len = Array.length argv in
let root = Sys.getenv "NH_FLAKE" in
let root = Sys.getenv "MEATS" in
let base_dir = root ^ "/flakes" in
(match (sub_flag (), all_flag ()) with
| false, false ->
@ -132,14 +145,14 @@ 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))
else do_cmd ("nix flake update --flake " ^ root)
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 *)
walk base_dir |> List.sort compdepth |> List.rev |> submeats;
print_string footer;
meat_print "PROCESSING FRESH MEATS..";
do_cmd ~args:false ("nix flake update --flake " ^ root)
do_cmd ~args:false @@ "nix flake update --flake " ^ root |> ignore
| true, _ when argv_len >= 4 ->
(* sub flag, update inputs as subflakes *)
let subflakes =
@ -155,8 +168,8 @@ let fresh () =
meat_print "PROCESSING FRESH MEATS..";
subflakes
|> iter (fun f ->
do_cmd ~args:false
("nix flake update " ^ all_low f ^ " --flake $NH_FLAKE"))
do_cmd ~args:false @@
"nix flake update " ^ all_low f ^ " --flake $MEATS" |> ignore)
| _ -> print_string help);
print_string footer;
print_newline ()