This commit is contained in:
parent
0fc93545ce
commit
703ac28f52
16 changed files with 548 additions and 215 deletions
9
lib/commands/cook.ml
Normal file
9
lib/commands/cook.ml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
let run () =
|
||||
print_string Common.header;
|
||||
Common.meat_print "PREPARING DELICIOUS MEATS..";
|
||||
let build_target =
|
||||
Unix.getenv "MEATS" ^ "#nixosConfigurations." ^ Unix.gethostname ()
|
||||
^ ".config.system.build.toplevel"
|
||||
in
|
||||
Common.do_cmd @@ "nix build --no-link" ^ build_target |> ignore;
|
||||
print_string Common.footer
|
||||
17
lib/commands/fresh.ml
Normal file
17
lib/commands/fresh.ml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
let run () =
|
||||
print_string Common.header;
|
||||
Common.meat_print "HUNTING FRESH MEATS..";
|
||||
let argv_len = Array.length Sys.argv in
|
||||
let root = Sys.getenv "MEATS" in
|
||||
if argv_len >= 3 then
|
||||
let open Array in
|
||||
let flakes = sub Sys.argv 2 (argv_len - 2) in
|
||||
flakes
|
||||
|> iter (fun f ->
|
||||
if Common.all_low f = "meat" then Common.meat_print "PROCESSING REAL MEAT.."
|
||||
else Common.meat_print ("PROCESSING FRESH MEAT " ^ Common.all_caps f ^ "..");
|
||||
Common.do_cmd ~args:false @@ "nix flake update " ^ f ^ " --flake " ^ root
|
||||
|> ignore)
|
||||
else Common.do_cmd @@ "nix flake update --flake " ^ root |> ignore;
|
||||
print_string Common.footer;
|
||||
print_newline ()
|
||||
5
lib/commands/gut.ml
Normal file
5
lib/commands/gut.ml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
let run () =
|
||||
print_string Common.header;
|
||||
Common.meat_print "CLEANING MEAT STORES..";
|
||||
Common.do_cmd "nh clean all" |> ignore;
|
||||
print_string Common.footer
|
||||
1
lib/commands/help.ml
Normal file
1
lib/commands/help.ml
Normal file
|
|
@ -0,0 +1 @@
|
|||
let run () = print_string (Common.header ^ Common.help_text ^ Common.footer ^ "\n")
|
||||
61
lib/commands/hunt.ml
Normal file
61
lib/commands/hunt.ml
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
let es_host = "nixos-search-7-1733963800.us-east-1.bonsaisearch.net"
|
||||
|
||||
let es_query term =
|
||||
Printf.sprintf
|
||||
{|{"from":0,"size":20,"sort":[{"_score":"desc","package_attr_name":"desc","package_pversion":"desc"}],"collapse":{"field":"package_attr_name"},"query":{"bool":{"must":[{"term":{"type":"package"}},{"multi_match":{"type":"cross_fields","query":"%s","fields":["package_attr_name^9","package_pname^6","package_description^1.3","package_longDescription^1"]}}]}}}|}
|
||||
term
|
||||
|
||||
let truncate n s = if String.length s > n then String.sub s 0 n ^ ".." else s
|
||||
|
||||
let run () =
|
||||
print_string Common.header;
|
||||
let argv_len = Array.length Sys.argv in
|
||||
if argv_len < 3 then (
|
||||
Common.meat_print "WHAT MEAT ARE YOU HUNTING?";
|
||||
print_string Common.footer)
|
||||
else
|
||||
let query =
|
||||
Array.sub Sys.argv 2 (argv_len - 2)
|
||||
|> Array.to_list |> String.concat " "
|
||||
in
|
||||
Common.meat_print ("HUNTING FOR " ^ Common.all_caps query ^ "..");
|
||||
let body = es_query query in
|
||||
let path = "/nixos-*-unstable-*/_search" in
|
||||
(try
|
||||
let resp = Http.https_post ~host:es_host ~path ~body in
|
||||
let json = Json.parse_json resp in
|
||||
let hits =
|
||||
match Option.bind (Json.jfield "hits" json) (fun h -> Json.jfield "hits" h) with
|
||||
| Some (`List items) -> items
|
||||
| _ -> []
|
||||
in
|
||||
if hits = [] then
|
||||
Common.meat_print "NO MEATS FOUND!"
|
||||
else
|
||||
List.iter
|
||||
(fun hit ->
|
||||
let src =
|
||||
match Json.jfield "_source" hit with Some s -> s | None -> `Null
|
||||
in
|
||||
let name =
|
||||
match Option.bind (Json.jfield "package_attr_name" src) Json.jstring with
|
||||
| Some s -> s
|
||||
| None -> "?"
|
||||
in
|
||||
let version =
|
||||
match Option.bind (Json.jfield "package_pversion" src) Json.jstring with
|
||||
| Some s -> s
|
||||
| None -> ""
|
||||
in
|
||||
let desc =
|
||||
match Option.bind (Json.jfield "package_description" src) Json.jstring with
|
||||
| Some s -> truncate 60 s
|
||||
| None -> ""
|
||||
in
|
||||
let ver_str = if version <> "" then " (" ^ version ^ ")" else "" in
|
||||
Printf.printf " \tnixpkgs#%s%s\n" name ver_str;
|
||||
if desc <> "" then Printf.printf " \t %s\n" desc)
|
||||
hits
|
||||
with e ->
|
||||
Common.meat_print ("HUNT FAILED: " ^ Printexc.to_string e));
|
||||
print_string Common.footer
|
||||
114
lib/commands/look.ml
Normal file
114
lib/commands/look.ml
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
let run () =
|
||||
print_string Common.header;
|
||||
Common.meat_print "LOOKING FOR FRESHER MEATS..";
|
||||
let lockfile = Http.read_file (Unix.getenv "MEATS" ^ "/flake.lock") in
|
||||
let json = Json.parse_json lockfile in
|
||||
let nodes =
|
||||
match Json.jfield "nodes" json with Some n -> n | None -> failwith "no nodes"
|
||||
in
|
||||
let root_node =
|
||||
match Json.jfield "root" nodes with Some n -> n | None -> failwith "no root"
|
||||
in
|
||||
let root_inputs =
|
||||
match Json.jfield "inputs" root_node with
|
||||
| Some n -> n
|
||||
| None -> failwith "no root inputs"
|
||||
in
|
||||
let input_pairs =
|
||||
match Json.jassoc root_inputs with
|
||||
| Some p -> p
|
||||
| None -> failwith "root inputs not object"
|
||||
in
|
||||
let any_stale = ref false in
|
||||
List.iter
|
||||
(fun (name, node_ref) ->
|
||||
let node_name =
|
||||
match Json.jstring node_ref with Some s -> s | None -> name
|
||||
in
|
||||
let node =
|
||||
match Json.jfield node_name nodes with
|
||||
| Some n -> n
|
||||
| None -> failwith ("no node: " ^ node_name)
|
||||
in
|
||||
let locked =
|
||||
match Json.jfield "locked" node with
|
||||
| Some n -> n
|
||||
| None -> failwith "no locked"
|
||||
in
|
||||
let original =
|
||||
match Json.jfield "original" node with
|
||||
| Some n -> n
|
||||
| None -> failwith "no original"
|
||||
in
|
||||
let locked_rev =
|
||||
match Option.bind (Json.jfield "rev" locked) Json.jstring with
|
||||
| Some s -> s
|
||||
| None -> failwith "no rev"
|
||||
in
|
||||
let locked_type =
|
||||
match Option.bind (Json.jfield "type" locked) Json.jstring with
|
||||
| Some s -> s
|
||||
| None -> failwith "no type"
|
||||
in
|
||||
let original_ref = Option.bind (Json.jfield "ref" original) Json.jstring in
|
||||
let host, path =
|
||||
match locked_type with
|
||||
| "github" ->
|
||||
let owner =
|
||||
match Option.bind (Json.jfield "owner" locked) Json.jstring with
|
||||
| Some s -> s
|
||||
| None -> failwith "no owner"
|
||||
in
|
||||
let repo =
|
||||
match Option.bind (Json.jfield "repo" locked) Json.jstring with
|
||||
| Some s -> s
|
||||
| None -> failwith "no repo"
|
||||
in
|
||||
( "github.com",
|
||||
"/" ^ owner ^ "/" ^ repo
|
||||
^ ".git/info/refs?service=git-upload-pack" )
|
||||
| "git" ->
|
||||
let url =
|
||||
match Option.bind (Json.jfield "url" original) Json.jstring with
|
||||
| Some s -> s
|
||||
| None -> failwith "no url"
|
||||
in
|
||||
let prefix = "https://" in
|
||||
let plen = String.length prefix in
|
||||
if String.length url > plen && String.sub url 0 plen = prefix then
|
||||
let after =
|
||||
String.sub url plen (String.length url - plen)
|
||||
in
|
||||
let slash =
|
||||
match String.index_opt after '/' with
|
||||
| Some i -> i
|
||||
| None -> failwith "no path in url"
|
||||
in
|
||||
let h = String.sub after 0 slash in
|
||||
let p =
|
||||
String.sub after slash (String.length after - slash)
|
||||
in
|
||||
(h, p ^ "/info/refs?service=git-upload-pack")
|
||||
else failwith ("unsupported url: " ^ url)
|
||||
| t -> failwith ("unsupported type: " ^ t)
|
||||
in
|
||||
try
|
||||
let body = Http.https_get ~host ~path in
|
||||
let refs = Http.parse_pktline body in
|
||||
let target_ref =
|
||||
match original_ref with
|
||||
| Some r -> "refs/heads/" ^ r
|
||||
| None -> "HEAD"
|
||||
in
|
||||
let latest_rev =
|
||||
match List.assoc_opt target_ref refs with
|
||||
| Some rev -> rev
|
||||
| None -> failwith ("ref not found: " ^ target_ref)
|
||||
in
|
||||
if latest_rev <> locked_rev then (
|
||||
any_stale := true;
|
||||
Common.meat_print (Common.all_caps name ^ " HAS FRESHER MEAT!"))
|
||||
with _ -> Common.meat_print ("COULD NOT REACH " ^ Common.all_caps name ^ ".."))
|
||||
input_pairs;
|
||||
if not !any_stale then Common.meat_print "ALL MEATS ARE FRESH!";
|
||||
print_string Common.footer
|
||||
9
lib/commands/poke.ml
Normal file
9
lib/commands/poke.ml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
let run () =
|
||||
print_string Common.header;
|
||||
Common.meat_print "PREPARING SUSPICIOUS MEATS..";
|
||||
let build_target =
|
||||
Unix.getenv "MEATS" ^ "#nixosConfigurations." ^ Unix.gethostname ()
|
||||
^ ".config.system.build.toplevel"
|
||||
in
|
||||
Common.do_cmd @@ "nix build --no-link " ^ build_target ^ " --show-trace" |> ignore;
|
||||
print_string Common.footer
|
||||
8
lib/commands/trade.ml
Normal file
8
lib/commands/trade.ml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
let run () =
|
||||
print_string Common.header;
|
||||
Common.meat_print "TRADING FOREIGN MEATS..";
|
||||
Common.do_remote () |> function
|
||||
| Error _ -> print_string "FAILED TO TRADE MEATS."
|
||||
| _ ->
|
||||
();
|
||||
print_string Common.footer
|
||||
7
lib/commands/yum.ml
Normal file
7
lib/commands/yum.ml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
let run () =
|
||||
print_string Common.header;
|
||||
Common.meat_print "CONSUMING DELICIOUS MEATS..";
|
||||
( Common.do_build () |> function
|
||||
| Error _ -> print_string "FAILED TO CONSUME MEATS."
|
||||
| _ -> () );
|
||||
print_string Common.footer
|
||||
Loading…
Add table
Add a link
Reference in a new issue