let run () = print_string Common.header; Common.meat_print "PREPARING RITUAL GROUND.."; let ( >>= ) = Result.bind in let ( >|= ) = Fun.flip Result.map in let tmpdir = Filename.temp_dir "meat-chew" "" in let meats = Unix.getenv "MEATS" in let hostname = Unix.gethostname () in let nix_conf_target = meats ^ "/entry.nix -A nixosConfigurations." ^ hostname ^ {|'.config.environment.etc."nix/nix.conf"'|} in let build_target = meats ^ "/entry.nix -A nixosConfigurations." ^ hostname ^ ".config.system.build.toplevel" in ( Common.do_cmd ~args:false @@ "nix-build --log-format internal-json -v --out-link " ^ tmpdir ^ "/nix.conf " ^ nix_conf_target ^ " |& nom --json" >>= fun () -> Common.meat_print "CONSUMING MEATS.."; Common.do_cmd ~args:false @@ "NIX_USER_CONF_FILES=" ^ tmpdir ^ "/nix.conf nix-build --log-format internal-json -v --out-link " ^ tmpdir ^ "/build " ^ build_target ^ " |& nom --json" >>= fun () -> Common.do_cmd ~args:false @@ "dix /nix/var/nix/profiles/system " ^ tmpdir ^ "/build" >>= fun () -> Common.do_cmd ~args:false @@ "sudo nix-env --set -p /nix/var/nix/profiles/system " ^ tmpdir ^ "/build && " ^ tmpdir ^ "/build/bin/switch-to-configuration switch" >|= fun () -> Unix.unlink @@ tmpdir ^ "/nix-conf"; Unix.unlink @@ tmpdir ^ "/build" ) |> ( function | Error _ -> print_string "FAILED TO CONSUME MEATS." | _ -> () ); print_string Common.footer