From 3393f1ecfe7f21a30a02af4fdb197ae2c75917d5 Mon Sep 17 00:00:00 2001 From: atagen Date: Sat, 23 Nov 2024 16:49:05 +1100 Subject: [PATCH 01/44] first release --- .gitignore | 3 + bin/.ocamlformat | 0 bin/dune | 4 + bin/main.ml | 16 +++ dune-project | 26 +++++ flake.lock | 239 ++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 112 +++++++++++++++++++++ lib/.ocamlformat | 0 lib/dune | 3 + lib/meat.ml | 124 +++++++++++++++++++++++ meat.opam | 31 ++++++ nix/default.nix | 18 ++++ nix/meat-module.nix | 30 ++++++ nix/module.nix | 7 ++ test/dune | 2 + test/test_meat.ml | 0 16 files changed, 615 insertions(+) create mode 100644 .gitignore create mode 100644 bin/.ocamlformat create mode 100644 bin/dune create mode 100644 bin/main.ml create mode 100644 dune-project create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 lib/.ocamlformat create mode 100644 lib/dune create mode 100644 lib/meat.ml create mode 100644 meat.opam create mode 100644 nix/default.nix create mode 100644 nix/meat-module.nix create mode 100644 nix/module.nix create mode 100644 test/dune create mode 100644 test/test_meat.ml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8fa2eea --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +_build +.direnv/ +.envrc diff --git a/bin/.ocamlformat b/bin/.ocamlformat new file mode 100644 index 0000000..e69de29 diff --git a/bin/dune b/bin/dune new file mode 100644 index 0000000..b1f555a --- /dev/null +++ b/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name meat) + (name main) + (libraries meat)) diff --git a/bin/main.ml b/bin/main.ml new file mode 100644 index 0000000..cdbde92 --- /dev/null +++ b/bin/main.ml @@ -0,0 +1,16 @@ +open Meat + +let () = + print_int (Array.length Sys.argv); + if Array.length Sys.argv >= 2 then ( + print_endline " args. contents:"; + Array.iter print_endline Sys.argv; + match String.lowercase_ascii (Array.get Sys.argv 1) with + | "yum" -> yum () + | "cook" -> cook () + | "poke" -> poke () + | "gut" -> gut () + | "look" -> look () + | "fresh" -> fresh () + | _ -> help () + ) else help (); diff --git a/dune-project b/dune-project new file mode 100644 index 0000000..1a97c3c --- /dev/null +++ b/dune-project @@ -0,0 +1,26 @@ +(lang dune 3.17) + +(name meat) + +(generate_opam_files true) + +(source + (github username/reponame)) + +(authors "Author Name ") + +(maintainers "Maintainer Name ") + +(license LICENSE) + +(documentation https://url/to/documentation) + +(package + (name meat) + (synopsis "A short synopsis") + (description "A longer description") + (depends ocaml dune) + (tags + ("add topics" "to describe" your project))) + +; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..f3b3467 --- /dev/null +++ b/flake.lock @@ -0,0 +1,239 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flakey-profile": { + "locked": { + "lastModified": 1712898590, + "narHash": "sha256-FhGIEU93VHAChKEXx905TSiPZKga69bWl1VB37FK//I=", + "owner": "lf-", + "repo": "flakey-profile", + "rev": "243c903fd8eadc0f63d205665a92d4df91d42d9d", + "type": "github" + }, + "original": { + "owner": "lf-", + "repo": "flakey-profile", + "type": "github" + } + }, + "lix": { + "flake": false, + "locked": { + "lastModified": 1732112222, + "narHash": "sha256-H7GN4++a4vE49SUNojZx+FSk4mmpb2ifJUtJMJHProI=", + "rev": "66f6dbda32959dd5cf3a9aaba15af72d037ab7ff", + "type": "tarball", + "url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/66f6dbda32959dd5cf3a9aaba15af72d037ab7ff.tar.gz?rev=66f6dbda32959dd5cf3a9aaba15af72d037ab7ff" + }, + "original": { + "type": "tarball", + "url": "https://git.lix.systems/lix-project/lix/archive/main.tar.gz" + } + }, + "lix-module": { + "inputs": { + "flake-utils": "flake-utils_2", + "flakey-profile": "flakey-profile", + "lix": [ + "lix" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1731967274, + "narHash": "sha256-n6dPGRlMGdL8X5gviA6ZuRfUdbdD5KiNN/BpABA5YT0=", + "rev": "aa2846680fa9a2032939d720487942567fd9eb63", + "type": "tarball", + "url": "https://git.lix.systems/api/v1/repos/lix-project/nixos-module/archive/aa2846680fa9a2032939d720487942567fd9eb63.tar.gz?rev=aa2846680fa9a2032939d720487942567fd9eb63" + }, + "original": { + "type": "tarball", + "url": "https://git.lix.systems/lix-project/nixos-module/archive/main.tar.gz" + } + }, + "nh": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1732089528, + "narHash": "sha256-+yXeJiSFn96pW6H/50DfCfZiOLSfZNGhK7R4f0aUvGY=", + "owner": "viperML", + "repo": "nh", + "rev": "cff51af0ebb09227070b0332c598c7a4b7f8175a", + "type": "github" + }, + "original": { + "owner": "viperML", + "repo": "nh", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1731386116, + "narHash": "sha256-lKA770aUmjPHdTaJWnP3yQ9OI1TigenUqVC3wweqZuI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "689fed12a013f56d4c4d3f612489634267d86529", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1730359060, + "narHash": "sha256-Hkk0mf4pgvX9Ut0YA397nsFqMLhzFVBdFHc4PhBrxYE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e19cfce6f3f08d07653157d8826f5c920c770d7b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e19cfce6f3f08d07653157d8826f5c920c770d7b", + "type": "github" + } + }, + "ocaml-overlay": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1730414122, + "narHash": "sha256-eAfo1XsQMdKuiOOhqCuai7vpIBH8S4ll7Sm4BP/M58c=", + "owner": "nix-ocaml", + "repo": "nix-overlays", + "rev": "1de1cabdb68cbc667dd48da2f128c2df6d5fe604", + "type": "github" + }, + "original": { + "owner": "nix-ocaml", + "repo": "nix-overlays", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "lix": "lix", + "lix-module": "lix-module", + "nh": "nh", + "nixpkgs": [ + "ocaml-overlay", + "nixpkgs" + ], + "ocaml-overlay": "ocaml-overlay" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..56c5bee --- /dev/null +++ b/flake.nix @@ -0,0 +1,112 @@ +{ + inputs = { + nixpkgs.follows = "ocaml-overlay/nixpkgs"; + + ocaml-overlay = { + url = "github:nix-ocaml/nix-overlays"; + }; + + flake-utils.url = "github:numtide/flake-utils"; + + nh.url = "github:viperML/nh"; + + lix = { + url = "https://git.lix.systems/lix-project/lix/archive/main.tar.gz"; + flake = false; + }; + + lix-module = { + url = "https://git.lix.systems/lix-project/nixos-module/archive/main.tar.gz"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.lix.follows = "lix"; + }; + }; + + outputs = inputs @ { + self, + nixpkgs, + flake-utils, + ocaml-overlay, + ... + }: let + inherit (inputs) nixpkgs; + lix-overlay = inputs.lix-module.overlays.default; + lix-module = inputs.lix-module.nixosModules.default; + nh-overlay = inputs.nh.overlays.default; + in + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = import nixpkgs { + inherit system; + overlays = [ + ocaml-overlay.overlays.default + lix-overlay + nh-overlay + ]; + modules = [lix-module]; + extra-substituters = "https://anmonteiro.nix-cache.workers.dev"; + extra-trusted-public-keys = "ocaml.nix-cache.com-1:/xI2h2+56rwFfKyyFVbkJSeGqSIYMC/Je+7XXqGKDIY="; + }; + minimal = let + inherit (pkgs) ocaml-ng; + inherit + (ocaml-ng.ocamlPackages_5_2) + dune_3 + ocaml + ; + in [ + dune_3 + ocaml + ]; + dev = let + inherit (pkgs) ocaml-ng; + inherit + (ocaml-ng.ocamlPackages_5_2) + utop + ocaml-lsp + ocamlformat + ocamlformat-rpc-lib + ; + in [ + utop + ocaml-lsp + ocamlformat + ocamlformat-rpc-lib + ]; + inherit (pkgs) lix nh; + in { + devShells.default = let + inherit (pkgs) mkShell; + in + mkShell { + buildInputs = minimal ++ dev ++ [lix nh]; + }; + + packages.default = pkgs.callPackage ./nix/default.nix {ocaml-deps = minimal;}; + + defaultPackage = self.packages.${system}.default; + } + ) + // { + nixosModules.meat = import ./nix/module.nix { + meatOverlays = [self.overlays.meat nh-overlay]; + lixModule = lix-module; + }; + + overlays.meat = final: _prev: let + ocaml-deps = let + inherit (final) ocaml-ng; + inherit + (ocaml-ng.ocamlPackages_5_2) + dune_3 + ocaml + ; + in [ + dune_3 + ocaml + ]; + in { + meat = final.callPackage ./nix/default.nix {inherit ocaml-deps;}; + }; + }; +} diff --git a/lib/.ocamlformat b/lib/.ocamlformat new file mode 100644 index 0000000..e69de29 diff --git a/lib/dune b/lib/dune new file mode 100644 index 0000000..2b63e36 --- /dev/null +++ b/lib/dune @@ -0,0 +1,3 @@ +(library + (name meat) + (libraries unix)) diff --git a/lib/meat.ml b/lib/meat.ml new file mode 100644 index 0000000..77b6b35 --- /dev/null +++ b/lib/meat.ml @@ -0,0 +1,124 @@ +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 LATEST MEATS\n\ + \t ..N - ..LATEST SUBMEATS OF N\n\ + \t ..-A - ..HUNT ALL SUBMEATS\n" + +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 _ -> () + +let meat_print text = print_endline ("\n \t" ^ text ^ "\n") + +let yum () = + print_string header; + meat_print "CONSUMING DELICIOUS MEATS.."; + do_cmd "nh os switch"; + print_string footer + +let cook () = + print_string header; + meat_print "PREPARING DELICIOUS MEATS.."; + do_cmd "nh os build"; + print_string footer + +let poke () = + print_string header; + meat_print "PREPARING SUSPICIOUS MEATS.."; + do_cmd "nh os build --show-trace"; + print_string footer + +let gut () = + print_string header; + meat_print "CLEANING MEAT STORES.."; + do_cmd "nh clean all"; + print_string footer + +let look () = + print_string header; + meat_print "INSPECTING MEAT.."; + do_cmd "nix flake info --flake $NH_FLAKE"; + print_string footer + +let all_flag () = Array.mem "-a" argv || Array.mem "--all" argv +let derelativise base = List.map (fun a -> base ^ "/" ^ a) + +let filter_dirs fullpath dirs = + dirs |> derelativise fullpath + |> List.filter (fun d -> (Unix.stat d).st_kind = S_DIR) + +let walk ?(include_base = false) entry = + let rec loop dir : string list = + let contents = Sys.readdir dir |> Array.to_list in + let is_flake = List.mem "flake.nix" contents in + if dir = entry && not include_base then + let subdirs = contents |> filter_dirs dir in + List.flatten (List.map loop subdirs) + else if is_flake || (dir = entry && include_base) then + let subdirs = contents |> filter_dirs dir in + let children = List.flatten (List.map loop subdirs) in + [ dir ] @ children + else [] + in + loop entry + +let countdepth s = + s |> String.fold_left (fun acc el -> acc + if el = '/' then 1 else 0) 0 + +let compdepth a b = + let ad = countdepth a and bd = countdepth b in + let dif = ad - bd in + match dif with 0 -> 0 | _ -> dif / abs dif + +let allcaps s = + String.map (fun c -> Char.uppercase_ascii c) s + +let fresh () = + print_string header; + meat_print "HUNTING FRESH MEATS.."; + print_string footer; + let argv_len = Array.length argv in + let root = Sys.getenv "NH_FLAKE" in + let base_dir = root ^ "/flakes" in + let update = + if all_flag () then walk base_dir |> List.sort compdepth |> List.rev + else if argv_len >= 3 then + let subflakes = + match argv_len with + | 3 -> [ argv.(2) ] + | _ -> Array.sub argv 2 (argv_len - 2) |> Array.to_list + in + subflakes |> derelativise base_dir + |> List.map (walk ~include_base:true) + |> List.flatten |> List.sort compdepth |> List.rev + else [] + in + update @ [ root ] + |> List.iter (fun d -> + if d != root then + (meat_print ("PROCESSING SUBMEAT " ^ (String.split_on_char '/' d |> List.rev |> List.hd |> allcaps) ^ "..");) + else + meat_print ("PROCESSING FRESH MEATS.."); + do_cmd ~args:false ("nix flake update --flake " ^ d); + print_string footer;); + print_newline () + +let help () = print_string (header ^ help ^ footer) diff --git a/meat.opam b/meat.opam new file mode 100644 index 0000000..fe4df60 --- /dev/null +++ b/meat.opam @@ -0,0 +1,31 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "A short synopsis" +description: "A longer description" +maintainer: ["Maintainer Name "] +authors: ["Author Name "] +license: "LICENSE" +tags: ["add topics" "to describe" "your" "project"] +homepage: "https://github.com/username/reponame" +doc: "https://url/to/documentation" +bug-reports: "https://github.com/username/reponame/issues" +depends: [ + "ocaml" + "dune" {>= "3.17"} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/username/reponame.git" diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..26dd7ff --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,18 @@ +{ + pkgs, + lib, + ocamlPackages, + ocaml-deps, + nh, + nix, + ... +}: +ocamlPackages.buildDunePackage { + pname = "meat"; + version = "delicious-0.1"; + + minimalOCamlVersion = "5.2"; + + src = ./..; + buildInputs = ocaml-deps; +} diff --git a/nix/meat-module.nix b/nix/meat-module.nix new file mode 100644 index 0000000..9241d68 --- /dev/null +++ b/nix/meat-module.nix @@ -0,0 +1,30 @@ +{ + pkgs, + lib, + config, + ... +}: let + inherit (lib) mkEnableOption mkOption types; + cfg = config.programs.meat; +in { + options.programs.meat = { + enable = mkEnableOption "meat"; + flake = mkOption { + type = with types; nullOr (either path str); + default = null; + description = "path to your system flake"; + }; + }; + config = let + inherit (pkgs) meat nh lix; + in + lib.mkIf + cfg.enable + { + environment.systemPackages = [meat nh lix]; + environment.sessionVariables.NH_FLAKE = + if (cfg.flake == null) + then abort "Please set the programs.meat.flake option to your system flake." + else config.programs.meat.flake; + }; +} diff --git a/nix/module.nix b/nix/module.nix new file mode 100644 index 0000000..d30769b --- /dev/null +++ b/nix/module.nix @@ -0,0 +1,7 @@ +{ + meatOverlays, + lixModule, +}: { + imports = [./meat-module.nix lixModule]; + nixpkgs.overlays = meatOverlays; +} diff --git a/test/dune b/test/dune new file mode 100644 index 0000000..249a645 --- /dev/null +++ b/test/dune @@ -0,0 +1,2 @@ +(test + (name test_meat)) diff --git a/test/test_meat.ml b/test/test_meat.ml new file mode 100644 index 0000000..e69de29 From 5ccc27c0e26d74c09858f70bd2c3908bf971cc3a Mon Sep 17 00:00:00 2001 From: atagen Date: Sat, 23 Nov 2024 17:15:02 +1100 Subject: [PATCH 02/44] remove debug prints, oops --- bin/main.ml | 3 --- flake.nix | 6 +++++- nix/default.nix | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/main.ml b/bin/main.ml index cdbde92..086f4b0 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,10 +1,7 @@ open Meat let () = - print_int (Array.length Sys.argv); if Array.length Sys.argv >= 2 then ( - print_endline " args. contents:"; - Array.iter print_endline Sys.argv; match String.lowercase_ascii (Array.get Sys.argv 1) with | "yum" -> yum () | "cook" -> cook () diff --git a/flake.nix b/flake.nix index 56c5bee..853190b 100644 --- a/flake.nix +++ b/flake.nix @@ -89,7 +89,11 @@ ) // { nixosModules.meat = import ./nix/module.nix { - meatOverlays = [self.overlays.meat nh-overlay]; + meatOverlays = [ + self.overlays.meat + nh-overlay + ocaml-overlay.overlays.default + ]; lixModule = lix-module; }; diff --git a/nix/default.nix b/nix/default.nix index 26dd7ff..ad7465a 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -5,6 +5,7 @@ ocaml-deps, nh, nix, + git, ... }: ocamlPackages.buildDunePackage { @@ -14,5 +15,6 @@ ocamlPackages.buildDunePackage { minimalOCamlVersion = "5.2"; src = ./..; + nativeBuildInputs = [git]; buildInputs = ocaml-deps; } From 61ccbd63b59716aa2c5b80a71ab5b85d62d5fff0 Mon Sep 17 00:00:00 2001 From: atagen Date: Sat, 23 Nov 2024 17:22:15 +1100 Subject: [PATCH 03/44] include envrc --- .envrc | 1 + .gitignore | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 8fa2eea..8444c29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ _build .direnv/ -.envrc From 245f62ed4196fdbf3b8018bf58e52ce22648bb16 Mon Sep 17 00:00:00 2001 From: atagen Date: Sat, 23 Nov 2024 17:26:23 +1100 Subject: [PATCH 04/44] look cmd typo --- lib/meat.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/meat.ml b/lib/meat.ml index 77b6b35..3ebffa6 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -55,7 +55,7 @@ let gut () = let look () = print_string header; meat_print "INSPECTING MEAT.."; - do_cmd "nix flake info --flake $NH_FLAKE"; + do_cmd "nix flake info $NH_FLAKE"; print_string footer let all_flag () = Array.mem "-a" argv || Array.mem "--all" argv From ce7b751c6f85a09af43498401eb56d5e04d790d8 Mon Sep 17 00:00:00 2001 From: atagen Date: Sat, 23 Nov 2024 17:27:52 +1100 Subject: [PATCH 05/44] revamp look command --- lib/meat.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/meat.ml b/lib/meat.ml index 3ebffa6..8336f1b 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -55,7 +55,10 @@ let gut () = let look () = print_string header; meat_print "INSPECTING MEAT.."; - do_cmd "nix flake info $NH_FLAKE"; + 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 let all_flag () = Array.mem "-a" argv || Array.mem "--all" argv From 6681fd984f1692a6fd8f61c7e7d4427c4fd1d2f5 Mon Sep 17 00:00:00 2001 From: atagen Date: Sat, 23 Nov 2024 22:50:46 +1100 Subject: [PATCH 06/44] check for nh_flake variable --- bin/main.ml | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/bin/main.ml b/bin/main.ml index 086f4b0..3023220 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,13 +1,18 @@ open Meat let () = - if Array.length Sys.argv >= 2 then ( - match String.lowercase_ascii (Array.get Sys.argv 1) with - | "yum" -> yum () - | "cook" -> cook () - | "poke" -> poke () - | "gut" -> gut () - | "look" -> look () - | "fresh" -> fresh () - | _ -> help () - ) else help (); + match Sys.getenv_opt "NH_FLAKE" with + | Some _ -> + if Array.length Sys.argv >= 2 then + match String.lowercase_ascii (Array.get Sys.argv 1) with + | "yum" -> yum () + | "cook" -> cook () + | "poke" -> poke () + | "gut" -> gut () + | "look" -> look () + | "fresh" -> fresh () + | _ -> help () + else help () + | None -> + meat_print "NO PATH TO RUNESTONE FOUND!"; + help () From a624c6ff044c10be2af0c331358eebe5d44e67fc Mon Sep 17 00:00:00 2001 From: atagen Date: Sat, 23 Nov 2024 22:50:54 +1100 Subject: [PATCH 07/44] flake bump --- flake.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/flake.lock b/flake.lock index f3b3467..24504ca 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1726560853, - "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -41,11 +41,11 @@ "systems": "systems_3" }, "locked": { - "lastModified": 1726560853, - "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -142,17 +142,17 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1730359060, - "narHash": "sha256-Hkk0mf4pgvX9Ut0YA397nsFqMLhzFVBdFHc4PhBrxYE=", + "lastModified": 1732267161, + "narHash": "sha256-6NjOM6IWdyqJLzrFxuajvf1DGDEr7ceFaeKZ081Ya3w=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e19cfce6f3f08d07653157d8826f5c920c770d7b", + "rev": "a25e476c6a35d5fbc5c85754bba5eeba0ee3074e", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "e19cfce6f3f08d07653157d8826f5c920c770d7b", + "rev": "a25e476c6a35d5fbc5c85754bba5eeba0ee3074e", "type": "github" } }, @@ -162,11 +162,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1730414122, - "narHash": "sha256-eAfo1XsQMdKuiOOhqCuai7vpIBH8S4ll7Sm4BP/M58c=", + "lastModified": 1732316396, + "narHash": "sha256-ammsJEPmId54GdCCkqabF/rD8HbhbX1OR2Xm2Xn5bi8=", "owner": "nix-ocaml", "repo": "nix-overlays", - "rev": "1de1cabdb68cbc667dd48da2f128c2df6d5fe604", + "rev": "486b0b646d69d0d36f96ce5c1986e0573f6d08e9", "type": "github" }, "original": { From c9c69f647d4de8a97c51adc75b1ab2b0c287e3f3 Mon Sep 17 00:00:00 2001 From: atagen Date: Sat, 23 Nov 2024 23:33:34 +1100 Subject: [PATCH 08/44] ignore nix build dir --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8444c29..9d8c5be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ _build .direnv/ +result From a37079c3d75dd85c2413bfa2e1dbb6d5aeec1a93 Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 24 Nov 2024 00:05:19 +1100 Subject: [PATCH 09/44] refine submeat behaviour --- lib/meat.ml | 80 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 29 deletions(-) diff --git a/lib/meat.ml b/lib/meat.ml index 8336f1b..62daf79 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -9,8 +9,9 @@ let help = \tGUT - CLEAN MEAT STORES\n\ \tLOOK - INSPECT MEAT\n\ \tFRESH - HUNT LATEST MEATS\n\ - \t ..N - ..LATEST SUBMEATS OF N\n\ - \t ..-A - ..HUNT ALL SUBMEATS\n" + \t..N - ..MEATS OF N\n\ + \t..-S N - ..SUBMEAT N\n\ + \t..-A - ..ALL MEATS\n" open Sys @@ -62,20 +63,23 @@ let look () = 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 let derelativise base = List.map (fun a -> base ^ "/" ^ a) let filter_dirs fullpath dirs = dirs |> derelativise fullpath |> List.filter (fun d -> (Unix.stat d).st_kind = S_DIR) -let walk ?(include_base = false) entry = +let readdir d = try Sys.readdir d with Sys_error _ -> [||] + +let walk entry = let rec loop dir : string list = - let contents = Sys.readdir dir |> Array.to_list in + let contents = readdir dir |> Array.to_list in let is_flake = List.mem "flake.nix" contents in - if dir = entry && not include_base then + if dir = entry then let subdirs = contents |> filter_dirs dir in List.flatten (List.map loop subdirs) - else if is_flake || (dir = entry && include_base) then + else if is_flake then let subdirs = contents |> filter_dirs dir in let children = List.flatten (List.map loop subdirs) in [ dir ] @ children @@ -91,37 +95,55 @@ let compdepth a b = let dif = ad - bd in match dif with 0 -> 0 | _ -> dif / abs dif -let allcaps s = - String.map (fun c -> Char.uppercase_ascii c) s +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) +let fmt_dir d = String.split_on_char '/' d |> List.rev |> List.hd |> all_caps + +let submeats s = + s + |> List.iter (fun d -> + meat_print ("PROCESSING SUBMEAT " ^ fmt_dir d ^ ".."); + do_cmd ~args:false ("nix flake update --flake " ^ d)) let fresh () = print_string header; meat_print "HUNTING FRESH MEATS.."; - print_string footer; let argv_len = Array.length argv in let root = Sys.getenv "NH_FLAKE" in let base_dir = root ^ "/flakes" in - let update = - if all_flag () then walk base_dir |> List.sort compdepth |> List.rev - else if argv_len >= 3 then + (match (sub_flag (), all_flag ()) with + | false, false -> + (* no flags, plain flake inputs *) + let flakes = Array.sub argv 2 (argv_len - 2) in + flakes + |> Array.iter (fun f -> + meat_print ("PROCESSING FRESH MEAT " ^ all_caps f ^ ".."); + do_cmd ~args:false + ("nix flake update " ^ all_low f ^ " --flake $NH_FLAKE")) + | _, 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) + | true, _ when argv_len >= 4 -> + (* sub flag, update inputs as subflakes *) let subflakes = - match argv_len with - | 3 -> [ argv.(2) ] - | _ -> Array.sub argv 2 (argv_len - 2) |> Array.to_list + (match argv_len with + | 4 -> [ argv.(3) ] + | _ -> Array.sub argv 4 (argv_len - 4) |> Array.to_list) in - subflakes |> derelativise base_dir - |> List.map (walk ~include_base:true) - |> List.flatten |> List.sort compdepth |> List.rev - else [] - in - update @ [ root ] - |> List.iter (fun d -> - if d != root then - (meat_print ("PROCESSING SUBMEAT " ^ (String.split_on_char '/' d |> List.rev |> List.hd |> allcaps) ^ "..");) - else - meat_print ("PROCESSING FRESH MEATS.."); - do_cmd ~args:false ("nix flake update --flake " ^ d); - print_string footer;); + let sf_full = subflakes |> derelativise base_dir in + sf_full |> List.map walk |> List.flatten |> List.sort compdepth + |> List.rev |> List.append sf_full |> submeats; + print_string footer; + meat_print "PROCESSING FRESH MEATS.."; + subflakes + |> List.iter (fun f -> + do_cmd ~args:false + ("nix flake update " ^ all_low f ^ " --flake $NH_FLAKE")) + | _ -> print_string help); + print_string footer; print_newline () - + let help () = print_string (header ^ help ^ footer) From bb6b145cfaf2870a686ae3076118e04baff30586 Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 24 Nov 2024 00:15:11 +1100 Subject: [PATCH 10/44] automate version from rev --- flake.nix | 10 ++++++++-- nix/default.nix | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 853190b..1b1aab6 100644 --- a/flake.nix +++ b/flake.nix @@ -82,7 +82,10 @@ buildInputs = minimal ++ dev ++ [lix nh]; }; - packages.default = pkgs.callPackage ./nix/default.nix {ocaml-deps = minimal;}; + packages.default = pkgs.callPackage ./nix/default.nix { + ocaml-deps = minimal; + version = self.rev or self.dirtyRev or "dirty"; + }; defaultPackage = self.packages.${system}.default; } @@ -110,7 +113,10 @@ ocaml ]; in { - meat = final.callPackage ./nix/default.nix {inherit ocaml-deps;}; + meat = final.callPackage ./nix/default.nix { + inherit ocaml-deps; + version = self.rev or self.dirtyRev or "dirty"; + }; }; }; } diff --git a/nix/default.nix b/nix/default.nix index ad7465a..e236d59 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -6,11 +6,12 @@ nh, nix, git, + version, ... }: ocamlPackages.buildDunePackage { pname = "meat"; - version = "delicious-0.1"; + version = "delicious-${version}"; minimalOCamlVersion = "5.2"; From 5006969275a981db5df5bac98f33fb1a2b706939 Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 24 Nov 2024 00:18:35 +1100 Subject: [PATCH 11/44] use short rev instead --- flake.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 1b1aab6..13ff9c1 100644 --- a/flake.nix +++ b/flake.nix @@ -33,6 +33,7 @@ lix-overlay = inputs.lix-module.overlays.default; lix-module = inputs.lix-module.nixosModules.default; nh-overlay = inputs.nh.overlays.default; + version = self.shortRev or self.dirtyShortRev or "dirty"; in flake-utils.lib.eachDefaultSystem ( system: let @@ -84,7 +85,7 @@ packages.default = pkgs.callPackage ./nix/default.nix { ocaml-deps = minimal; - version = self.rev or self.dirtyRev or "dirty"; + inherit version; }; defaultPackage = self.packages.${system}.default; @@ -114,8 +115,7 @@ ]; in { meat = final.callPackage ./nix/default.nix { - inherit ocaml-deps; - version = self.rev or self.dirtyRev or "dirty"; + inherit ocaml-deps version; }; }; }; From 2248bbef57d6555245cdc3596453c32aec3fa6cc Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 24 Nov 2024 00:18:35 +1100 Subject: [PATCH 12/44] use short rev instead only short rev Revert "only short rev" This reverts commit 7d8b0ab81d35f6b5fcd5f55b78cb0510b210294b. --- flake.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 1b1aab6..13ff9c1 100644 --- a/flake.nix +++ b/flake.nix @@ -33,6 +33,7 @@ lix-overlay = inputs.lix-module.overlays.default; lix-module = inputs.lix-module.nixosModules.default; nh-overlay = inputs.nh.overlays.default; + version = self.shortRev or self.dirtyShortRev or "dirty"; in flake-utils.lib.eachDefaultSystem ( system: let @@ -84,7 +85,7 @@ packages.default = pkgs.callPackage ./nix/default.nix { ocaml-deps = minimal; - version = self.rev or self.dirtyRev or "dirty"; + inherit version; }; defaultPackage = self.packages.${system}.default; @@ -114,8 +115,7 @@ ]; in { meat = final.callPackage ./nix/default.nix { - inherit ocaml-deps; - version = self.rev or self.dirtyRev or "dirty"; + inherit ocaml-deps version; }; }; }; From 6918230d1e81c9087a181c5bf5c813cfb01ec823 Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 24 Nov 2024 00:25:18 +1100 Subject: [PATCH 13/44] try lastModified instead --- flake.nix | 2 +- nix/default.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 13ff9c1..09d3715 100644 --- a/flake.nix +++ b/flake.nix @@ -33,7 +33,7 @@ lix-overlay = inputs.lix-module.overlays.default; lix-module = inputs.lix-module.nixosModules.default; nh-overlay = inputs.nh.overlays.default; - version = self.shortRev or self.dirtyShortRev or "dirty"; + version = builtins.toString self.lastModified; in flake-utils.lib.eachDefaultSystem ( system: let diff --git a/nix/default.nix b/nix/default.nix index e236d59..529053c 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -11,7 +11,7 @@ }: ocamlPackages.buildDunePackage { pname = "meat"; - version = "delicious-${version}"; + version = "0.1-delicious-${version}"; minimalOCamlVersion = "5.2"; From f67c005e5eee036b12f39cd131d8fbba7b49a8d5 Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 24 Nov 2024 11:14:11 +1100 Subject: [PATCH 14/44] newline at end of output --- lib/meat.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/meat.ml b/lib/meat.ml index 62daf79..8cbe245 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -146,4 +146,4 @@ let fresh () = print_string footer; print_newline () -let help () = print_string (header ^ help ^ footer) +let help () = print_string (header ^ help ^ footer ^ "\n") From c9348daa9aba821063857a0e8d211e1ae79cc5e3 Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 24 Nov 2024 11:18:33 +1100 Subject: [PATCH 15/44] account for zero arity fresh command --- lib/meat.ml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/meat.ml b/lib/meat.ml index 8cbe245..5b85988 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -114,12 +114,15 @@ let fresh () = (match (sub_flag (), all_flag ()) with | false, false -> (* no flags, plain flake inputs *) - let flakes = Array.sub argv 2 (argv_len - 2) in - flakes - |> Array.iter (fun f -> - meat_print ("PROCESSING FRESH MEAT " ^ all_caps f ^ ".."); - do_cmd ~args:false - ("nix flake update " ^ all_low f ^ " --flake $NH_FLAKE")) + (if argv_len > 3 then + let flakes = Array.sub argv 2 (argv_len - 2) in + flakes + |> Array.iter (fun f -> + meat_print ("PROCESSING FRESH MEAT " ^ all_caps f ^ ".."); + do_cmd ~args:false + ("nix flake update " ^ all_low f ^ " --flake $NH_FLAKE")); + else + do_cmd ("nix flake update --flake $NH_FLAKE")) | _, true -> (* all flag, update all subflakes and main flake inputs *) walk base_dir |> List.sort compdepth |> List.rev |> submeats; From c1b5f7b4aea8b8a4c4746bfda0a05b631776ff27 Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 24 Nov 2024 11:19:12 +1100 Subject: [PATCH 16/44] bump flake --- flake.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/flake.lock b/flake.lock index 24504ca..978f395 100644 --- a/flake.lock +++ b/flake.lock @@ -142,17 +142,17 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1732267161, - "narHash": "sha256-6NjOM6IWdyqJLzrFxuajvf1DGDEr7ceFaeKZ081Ya3w=", + "lastModified": 1732359803, + "narHash": "sha256-DPGw9u0Ejy5Hkip79wWSfC1i8q+YqKYngi0AFx3Z4W8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "a25e476c6a35d5fbc5c85754bba5eeba0ee3074e", + "rev": "1c79f7f85262067ecdffd95234032dda50f42958", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "a25e476c6a35d5fbc5c85754bba5eeba0ee3074e", + "rev": "1c79f7f85262067ecdffd95234032dda50f42958", "type": "github" } }, @@ -162,11 +162,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1732316396, - "narHash": "sha256-ammsJEPmId54GdCCkqabF/rD8HbhbX1OR2Xm2Xn5bi8=", + "lastModified": 1732401100, + "narHash": "sha256-eNxEkqGdyD+x3yNhJ096N7/8j8TryWA493rSmaL9jAQ=", "owner": "nix-ocaml", "repo": "nix-overlays", - "rev": "486b0b646d69d0d36f96ce5c1986e0573f6d08e9", + "rev": "f6f12811924de05d921c397fad7455e0e2ee644c", "type": "github" }, "original": { From 3601213fd01ee7a6963ad913741d5aa13eeb9315 Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 24 Nov 2024 11:21:34 +1100 Subject: [PATCH 17/44] change help wording --- lib/meat.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/meat.ml b/lib/meat.ml index 5b85988..759e413 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -8,7 +8,7 @@ let help = \tPOKE - TASTE SUSPICIOUS MEATS\n\ \tGUT - CLEAN MEAT STORES\n\ \tLOOK - INSPECT MEAT\n\ - \tFRESH - HUNT LATEST MEATS\n\ + \tFRESH - HUNT FRESH MEATS\n\ \t..N - ..MEATS OF N\n\ \t..-S N - ..SUBMEAT N\n\ \t..-A - ..ALL MEATS\n" From 933bf2efbd540642446a512415849cc0e7bcdd94 Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 24 Nov 2024 11:34:33 +1100 Subject: [PATCH 18/44] tighten acceptance of fresh cmd flags --- lib/meat.ml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/meat.ml b/lib/meat.ml index 759e413..1e6c13d 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -62,8 +62,19 @@ let look () = do_cmd "nix flake show $NH_FLAKE"; 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 +(* let all_flag () = Array.mem "-a" argv || Array.mem "--all" argv +let sub_flag () = Array.mem "-s" argv || Array.mem "--subflake" argv *) +let all_flag () = if Array.length argv >= 3 then match Array.get argv 2 with + | "-a" | "--all" -> true + | _ -> false +else + false +let sub_flag () = if Array.length argv >= 3 then match Array.get argv 2 with + | "-s" | "--sub" -> true + | _ -> false +else + false + let derelativise base = List.map (fun a -> base ^ "/" ^ a) let filter_dirs fullpath dirs = From f3a64228a40ecd237f345ae1cc15c6c031739a96 Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 24 Nov 2024 11:34:44 +1100 Subject: [PATCH 19/44] add substituter to flake --- flake.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/flake.nix b/flake.nix index 09d3715..fe29cf2 100644 --- a/flake.nix +++ b/flake.nix @@ -22,6 +22,11 @@ }; }; + nixConfig = { + extra-substituters = "https://anmonteiro.nix-cache.workers.dev"; + extra-trusted-public-keys = "ocaml.nix-cache.com-1:/xI2h2+56rwFfKyyFVbkJSeGqSIYMC/Je+7XXqGKDIY="; + }; + outputs = inputs @ { self, nixpkgs, From f08580885fea34811d2d0583c86863588102b09d Mon Sep 17 00:00:00 2001 From: atagen Date: Thu, 5 Dec 2024 13:26:42 +1100 Subject: [PATCH 20/44] clean up default.nix --- nix/default.nix | 4 ---- 1 file changed, 4 deletions(-) diff --git a/nix/default.nix b/nix/default.nix index 529053c..c1317fe 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,10 +1,6 @@ { - pkgs, - lib, ocamlPackages, ocaml-deps, - nh, - nix, git, version, ... From 48f1fa975f41c6599f8c0bfae3f923b8daefcf2b Mon Sep 17 00:00:00 2001 From: atagen Date: Thu, 5 Dec 2024 13:26:51 +1100 Subject: [PATCH 21/44] fix minor syntax bugs squash --- lib/meat.ml | 55 +++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/lib/meat.ml b/lib/meat.ml index 1e6c13d..188a176 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -44,7 +44,7 @@ let cook () = let poke () = print_string header; meat_print "PREPARING SUSPICIOUS MEATS.."; - do_cmd "nh os build --show-trace"; + do_cmd "nh os build -- --show-trace"; print_string footer let gut () = @@ -64,16 +64,15 @@ let look () = (* let all_flag () = Array.mem "-a" argv || Array.mem "--all" argv let sub_flag () = Array.mem "-s" argv || Array.mem "--subflake" argv *) -let all_flag () = if Array.length argv >= 3 then match Array.get argv 2 with - | "-a" | "--all" -> true - | _ -> false -else - false -let sub_flag () = if Array.length argv >= 3 then match Array.get argv 2 with - | "-s" | "--sub" -> true - | _ -> false -else - false +let all_flag () = + if Array.length argv >= 3 then + match Array.get argv 2 with "-a" | "--all" -> true | _ -> false + else false + +let sub_flag () = + if Array.length argv >= 3 then + match Array.get argv 2 with "-s" | "--sub" -> true | _ -> false + else false let derelativise base = List.map (fun a -> base ^ "/" ^ a) @@ -84,15 +83,16 @@ let filter_dirs fullpath dirs = let readdir d = try Sys.readdir d with Sys_error _ -> [||] let walk entry = + let open List in let rec loop dir : string list = let contents = readdir dir |> Array.to_list in - let is_flake = List.mem "flake.nix" contents in + let is_flake = mem "flake.nix" contents in if dir = entry then let subdirs = contents |> filter_dirs dir in - List.flatten (List.map loop subdirs) + flatten (map loop subdirs) else if is_flake then let subdirs = contents |> filter_dirs dir in - let children = List.flatten (List.map loop subdirs) in + let children = flatten (map loop subdirs) in [ dir ] @ children else [] in @@ -125,15 +125,15 @@ let fresh () = (match (sub_flag (), all_flag ()) with | false, false -> (* no flags, plain flake inputs *) - (if argv_len > 3 then - let flakes = Array.sub argv 2 (argv_len - 2) in + if argv_len >= 3 then + let open Array in + let flakes = sub argv 2 (argv_len - 2) in flakes - |> Array.iter (fun f -> - meat_print ("PROCESSING FRESH MEAT " ^ all_caps f ^ ".."); - do_cmd ~args:false - ("nix flake update " ^ all_low f ^ " --flake $NH_FLAKE")); - else - do_cmd ("nix flake update --flake $NH_FLAKE")) + |> 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) | _, true -> (* all flag, update all subflakes and main flake inputs *) walk base_dir |> List.sort compdepth |> List.rev |> submeats; @@ -143,17 +143,18 @@ let fresh () = | true, _ when argv_len >= 4 -> (* sub flag, update inputs as subflakes *) let subflakes = - (match argv_len with + match argv_len with | 4 -> [ argv.(3) ] - | _ -> Array.sub argv 4 (argv_len - 4) |> Array.to_list) + | _ -> Array.sub argv 4 (argv_len - 4) |> Array.to_list in + let open List in let sf_full = subflakes |> derelativise base_dir in - sf_full |> List.map walk |> List.flatten |> List.sort compdepth - |> List.rev |> List.append sf_full |> submeats; + sf_full |> map walk |> flatten |> sort compdepth |> rev |> append sf_full + |> submeats; print_string footer; meat_print "PROCESSING FRESH MEATS.."; subflakes - |> List.iter (fun f -> + |> iter (fun f -> do_cmd ~args:false ("nix flake update " ^ all_low f ^ " --flake $NH_FLAKE")) | _ -> print_string help); From 9fc368c2e63be53410147d3268814dd4d0e43c3c Mon Sep 17 00:00:00 2001 From: atagen Date: Thu, 5 Dec 2024 18:15:37 +1100 Subject: [PATCH 22/44] remove ocaml overlay --- flake.nix | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/flake.nix b/flake.nix index fe29cf2..54ec089 100644 --- a/flake.nix +++ b/flake.nix @@ -1,10 +1,6 @@ { inputs = { - nixpkgs.follows = "ocaml-overlay/nixpkgs"; - - ocaml-overlay = { - url = "github:nix-ocaml/nix-overlays"; - }; + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; @@ -22,16 +18,10 @@ }; }; - nixConfig = { - extra-substituters = "https://anmonteiro.nix-cache.workers.dev"; - extra-trusted-public-keys = "ocaml.nix-cache.com-1:/xI2h2+56rwFfKyyFVbkJSeGqSIYMC/Je+7XXqGKDIY="; - }; - outputs = inputs @ { self, nixpkgs, flake-utils, - ocaml-overlay, ... }: let inherit (inputs) nixpkgs; @@ -45,7 +35,6 @@ pkgs = import nixpkgs { inherit system; overlays = [ - ocaml-overlay.overlays.default lix-overlay nh-overlay ]; @@ -54,9 +43,8 @@ extra-trusted-public-keys = "ocaml.nix-cache.com-1:/xI2h2+56rwFfKyyFVbkJSeGqSIYMC/Je+7XXqGKDIY="; }; minimal = let - inherit (pkgs) ocaml-ng; inherit - (ocaml-ng.ocamlPackages_5_2) + (pkgs.ocamlPackages) dune_3 ocaml ; @@ -65,9 +53,8 @@ ocaml ]; dev = let - inherit (pkgs) ocaml-ng; inherit - (ocaml-ng.ocamlPackages_5_2) + (pkgs.ocamlPackages) utop ocaml-lsp ocamlformat @@ -101,16 +88,14 @@ meatOverlays = [ self.overlays.meat nh-overlay - ocaml-overlay.overlays.default ]; lixModule = lix-module; }; - overlays.meat = final: _prev: let + overlays.meat = final: prev: let ocaml-deps = let - inherit (final) ocaml-ng; inherit - (ocaml-ng.ocamlPackages_5_2) + (prev.ocamlPackages) dune_3 ocaml ; From abd078ac19c2678e5c614f401c188c2a1bf5b9b4 Mon Sep 17 00:00:00 2001 From: atagen Date: Thu, 5 Dec 2024 18:26:45 +1100 Subject: [PATCH 23/44] downgrade dune lang version --- dune-project | 2 +- flake.lock | 70 ++++++---------------------------------------------- 2 files changed, 8 insertions(+), 64 deletions(-) diff --git a/dune-project b/dune-project index 1a97c3c..256991c 100644 --- a/dune-project +++ b/dune-project @@ -1,4 +1,4 @@ -(lang dune 3.17) +(lang dune 3.16) (name meat) diff --git a/flake.lock b/flake.lock index 978f395..9d55469 100644 --- a/flake.lock +++ b/flake.lock @@ -36,24 +36,6 @@ "type": "github" } }, - "flake-utils_3": { - "inputs": { - "systems": "systems_3" - }, - "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "flakey-profile": { "locked": { "lastModified": 1712898590, @@ -142,36 +124,17 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1732359803, - "narHash": "sha256-DPGw9u0Ejy5Hkip79wWSfC1i8q+YqKYngi0AFx3Z4W8=", - "owner": "NixOS", + "lastModified": 1733229606, + "narHash": "sha256-FLYY5M0rpa5C2QAE3CKLYAM6TwbKicdRK6qNrSHlNrE=", + "owner": "nixos", "repo": "nixpkgs", - "rev": "1c79f7f85262067ecdffd95234032dda50f42958", + "rev": "566e53c2ad750c84f6d31f9ccb9d00f823165550", "type": "github" }, "original": { - "owner": "NixOS", + "owner": "nixos", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", - "rev": "1c79f7f85262067ecdffd95234032dda50f42958", - "type": "github" - } - }, - "ocaml-overlay": { - "inputs": { - "flake-utils": "flake-utils_3", - "nixpkgs": "nixpkgs_2" - }, - "locked": { - "lastModified": 1732401100, - "narHash": "sha256-eNxEkqGdyD+x3yNhJ096N7/8j8TryWA493rSmaL9jAQ=", - "owner": "nix-ocaml", - "repo": "nix-overlays", - "rev": "f6f12811924de05d921c397fad7455e0e2ee644c", - "type": "github" - }, - "original": { - "owner": "nix-ocaml", - "repo": "nix-overlays", "type": "github" } }, @@ -181,11 +144,7 @@ "lix": "lix", "lix-module": "lix-module", "nh": "nh", - "nixpkgs": [ - "ocaml-overlay", - "nixpkgs" - ], - "ocaml-overlay": "ocaml-overlay" + "nixpkgs": "nixpkgs_2" } }, "systems": { @@ -217,21 +176,6 @@ "repo": "default", "type": "github" } - }, - "systems_3": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", From fa2b70cfdb5df322bbc80f3349c49cf006a09712 Mon Sep 17 00:00:00 2001 From: atagen Date: Fri, 6 Dec 2024 15:19:33 +1100 Subject: [PATCH 24/44] gitignore update --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9d8c5be..802d42f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ _build .direnv/ result +justfile \ No newline at end of file From 32347132ccdaa03093e4a6a523061ec9c74c7c6b Mon Sep 17 00:00:00 2001 From: atagen Date: Fri, 6 Dec 2024 15:20:25 +1100 Subject: [PATCH 25/44] add ocaml overlay back, create justfile --- flake.lock | 38 ++++++++++++++++++++++++++++---------- flake.nix | 46 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 67 insertions(+), 17 deletions(-) diff --git a/flake.lock b/flake.lock index 9d55469..8ab77d7 100644 --- a/flake.lock +++ b/flake.lock @@ -73,7 +73,7 @@ "lix" ], "nixpkgs": [ - "nixpkgs" + "nixpkgs-oc" ] }, "locked": { @@ -122,19 +122,37 @@ "type": "github" } }, - "nixpkgs_2": { + "nixpkgs-oc": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, "locked": { - "lastModified": 1733229606, - "narHash": "sha256-FLYY5M0rpa5C2QAE3CKLYAM6TwbKicdRK6qNrSHlNrE=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "566e53c2ad750c84f6d31f9ccb9d00f823165550", + "lastModified": 1733437725, + "narHash": "sha256-ridu0NcO4Dr2TsHqPE+kh58xTHcXg7IHq/FF74KrP/g=", + "owner": "nix-ocaml", + "repo": "nix-overlays", + "rev": "03b85ffd6c37255829d475f3584f8d8a1556d5f2", "type": "github" }, "original": { - "owner": "nixos", - "ref": "nixpkgs-unstable", + "owner": "nix-ocaml", + "repo": "nix-overlays", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1733380312, + "narHash": "sha256-ywntxT10Om755wkB9tYgJwEwELQZKYAO5WcNuHv1vjI=", + "owner": "NixOS", "repo": "nixpkgs", + "rev": "a772498086eac57d97065a980a21fc0f304e3192", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a772498086eac57d97065a980a21fc0f304e3192", "type": "github" } }, @@ -144,7 +162,7 @@ "lix": "lix", "lix-module": "lix-module", "nh": "nh", - "nixpkgs": "nixpkgs_2" + "nixpkgs-oc": "nixpkgs-oc" } }, "systems": { diff --git a/flake.nix b/flake.nix index 54ec089..1732604 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + nixpkgs-oc.url = "github:nix-ocaml/nix-overlays"; flake-utils.url = "github:numtide/flake-utils"; @@ -13,18 +13,23 @@ lix-module = { url = "https://git.lix.systems/lix-project/nixos-module/archive/main.tar.gz"; - inputs.nixpkgs.follows = "nixpkgs"; + inputs.nixpkgs.follows = "nixpkgs-oc"; inputs.lix.follows = "lix"; }; }; + nixConfig = { + extra-substituters = "https://anmonteiro.nix-cache.workers.dev"; + extra-trusted-public-keys = "ocaml.nix-cache.com-1:/xI2h2+56rwFfKyyFVbkJSeGqSIYMC/Je+7XXqGKDIY="; + }; + outputs = inputs @ { self, - nixpkgs, + nixpkgs-oc, flake-utils, ... }: let - inherit (inputs) nixpkgs; + inherit (inputs) nixpkgs-oc; lix-overlay = inputs.lix-module.overlays.default; lix-module = inputs.lix-module.nixosModules.default; nh-overlay = inputs.nh.overlays.default; @@ -32,11 +37,12 @@ in flake-utils.lib.eachDefaultSystem ( system: let - pkgs = import nixpkgs { + pkgs = import nixpkgs-oc { inherit system; overlays = [ lix-overlay nh-overlay + nixpkgs-oc.overlays.default ]; modules = [lix-module]; extra-substituters = "https://anmonteiro.nix-cache.workers.dev"; @@ -73,6 +79,31 @@ in mkShell { buildInputs = minimal ++ dev ++ [lix nh]; + shellHook = let + justFile = '' + default: + @just --list + + @build: + nix build .#debug --offline + + @release: + nix build --offline + + @test: + printf "\\n\\n\\t************ running nix+dune tests ************\\n\\n\\n" + nix flake check --offline + nix build .#tests --offline + printf "\\n\\n\\t************ running visual test ************\\n\\n\\n" + echo one two three four | CULRS="(255,0,0);(0,0,255);#00FF00" CULR_ORDER="1;0;2" result/bin/culr + + @push: + git commit -a + git push + ''; + in '' + printf '${justFile}' > justfile + ''; }; packages.default = pkgs.callPackage ./nix/default.nix { @@ -86,8 +117,9 @@ // { nixosModules.meat = import ./nix/module.nix { meatOverlays = [ - self.overlays.meat + nixpkgs-oc.overlays.default nh-overlay + self.overlays.meat ]; lixModule = lix-module; }; @@ -95,7 +127,7 @@ overlays.meat = final: prev: let ocaml-deps = let inherit - (prev.ocamlPackages) + (final.ocamlPackages) dune_3 ocaml ; From ad43326a4306c664216123bb59e9e2a4101fe0bf Mon Sep 17 00:00:00 2001 From: atagen Date: Fri, 6 Dec 2024 15:24:02 +1100 Subject: [PATCH 26/44] remove superfluous tests --- flake.nix | 3 --- 1 file changed, 3 deletions(-) diff --git a/flake.nix b/flake.nix index 1732604..539578a 100644 --- a/flake.nix +++ b/flake.nix @@ -93,9 +93,6 @@ @test: printf "\\n\\n\\t************ running nix+dune tests ************\\n\\n\\n" nix flake check --offline - nix build .#tests --offline - printf "\\n\\n\\t************ running visual test ************\\n\\n\\n" - echo one two three four | CULRS="(255,0,0);(0,0,255);#00FF00" CULR_ORDER="1;0;2" result/bin/culr @push: git commit -a From 4490c67de91381eeb258703fa24215fc5a900c3b Mon Sep 17 00:00:00 2001 From: atagen Date: Fri, 6 Dec 2024 15:24:19 +1100 Subject: [PATCH 27/44] downgrade dune ver --- meat.opam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meat.opam b/meat.opam index fe4df60..f89d30f 100644 --- a/meat.opam +++ b/meat.opam @@ -11,7 +11,7 @@ doc: "https://url/to/documentation" bug-reports: "https://github.com/username/reponame/issues" depends: [ "ocaml" - "dune" {>= "3.17"} + "dune" {>= "3.16"} "odoc" {with-doc} ] build: [ From 4bc3176ce656beeae0e52a220bdd1b260bdebf14 Mon Sep 17 00:00:00 2001 From: atagen Date: Thu, 12 Dec 2024 12:31:04 +1100 Subject: [PATCH 28/44] use nixpkgs input and ocaml overlay --- flake.lock | 53 +++++++++++++++++++++++++++++++++++------------------ flake.nix | 17 ++++++++++------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/flake.lock b/flake.lock index 8ab77d7..efe68e5 100644 --- a/flake.lock +++ b/flake.lock @@ -73,7 +73,7 @@ "lix" ], "nixpkgs": [ - "nixpkgs-oc" + "ocaml-overlay" ] }, "locked": { @@ -122,37 +122,53 @@ "type": "github" } }, - "nixpkgs-oc": { - "inputs": { - "nixpkgs": "nixpkgs_2" - }, + "nixpkgs_2": { "locked": { - "lastModified": 1733437725, - "narHash": "sha256-ridu0NcO4Dr2TsHqPE+kh58xTHcXg7IHq/FF74KrP/g=", - "owner": "nix-ocaml", - "repo": "nix-overlays", - "rev": "03b85ffd6c37255829d475f3584f8d8a1556d5f2", + "lastModified": 1733749988, + "narHash": "sha256-+5qdtgXceqhK5ZR1YbP1fAUsweBIrhL38726oIEAtDs=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "bc27f0fde01ce4e1bfec1ab122d72b7380278e68", "type": "github" }, "original": { - "owner": "nix-ocaml", - "repo": "nix-overlays", + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", "type": "github" } }, - "nixpkgs_2": { + "nixpkgs_3": { "locked": { - "lastModified": 1733380312, - "narHash": "sha256-ywntxT10Om755wkB9tYgJwEwELQZKYAO5WcNuHv1vjI=", + "lastModified": 1733838633, + "narHash": "sha256-51x/FRiqMGQMyP+aSTp5b36WxsvT7q9KYtW2f+7+HoI=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "a772498086eac57d97065a980a21fc0f304e3192", + "rev": "cdb5bd9f4fe066d1726cd848ad5858eb36a2ca93", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "a772498086eac57d97065a980a21fc0f304e3192", + "rev": "cdb5bd9f4fe066d1726cd848ad5858eb36a2ca93", + "type": "github" + } + }, + "ocaml-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1733872709, + "narHash": "sha256-CSjVHftyEGmkDeheoWDjQECIrgASNy8FNc0fqIFvcwM=", + "owner": "nix-ocaml", + "repo": "nix-overlays", + "rev": "8a82971570aafb4233340ef429ba672fd780b5ac", + "type": "github" + }, + "original": { + "owner": "nix-ocaml", + "repo": "nix-overlays", "type": "github" } }, @@ -162,7 +178,8 @@ "lix": "lix", "lix-module": "lix-module", "nh": "nh", - "nixpkgs-oc": "nixpkgs-oc" + "nixpkgs": "nixpkgs_2", + "ocaml-overlay": "ocaml-overlay" } }, "systems": { diff --git a/flake.nix b/flake.nix index 539578a..6cef530 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,8 @@ { inputs = { - nixpkgs-oc.url = "github:nix-ocaml/nix-overlays"; + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + + ocaml-overlay.url = "github:nix-ocaml/nix-overlays"; flake-utils.url = "github:numtide/flake-utils"; @@ -13,7 +15,7 @@ lix-module = { url = "https://git.lix.systems/lix-project/nixos-module/archive/main.tar.gz"; - inputs.nixpkgs.follows = "nixpkgs-oc"; + inputs.nixpkgs.follows = "ocaml-overlay"; inputs.lix.follows = "lix"; }; }; @@ -25,11 +27,12 @@ outputs = inputs @ { self, - nixpkgs-oc, + nixpkgs, + ocaml-overlay, flake-utils, ... }: let - inherit (inputs) nixpkgs-oc; + inherit (inputs) ocaml-overlay; lix-overlay = inputs.lix-module.overlays.default; lix-module = inputs.lix-module.nixosModules.default; nh-overlay = inputs.nh.overlays.default; @@ -37,12 +40,12 @@ in flake-utils.lib.eachDefaultSystem ( system: let - pkgs = import nixpkgs-oc { + pkgs = import nixpkgs { inherit system; overlays = [ lix-overlay nh-overlay - nixpkgs-oc.overlays.default + ocaml-overlay.overlays.default ]; modules = [lix-module]; extra-substituters = "https://anmonteiro.nix-cache.workers.dev"; @@ -114,7 +117,7 @@ // { nixosModules.meat = import ./nix/module.nix { meatOverlays = [ - nixpkgs-oc.overlays.default + ocaml-overlay.overlays.default nh-overlay self.overlays.meat ]; From ec00841899f560fcf1a8854a4dc4442490f1c40b Mon Sep 17 00:00:00 2001 From: atagen Date: Sat, 14 Dec 2024 18:31:15 +1100 Subject: [PATCH 29/44] overlay fixed, update --- flake.lock | 26 ++++++-------------------- flake.nix | 7 +++++-- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/flake.lock b/flake.lock index efe68e5..35b2aa7 100644 --- a/flake.lock +++ b/flake.lock @@ -138,32 +138,18 @@ "type": "github" } }, - "nixpkgs_3": { - "locked": { - "lastModified": 1733838633, - "narHash": "sha256-51x/FRiqMGQMyP+aSTp5b36WxsvT7q9KYtW2f+7+HoI=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "cdb5bd9f4fe066d1726cd848ad5858eb36a2ca93", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "cdb5bd9f4fe066d1726cd848ad5858eb36a2ca93", - "type": "github" - } - }, "ocaml-overlay": { "inputs": { - "nixpkgs": "nixpkgs_3" + "nixpkgs": [ + "nixpkgs" + ] }, "locked": { - "lastModified": 1733872709, - "narHash": "sha256-CSjVHftyEGmkDeheoWDjQECIrgASNy8FNc0fqIFvcwM=", + "lastModified": 1734156418, + "narHash": "sha256-7I6hKojqDm0Z+q9ZvDk8R5J/TfoPbprmVquwfQIzQrg=", "owner": "nix-ocaml", "repo": "nix-overlays", - "rev": "8a82971570aafb4233340ef429ba672fd780b5ac", + "rev": "3bd751c1d602713195432d4818b35d29c4b1dccc", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 6cef530..f1c5cec 100644 --- a/flake.nix +++ b/flake.nix @@ -2,8 +2,11 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; - ocaml-overlay.url = "github:nix-ocaml/nix-overlays"; - + ocaml-overlay = { + url = "github:nix-ocaml/nix-overlays"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-utils.url = "github:numtide/flake-utils"; nh.url = "github:viperML/nh"; From 56d0dc028fae61803fd7a3d25e8f87ee3b28ed10 Mon Sep 17 00:00:00 2001 From: atagen Date: Sat, 8 Feb 2025 11:00:56 +1100 Subject: [PATCH 30/44] remove ocaml overlay --- .gitignore | 3 +- flake.lock | 25 +------- flake.nix | 173 +++++++++++++++++++++++++++-------------------------- 3 files changed, 92 insertions(+), 109 deletions(-) diff --git a/.gitignore b/.gitignore index 802d42f..9a62042 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ _build .direnv/ result -justfile \ No newline at end of file +justfile +todo diff --git a/flake.lock b/flake.lock index 35b2aa7..9a8a4cf 100644 --- a/flake.lock +++ b/flake.lock @@ -73,7 +73,7 @@ "lix" ], "nixpkgs": [ - "ocaml-overlay" + "nixpkgs" ] }, "locked": { @@ -138,34 +138,13 @@ "type": "github" } }, - "ocaml-overlay": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1734156418, - "narHash": "sha256-7I6hKojqDm0Z+q9ZvDk8R5J/TfoPbprmVquwfQIzQrg=", - "owner": "nix-ocaml", - "repo": "nix-overlays", - "rev": "3bd751c1d602713195432d4818b35d29c4b1dccc", - "type": "github" - }, - "original": { - "owner": "nix-ocaml", - "repo": "nix-overlays", - "type": "github" - } - }, "root": { "inputs": { "flake-utils": "flake-utils", "lix": "lix", "lix-module": "lix-module", "nh": "nh", - "nixpkgs": "nixpkgs_2", - "ocaml-overlay": "ocaml-overlay" + "nixpkgs": "nixpkgs_2" } }, "systems": { diff --git a/flake.nix b/flake.nix index f1c5cec..020bbe4 100644 --- a/flake.nix +++ b/flake.nix @@ -2,11 +2,6 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; - ocaml-overlay = { - url = "github:nix-ocaml/nix-overlays"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - flake-utils.url = "github:numtide/flake-utils"; nh.url = "github:viperML/nh"; @@ -18,95 +13,100 @@ lix-module = { url = "https://git.lix.systems/lix-project/nixos-module/archive/main.tar.gz"; - inputs.nixpkgs.follows = "ocaml-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; inputs.lix.follows = "lix"; }; }; - nixConfig = { - extra-substituters = "https://anmonteiro.nix-cache.workers.dev"; - extra-trusted-public-keys = "ocaml.nix-cache.com-1:/xI2h2+56rwFfKyyFVbkJSeGqSIYMC/Je+7XXqGKDIY="; - }; - - outputs = inputs @ { - self, - nixpkgs, - ocaml-overlay, - flake-utils, - ... - }: let - inherit (inputs) ocaml-overlay; - lix-overlay = inputs.lix-module.overlays.default; - lix-module = inputs.lix-module.nixosModules.default; - nh-overlay = inputs.nh.overlays.default; - version = builtins.toString self.lastModified; - in + outputs = + inputs@{ + self, + nixpkgs, + flake-utils, + ... + }: + let + lix-overlay = inputs.lix-module.overlays.default; + lix-module = inputs.lix-module.nixosModules.default; + nh-overlay = inputs.nh.overlays.default; + version = builtins.toString self.lastModified; + in flake-utils.lib.eachDefaultSystem ( - system: let + system: + let pkgs = import nixpkgs { inherit system; overlays = [ lix-overlay nh-overlay - ocaml-overlay.overlays.default ]; - modules = [lix-module]; - extra-substituters = "https://anmonteiro.nix-cache.workers.dev"; - extra-trusted-public-keys = "ocaml.nix-cache.com-1:/xI2h2+56rwFfKyyFVbkJSeGqSIYMC/Je+7XXqGKDIY="; + modules = [ lix-module ]; }; - minimal = let - inherit - (pkgs.ocamlPackages) + minimal = + let + inherit (pkgs.ocamlPackages) + dune_3 + ocaml + ; + in + [ dune_3 ocaml - ; - in [ - dune_3 - ocaml - ]; - dev = let - inherit - (pkgs.ocamlPackages) + ]; + dev = + let + inherit (pkgs.ocamlPackages) + utop + ocaml-lsp + ocamlformat + ocamlformat-rpc-lib + ; + in + [ utop ocaml-lsp ocamlformat ocamlformat-rpc-lib - ; - in [ - utop - ocaml-lsp - ocamlformat - ocamlformat-rpc-lib - ]; + ]; inherit (pkgs) lix nh; - in { - devShells.default = let - inherit (pkgs) mkShell; - in + in + { + devShells.default = + let + inherit (pkgs) mkShell; + in mkShell { - buildInputs = minimal ++ dev ++ [lix nh]; - shellHook = let - justFile = '' - default: - @just --list + buildInputs = + minimal + ++ dev + ++ [ + lix + nh + ]; + shellHook = + let + justFile = '' + default: + @just --list - @build: - nix build .#debug --offline + @build: + nix build .#debug --offline - @release: - nix build --offline + @release: + nix build --offline - @test: - printf "\\n\\n\\t************ running nix+dune tests ************\\n\\n\\n" - nix flake check --offline + @test: + printf "\\n\\n\\t************ running nix+dune tests ************\\n\\n\\n" + nix flake check --offline - @push: - git commit -a - git push + @push: + git commit -a + git push + ''; + in + '' + printf '${justFile}' > justfile ''; - in '' - printf '${justFile}' > justfile - ''; }; packages.default = pkgs.callPackage ./nix/default.nix { @@ -120,28 +120,31 @@ // { nixosModules.meat = import ./nix/module.nix { meatOverlays = [ - ocaml-overlay.overlays.default nh-overlay self.overlays.meat ]; lixModule = lix-module; }; - overlays.meat = final: prev: let - ocaml-deps = let - inherit - (final.ocamlPackages) - dune_3 - ocaml - ; - in [ - dune_3 - ocaml - ]; - in { - meat = final.callPackage ./nix/default.nix { - inherit ocaml-deps version; + overlays.meat = + final: prev: + let + ocaml-deps = + let + inherit (final.ocamlPackages) + dune_3 + ocaml + ; + in + [ + dune_3 + ocaml + ]; + in + { + meat = final.callPackage ./nix/default.nix { + inherit ocaml-deps version; + }; }; - }; }; } From 1a2ca2dcbdadd9f0cce88bf5c2f0e5da95d530bc Mon Sep 17 00:00:00 2001 From: atagen Date: Fri, 20 Jun 2025 12:54:21 +1000 Subject: [PATCH 31/44] remove reliance on nh for most things --- bin/main.ml | 4 +- flake.lock | 220 ++++++++++++++++++++------------------------ flake.nix | 190 +++++++++++++------------------------- lib/meat.ml | 77 +++++++++------- nix/default.nix | 6 +- nix/meat-module.nix | 30 ------ nix/module.nix | 33 ++++++- 7 files changed, 242 insertions(+), 318 deletions(-) delete mode 100644 nix/meat-module.nix diff --git a/bin/main.ml b/bin/main.ml index 3023220..7c40538 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,7 +1,7 @@ open Meat let () = - match Sys.getenv_opt "NH_FLAKE" with + match Sys.getenv_opt "MEATS" with | Some _ -> if Array.length Sys.argv >= 2 then match String.lowercase_ascii (Array.get Sys.argv 1) with @@ -9,7 +9,7 @@ let () = | "cook" -> cook () | "poke" -> poke () | "gut" -> gut () - | "look" -> look () + (* | "look" -> look () *) | "fresh" -> fresh () | _ -> help () else help () diff --git a/flake.lock b/flake.lock index 9a8a4cf..2964faf 100644 --- a/flake.lock +++ b/flake.lock @@ -1,134 +1,127 @@ { "nodes": { - "flake-utils": { + "flake-compat": { + "locked": { + "lastModified": 1733328505, + "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { "inputs": { - "systems": "systems" + "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "lastModified": 1743550720, + "narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "c621e8422220273271f52058f618c94e405bb0f5", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "hercules-ci", + "repo": "flake-parts", "type": "github" } }, - "flake-utils_2": { + "ndg": { "inputs": { - "systems": "systems_2" + "flake-compat": "flake-compat", + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "lastModified": 1748103964, + "narHash": "sha256-aRFl6I3x1aKzeOBaD/OJHYv+OQ+qE+3FR9uKhIvfW+A=", + "owner": "feel-co", + "repo": "ndg", + "rev": "c556c4cbcba61474bf8a342a31a2d94cbefd8986", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "feel-co", + "repo": "ndg", "type": "github" } }, - "flakey-profile": { + "nix-systems": { "locked": { - "lastModified": 1712898590, - "narHash": "sha256-FhGIEU93VHAChKEXx905TSiPZKga69bWl1VB37FK//I=", - "owner": "lf-", - "repo": "flakey-profile", - "rev": "243c903fd8eadc0f63d205665a92d4df91d42d9d", + "lastModified": 1689347949, + "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", + "owner": "nix-systems", + "repo": "default-linux", + "rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68", "type": "github" }, "original": { - "owner": "lf-", - "repo": "flakey-profile", - "type": "github" - } - }, - "lix": { - "flake": false, - "locked": { - "lastModified": 1732112222, - "narHash": "sha256-H7GN4++a4vE49SUNojZx+FSk4mmpb2ifJUtJMJHProI=", - "rev": "66f6dbda32959dd5cf3a9aaba15af72d037ab7ff", - "type": "tarball", - "url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/66f6dbda32959dd5cf3a9aaba15af72d037ab7ff.tar.gz?rev=66f6dbda32959dd5cf3a9aaba15af72d037ab7ff" - }, - "original": { - "type": "tarball", - "url": "https://git.lix.systems/lix-project/lix/archive/main.tar.gz" - } - }, - "lix-module": { - "inputs": { - "flake-utils": "flake-utils_2", - "flakey-profile": "flakey-profile", - "lix": [ - "lix" - ], - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1731967274, - "narHash": "sha256-n6dPGRlMGdL8X5gviA6ZuRfUdbdD5KiNN/BpABA5YT0=", - "rev": "aa2846680fa9a2032939d720487942567fd9eb63", - "type": "tarball", - "url": "https://git.lix.systems/api/v1/repos/lix-project/nixos-module/archive/aa2846680fa9a2032939d720487942567fd9eb63.tar.gz?rev=aa2846680fa9a2032939d720487942567fd9eb63" - }, - "original": { - "type": "tarball", - "url": "https://git.lix.systems/lix-project/nixos-module/archive/main.tar.gz" - } - }, - "nh": { - "inputs": { - "nixpkgs": "nixpkgs" - }, - "locked": { - "lastModified": 1732089528, - "narHash": "sha256-+yXeJiSFn96pW6H/50DfCfZiOLSfZNGhK7R4f0aUvGY=", - "owner": "viperML", - "repo": "nh", - "rev": "cff51af0ebb09227070b0332c598c7a4b7f8175a", - "type": "github" - }, - "original": { - "owner": "viperML", - "repo": "nh", + "owner": "nix-systems", + "repo": "default-linux", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1731386116, - "narHash": "sha256-lKA770aUmjPHdTaJWnP3yQ9OI1TigenUqVC3wweqZuI=", - "owner": "NixOS", + "lastModified": 1748217807, + "narHash": "sha256-P3u2PXxMlo49PutQLnk2PhI/imC69hFl1yY4aT5Nax8=", + "owner": "nixos", "repo": "nixpkgs", - "rev": "689fed12a013f56d4c4d3f612489634267d86529", + "rev": "3108eaa516ae22c2360928589731a4f1581526ef", "type": "github" }, "original": { - "owner": "NixOS", - "ref": "nixos-24.05", + "owner": "nixos", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1743296961, + "narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, "nixpkgs_2": { "locked": { - "lastModified": 1733749988, - "narHash": "sha256-+5qdtgXceqhK5ZR1YbP1fAUsweBIrhL38726oIEAtDs=", + "lastModified": 1745930157, + "narHash": "sha256-y3h3NLnzRSiUkYpnfvnS669zWZLoqqI6NprtLQ+5dck=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "46e634be05ce9dc6d4db8e664515ba10b78151ae", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1748217807, + "narHash": "sha256-P3u2PXxMlo49PutQLnk2PhI/imC69hFl1yY4aT5Nax8=", "owner": "nixos", "repo": "nixpkgs", - "rev": "bc27f0fde01ce4e1bfec1ab122d72b7380278e68", + "rev": "3108eaa516ae22c2360928589731a4f1581526ef", "type": "github" }, "original": { @@ -140,41 +133,28 @@ }, "root": { "inputs": { - "flake-utils": "flake-utils", - "lix": "lix", - "lix-module": "lix-module", - "nh": "nh", - "nixpkgs": "nixpkgs_2" + "nix-systems": "nix-systems", + "nixpkgs": "nixpkgs", + "unf": "unf" } }, - "systems": { + "unf": { + "inputs": { + "ndg": "ndg", + "nixpkgs": "nixpkgs_3" + }, "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" + "lastModified": 1748163740, + "narHash": "sha256-WOK9w5gtdpy4RefaiRtr6YqFaPxR0OrmI2PleZnn4O4=", + "ref": "refs/heads/main", + "rev": "4d711e5002bd22adbe6d786560be0fde6cbcf81e", + "revCount": 1, + "type": "git", + "url": "https://git.atagen.co/atagen/unf" }, "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "systems_2": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" + "type": "git", + "url": "https://git.atagen.co/atagen/unf" } } }, diff --git a/flake.nix b/flake.nix index 020bbe4..2288a2c 100644 --- a/flake.nix +++ b/flake.nix @@ -1,150 +1,88 @@ { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; - - flake-utils.url = "github:numtide/flake-utils"; - - nh.url = "github:viperML/nh"; - - lix = { - url = "https://git.lix.systems/lix-project/lix/archive/main.tar.gz"; - flake = false; - }; - - lix-module = { - url = "https://git.lix.systems/lix-project/nixos-module/archive/main.tar.gz"; - inputs.nixpkgs.follows = "nixpkgs"; - inputs.lix.follows = "lix"; - }; + nix-systems.url = "github:nix-systems/default-linux"; + unf.url = "git+https://git.atagen.co/atagen/unf"; }; outputs = - inputs@{ - self, - nixpkgs, - flake-utils, - ... - }: + inputs: + with inputs; let - lix-overlay = inputs.lix-module.overlays.default; - lix-module = inputs.lix-module.nixosModules.default; - nh-overlay = inputs.nh.overlays.default; version = builtins.toString self.lastModified; - in - flake-utils.lib.eachDefaultSystem ( - system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [ - lix-overlay - nh-overlay - ]; - modules = [ lix-module ]; - }; - minimal = - let - inherit (pkgs.ocamlPackages) - dune_3 - ocaml - ; - in - [ + collectPkgs = builtins.attrValues; + forEachSystem = + function: + nixpkgs.lib.genAttrs (import nix-systems) (system: function nixpkgs.legacyPackages.${system}); + deps = forEachSystem (pkgs: { + build = collectPkgs { + inherit (pkgs.ocamlPackages) dune_3 ocaml - ]; - dev = - let - inherit (pkgs.ocamlPackages) - utop - ocaml-lsp - ocamlformat - ocamlformat-rpc-lib - ; - in - [ + ; + }; + dev = collectPkgs { + inherit (pkgs.ocamlPackages) utop ocaml-lsp ocamlformat ocamlformat-rpc-lib - ]; - inherit (pkgs) lix nh; - in - { - devShells.default = - let - inherit (pkgs) mkShell; - in - mkShell { - buildInputs = - minimal - ++ dev - ++ [ - lix - nh - ]; - shellHook = - let - justFile = '' - default: - @just --list + ; + }; + }); + in + { + devShells = forEachSystem (pkgs: { + default = pkgs.mkShell { + packages = pkgs.lib.mapAttrsToList (_: v: v) deps.${pkgs.system}; + shellHook = + let + justFile = '' + default: + @just --list - @build: - nix build .#debug --offline + @build: + nix build .#debug --offline - @release: - nix build --offline + @release: + nix build --offline - @test: - printf "\\n\\n\\t************ running nix+dune tests ************\\n\\n\\n" - nix flake check --offline - - @push: - git commit -a - git push - ''; - in - '' - printf '${justFile}' > justfile + @test: + printf "\\n\\n\\t************ running nix+dune tests ************\\n\\n\\n" + nix flake check --offline ''; - }; + in + '' + printf '${justFile}' > justfile + ''; + }; + }); - packages.default = pkgs.callPackage ./nix/default.nix { - ocaml-deps = minimal; + packages = forEachSystem (pkgs: { + default = pkgs.callPackage ./nix/default.nix { + buildInputs = deps.${pkgs.system}.build; inherit version; }; - - defaultPackage = self.packages.${system}.default; - } - ) - // { - nixosModules.meat = import ./nix/module.nix { - meatOverlays = [ - nh-overlay - self.overlays.meat - ]; - lixModule = lix-module; - }; - - overlays.meat = - final: prev: - let - ocaml-deps = - let - inherit (final.ocamlPackages) - dune_3 - ocaml - ; - in - [ - dune_3 - ocaml - ]; - in - { - meat = final.callPackage ./nix/default.nix { - inherit ocaml-deps version; - }; + docs = pkgs.callPackage unf.lib.pak-chooie { + inherit self; + projectName = "meat"; + newPath = "https://git.atagen.co/atagen/meat/src"; + modules = [ + self.nixosModules.meat + ]; }; + }); + + nixosModules.meat = + { + pkgs, + lib, + ... + }: + { + imports = [ ./nix/module.nix ]; + programs.meat.package = self.packages.${pkgs.system}.default; + }; + }; } diff --git a/lib/meat.ml b/lib/meat.ml index 188a176..47096ae 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -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 () diff --git a/nix/default.nix b/nix/default.nix index c1317fe..f5274ad 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,6 +1,6 @@ { ocamlPackages, - ocaml-deps, + buildInputs, git, version, ... @@ -12,6 +12,6 @@ ocamlPackages.buildDunePackage { minimalOCamlVersion = "5.2"; src = ./..; - nativeBuildInputs = [git]; - buildInputs = ocaml-deps; + nativeBuildInputs = [ git ]; + inherit buildInputs; } diff --git a/nix/meat-module.nix b/nix/meat-module.nix deleted file mode 100644 index 9241d68..0000000 --- a/nix/meat-module.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ - pkgs, - lib, - config, - ... -}: let - inherit (lib) mkEnableOption mkOption types; - cfg = config.programs.meat; -in { - options.programs.meat = { - enable = mkEnableOption "meat"; - flake = mkOption { - type = with types; nullOr (either path str); - default = null; - description = "path to your system flake"; - }; - }; - config = let - inherit (pkgs) meat nh lix; - in - lib.mkIf - cfg.enable - { - environment.systemPackages = [meat nh lix]; - environment.sessionVariables.NH_FLAKE = - if (cfg.flake == null) - then abort "Please set the programs.meat.flake option to your system flake." - else config.programs.meat.flake; - }; -} diff --git a/nix/module.nix b/nix/module.nix index d30769b..b9248c4 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -1,7 +1,30 @@ { - meatOverlays, - lixModule, -}: { - imports = [./meat-module.nix lixModule]; - nixpkgs.overlays = meatOverlays; + pkgs, + lib, + config, + ... +}: +let + inherit (lib) mkEnableOption mkOption types; + cfg = config.programs.meat; +in +{ + options.programs.meat = { + enable = mkEnableOption "meat"; + flake = mkOption { + type = with types; either path str; + description = "path to your system flake"; + }; + package = mkOption { + type = types.package; + description = "your ideal meat"; + }; + }; + config = lib.mkIf cfg.enable { + environment.sessionVariables.MEATS = cfg.flake; + environment.systemPackages = [ + cfg.package + pkgs.nh # for now.. + ]; + }; } From a1a0b134ad975893ab54ada381cf661211a9c3c3 Mon Sep 17 00:00:00 2001 From: atagen Date: Wed, 25 Jun 2025 16:37:35 +1000 Subject: [PATCH 32/44] format + add missing profile cmd --- lib/meat.ml | 70 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/lib/meat.ml b/lib/meat.ml index 47096ae..93095e4 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -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 () From c8978534dc297e108c5fd214f3704421dfda97de Mon Sep 17 00:00:00 2001 From: atagen Date: Thu, 26 Jun 2025 23:40:43 +1000 Subject: [PATCH 33/44] simplify yum command --- lib/meat.ml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/meat.ml b/lib/meat.ml index 93095e4..7ef5165 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -39,15 +39,9 @@ let do_build () = Unix.getenv "MEATS" ^ "#nixosConfigurations." ^ Unix.gethostname () ^ ".config.system.build.toplevel" in - do_cmd @@ "nix build --out-link " ^ tmpdir ^ "/build " ^ build_target + do_cmd @@ "sudo nix build --profile /nix/var/nix/profiles/system --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 () = @@ -55,9 +49,8 @@ let yum () = meat_print "CONSUMING DELICIOUS MEATS.."; do_build () |> function | Error _ -> - print_string "FAILED TO CONSUME MEATS"; - print_string footer - | _ -> print_string footer + print_string "FAILED TO CONSUME MEATS."; + | _ -> (); print_string footer let cook () = print_string header; From 8ba7d1cbaba7ec08efd24cf05f2f283ab10b6855 Mon Sep 17 00:00:00 2001 From: atagen Date: Thu, 26 Jun 2025 23:57:52 +1000 Subject: [PATCH 34/44] ci: create workflow --- .gitea/workflows/nix.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .gitea/workflows/nix.yaml diff --git a/.gitea/workflows/nix.yaml b/.gitea/workflows/nix.yaml new file mode 100644 index 0000000..d5443ef --- /dev/null +++ b/.gitea/workflows/nix.yaml @@ -0,0 +1,11 @@ +name: Nix Build +on: [push] + +jobs: + all-in-one: + runs-on: [native] + name: nix build + steps: + - uses: actions/checkout@v4 + - run: nix build --no-link . + From 51d501a68e2f6c11460733bffb590056edbfec11 Mon Sep 17 00:00:00 2001 From: atagen Date: Thu, 10 Jul 2025 23:20:25 +1000 Subject: [PATCH 35/44] fix sudo placement, always print footer --- lib/meat.ml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/meat.ml b/lib/meat.ml index 7ef5165..04346aa 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -39,7 +39,10 @@ let do_build () = Unix.getenv "MEATS" ^ "#nixosConfigurations." ^ Unix.gethostname () ^ ".config.system.build.toplevel" in - do_cmd @@ "sudo nix build --profile /nix/var/nix/profiles/system --out-link " ^ tmpdir ^ "/build " ^ build_target + do_cmd @@ "nix build --out-link " ^ tmpdir ^ "/build " ^ build_target + >>= fun () -> + do_cmd @@ "sudo nix-env --set -p /nix/var/nix/profiles/system " ^ tmpdir + ^ "/build" >>= fun () -> do_cmd @@ "sudo " ^ tmpdir ^ "/build/bin/switch-to-configuration switch" >|= fun () -> Unix.unlink @@ tmpdir ^ "/build" @@ -47,10 +50,10 @@ let do_build () = let yum () = print_string header; meat_print "CONSUMING DELICIOUS MEATS.."; - do_build () |> function - | Error _ -> - print_string "FAILED TO CONSUME MEATS."; - | _ -> (); print_string footer + ( do_build () |> function + | Error _ -> print_string "FAILED TO CONSUME MEATS." + | _ -> () ); + print_string footer let cook () = print_string header; From 6b4a286da4884242b6a62e4cd0c9f95bba0b3721 Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 20 Jul 2025 15:36:43 +1000 Subject: [PATCH 36/44] use nom and nix-build --- lib/meat.ml | 7 ++++--- nix/module.nix | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/meat.ml b/lib/meat.ml index 04346aa..867784e 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -36,10 +36,11 @@ let do_build () = 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" + Unix.getenv "MEATS" ^ "/entry.nix -A nixosConfigurations." + ^ Unix.gethostname () ^ ".config.system.build.toplevel" in - do_cmd @@ "nix build --out-link " ^ tmpdir ^ "/build " ^ build_target + do_cmd @@ "nix-build --log-format internal-json -v --out-link " ^ tmpdir + ^ "/build " ^ build_target ^ " |& nom --json" >>= fun () -> do_cmd @@ "sudo nix-env --set -p /nix/var/nix/profiles/system " ^ tmpdir ^ "/build" diff --git a/nix/module.nix b/nix/module.nix index b9248c4..21e1d2e 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -25,6 +25,7 @@ in environment.systemPackages = [ cfg.package pkgs.nh # for now.. + pkgs.nix-output-monitor ]; }; } From de951b227223ee924c37c7aa282bade34686bf83 Mon Sep 17 00:00:00 2001 From: atagen Date: Mon, 21 Jul 2025 10:57:30 +1000 Subject: [PATCH 37/44] fix poke --- lib/meat.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/meat.ml b/lib/meat.ml index 867784e..79f0d1f 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -73,7 +73,7 @@ let poke () = Unix.getenv "MEATS" ^ "#nixosConfigurations." ^ Unix.gethostname () ^ ".config.system.build.toplevel" in - do_cmd @@ "nix build --no-link" ^ build_target ^ " --show-trace" |> ignore; + do_cmd @@ "nix build --no-link " ^ build_target ^ " --show-trace" |> ignore; print_string footer let gut () = From fafee12becfb49c2f77eb8fb6283050bd2fc04d9 Mon Sep 17 00:00:00 2001 From: atagen Date: Mon, 11 Aug 2025 14:14:39 +1000 Subject: [PATCH 38/44] add dix --- lib/meat.ml | 1 + nix/module.nix | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/meat.ml b/lib/meat.ml index 79f0d1f..ddf6b62 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -41,6 +41,7 @@ let do_build () = 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" diff --git a/nix/module.nix b/nix/module.nix index 21e1d2e..a45e9ef 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -26,6 +26,7 @@ in cfg.package pkgs.nh # for now.. pkgs.nix-output-monitor + pkgs.dix ]; }; } From 07776960903da8567ea365fde5bdd461ba5b4cc5 Mon Sep 17 00:00:00 2001 From: atagen Date: Mon, 15 Sep 2025 10:29:54 +1000 Subject: [PATCH 39/44] readme --- README.md | 1 + bin/main.ml | 1 + lib/meat.ml | 14 ++++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..a13e7e8 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +this is chopped dont look at it diff --git a/bin/main.ml b/bin/main.ml index 7c40538..0e465e8 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -9,6 +9,7 @@ let () = | "cook" -> cook () | "poke" -> poke () | "gut" -> gut () + | "trade" -> trade () (* | "look" -> look () *) | "fresh" -> fresh () | _ -> help () diff --git a/lib/meat.ml b/lib/meat.ml index ddf6b62..9a17705 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -8,6 +8,7 @@ let help = POKE - TASTE SUSPICIOUS MEATS GUT - CLEAN MEAT STORES FRESH - HUNT FRESH MEATS + TRADE - SEND MEATS FAR AWAY ..-A - ..ALL MEATS|} (* \tLOOK - LOOK FOR FRESHER MEATS *) @@ -49,6 +50,19 @@ let do_build () = do_cmd @@ "sudo " ^ tmpdir ^ "/build/bin/switch-to-configuration switch" >|= fun () -> Unix.unlink @@ tmpdir ^ "/build" +let do_remote () = + meat_print "tbd"; + Ok () + +let trade () = + print_string header; + meat_print "TRADING FOREIGN MEATS.."; + do_remote () |> function + | Error _ -> print_string "FAILED TO TRADE MEATS." + | _ -> + (); + print_string footer + let yum () = print_string header; meat_print "CONSUMING DELICIOUS MEATS.."; From 0fc93545ce334099b8ced66c5eb8533273bc4cb8 Mon Sep 17 00:00:00 2001 From: atagen Date: Thu, 29 Jan 2026 16:18:32 +1100 Subject: [PATCH 40/44] satisfy nixpkgs pedantry --- flake.nix | 114 +++++++++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 53 deletions(-) diff --git a/flake.nix b/flake.nix index 2288a2c..964647b 100644 --- a/flake.nix +++ b/flake.nix @@ -13,65 +13,73 @@ collectPkgs = builtins.attrValues; forEachSystem = function: - nixpkgs.lib.genAttrs (import nix-systems) (system: function nixpkgs.legacyPackages.${system}); - deps = forEachSystem (pkgs: { - build = collectPkgs { - inherit (pkgs.ocamlPackages) - dune_3 - ocaml - ; - }; - dev = collectPkgs { - inherit (pkgs.ocamlPackages) - utop - ocaml-lsp - ocamlformat - ocamlformat-rpc-lib - ; - }; - }); + nixpkgs.lib.genAttrs (import nix-systems) ( + system: function nixpkgs.legacyPackages.${system} system + ); + deps = forEachSystem ( + pkgs: _: { + build = collectPkgs { + inherit (pkgs.ocamlPackages) + dune_3 + ocaml + ; + }; + dev = collectPkgs { + inherit (pkgs.ocamlPackages) + utop + ocaml-lsp + ocamlformat + ocamlformat-rpc-lib + ; + }; + } + ); in { - devShells = forEachSystem (pkgs: { - default = pkgs.mkShell { - packages = pkgs.lib.mapAttrsToList (_: v: v) deps.${pkgs.system}; - shellHook = - let - justFile = '' - default: - @just --list + devShells = forEachSystem ( + pkgs: sys: { + default = pkgs.mkShell { + packages = pkgs.lib.mapAttrsToList (_: v: v) deps.${sys}; + shellHook = + let + justFile = '' + default: + @just --list - @build: - nix build .#debug --offline + @build: + nix build .#debug --offline - @release: - nix build --offline + @release: + nix build --offline - @test: - printf "\\n\\n\\t************ running nix+dune tests ************\\n\\n\\n" - nix flake check --offline + @test: + printf "\\n\\n\\t************ running nix+dune tests ************\\n\\n\\n" + nix flake check --offline + ''; + in + '' + printf '${justFile}' > justfile ''; - in - '' - printf '${justFile}' > justfile - ''; - }; - }); + }; + } + ); - packages = forEachSystem (pkgs: { - default = pkgs.callPackage ./nix/default.nix { - buildInputs = deps.${pkgs.system}.build; - inherit version; - }; - docs = pkgs.callPackage unf.lib.pak-chooie { - inherit self; - projectName = "meat"; - newPath = "https://git.atagen.co/atagen/meat/src"; - modules = [ - self.nixosModules.meat - ]; - }; - }); + packages = forEachSystem ( + pkgs: sys: { + default = pkgs.callPackage ./nix/default.nix { + buildInputs = deps.${sys}.build; + inherit version; + }; + docs = pkgs.callPackage unf.lib.pak-chooie { + inherit self; + projectName = "meat"; + newPath = "https://git.atagen.co/atagen/meat/src"; + modules = [ + self.nixosModules.meat + ]; + }; + } + ); nixosModules.meat = { @@ -81,7 +89,7 @@ }: { imports = [ ./nix/module.nix ]; - programs.meat.package = self.packages.${pkgs.system}.default; + programs.meat.package = self.packages.${pkgs.stdenv.hostPlatform.system}.default; }; }; From 703ac28f52359142defffd7d0c43628e82bf0c8f Mon Sep 17 00:00:00 2001 From: atagen Date: Mon, 23 Mar 2026 22:38:28 +1100 Subject: [PATCH 41/44] refactor, hunt --- bin/main.ml | 3 +- flake.nix | 3 + lib/commands/cook.ml | 9 ++ lib/commands/fresh.ml | 17 ++++ lib/commands/gut.ml | 5 + lib/commands/help.ml | 1 + lib/commands/hunt.ml | 61 +++++++++++ lib/commands/look.ml | 114 +++++++++++++++++++++ lib/commands/poke.ml | 9 ++ lib/commands/trade.ml | 8 ++ lib/commands/yum.ml | 7 ++ lib/common.ml | 60 +++++++++++ lib/dune | 3 +- lib/http.ml | 232 ++++++++++++++++++++++++++++++++++++++++++ lib/json.ml | 8 ++ lib/meat.ml | 223 ++-------------------------------------- 16 files changed, 548 insertions(+), 215 deletions(-) create mode 100644 lib/commands/cook.ml create mode 100644 lib/commands/fresh.ml create mode 100644 lib/commands/gut.ml create mode 100644 lib/commands/help.ml create mode 100644 lib/commands/hunt.ml create mode 100644 lib/commands/look.ml create mode 100644 lib/commands/poke.ml create mode 100644 lib/commands/trade.ml create mode 100644 lib/commands/yum.ml create mode 100644 lib/common.ml create mode 100644 lib/http.ml create mode 100644 lib/json.ml diff --git a/bin/main.ml b/bin/main.ml index 0e465e8..6aa19f9 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -10,8 +10,9 @@ let () = | "poke" -> poke () | "gut" -> gut () | "trade" -> trade () - (* | "look" -> look () *) + | "look" -> look () | "fresh" -> fresh () + | "hunt" -> hunt () | _ -> help () else help () | None -> diff --git a/flake.nix b/flake.nix index 964647b..33d7c3a 100644 --- a/flake.nix +++ b/flake.nix @@ -22,7 +22,10 @@ inherit (pkgs.ocamlPackages) dune_3 ocaml + yojson + ssl ; + inherit (pkgs.openssl) dev; }; dev = collectPkgs { inherit (pkgs.ocamlPackages) diff --git a/lib/commands/cook.ml b/lib/commands/cook.ml new file mode 100644 index 0000000..4c79b1c --- /dev/null +++ b/lib/commands/cook.ml @@ -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 diff --git a/lib/commands/fresh.ml b/lib/commands/fresh.ml new file mode 100644 index 0000000..d4c4a52 --- /dev/null +++ b/lib/commands/fresh.ml @@ -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 () diff --git a/lib/commands/gut.ml b/lib/commands/gut.ml new file mode 100644 index 0000000..8a5594c --- /dev/null +++ b/lib/commands/gut.ml @@ -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 diff --git a/lib/commands/help.ml b/lib/commands/help.ml new file mode 100644 index 0000000..f29a0e7 --- /dev/null +++ b/lib/commands/help.ml @@ -0,0 +1 @@ +let run () = print_string (Common.header ^ Common.help_text ^ Common.footer ^ "\n") diff --git a/lib/commands/hunt.ml b/lib/commands/hunt.ml new file mode 100644 index 0000000..655feee --- /dev/null +++ b/lib/commands/hunt.ml @@ -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 diff --git a/lib/commands/look.ml b/lib/commands/look.ml new file mode 100644 index 0000000..c1df668 --- /dev/null +++ b/lib/commands/look.ml @@ -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 diff --git a/lib/commands/poke.ml b/lib/commands/poke.ml new file mode 100644 index 0000000..800e39d --- /dev/null +++ b/lib/commands/poke.ml @@ -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 diff --git a/lib/commands/trade.ml b/lib/commands/trade.ml new file mode 100644 index 0000000..80e6dfa --- /dev/null +++ b/lib/commands/trade.ml @@ -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 diff --git a/lib/commands/yum.ml b/lib/commands/yum.ml new file mode 100644 index 0000000..08514cc --- /dev/null +++ b/lib/commands/yum.ml @@ -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 diff --git a/lib/common.ml b/lib/common.ml new file mode 100644 index 0000000..c8a87b9 --- /dev/null +++ b/lib/common.ml @@ -0,0 +1,60 @@ +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) diff --git a/lib/dune b/lib/dune index 2b63e36..016c372 100644 --- a/lib/dune +++ b/lib/dune @@ -1,3 +1,4 @@ +(include_subdirs qualified) (library (name meat) - (libraries unix)) + (libraries unix ssl yojson)) diff --git a/lib/http.ml b/lib/http.ml new file mode 100644 index 0000000..f681505 --- /dev/null +++ b/lib/http.ml @@ -0,0 +1,232 @@ +let read_file path = + let ic = open_in path in + let n = in_channel_length ic in + let s = really_input_string ic n in + close_in ic; + s + +let contains_sub haystack needle = + let hl = String.length haystack and nl = String.length needle in + if nl > hl then false + else + let rec check i = + if i + nl > hl then false + else if String.sub haystack i nl = needle then true + else check (i + 1) + in + check 0 + +let decode_chunked body = + let len = String.length body in + let buf = Buffer.create (len / 2) in + let i = ref 0 in + (try + while !i < len do + let line_end = + let rec find j = + if j >= len then raise Exit else if body.[j] = '\r' then j + else find (j + 1) + in + find !i + in + let size_str = String.sub body !i (line_end - !i) in + let size_str = + match String.index_opt size_str ';' with + | Some idx -> String.sub size_str 0 idx + | None -> size_str + in + let size = int_of_string ("0x" ^ String.trim size_str) in + if size = 0 then raise Exit; + i := line_end + 2; + if !i + size <= len then + Buffer.add_string buf (String.sub body !i size); + i := !i + size + 2 + done + with Exit -> ()); + Buffer.contents buf + +let b64_encode src = + let tbl = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" in + let len = String.length src in + let buf = Buffer.create (len * 4 / 3 + 4) in + let i = ref 0 in + while !i + 2 < len do + let a = Char.code src.[!i] and b = Char.code src.[!i+1] and c = Char.code src.[!i+2] in + Buffer.add_char buf tbl.[(a lsr 2) land 0x3f]; + Buffer.add_char buf tbl.[((a lsl 4) lor (b lsr 4)) land 0x3f]; + Buffer.add_char buf tbl.[((b lsl 2) lor (c lsr 6)) land 0x3f]; + Buffer.add_char buf tbl.[c land 0x3f]; + i := !i + 3 + done; + (match len - !i with + | 2 -> + let a = Char.code src.[!i] and b = Char.code src.[!i+1] in + Buffer.add_char buf tbl.[(a lsr 2) land 0x3f]; + Buffer.add_char buf tbl.[((a lsl 4) lor (b lsr 4)) land 0x3f]; + Buffer.add_char buf tbl.[(b lsl 2) land 0x3f]; + Buffer.add_char buf '=' + | 1 -> + let a = Char.code src.[!i] in + Buffer.add_char buf tbl.[(a lsr 2) land 0x3f]; + Buffer.add_char buf tbl.[(a lsl 4) land 0x3f]; + Buffer.add_string buf "==" + | _ -> ()); + Buffer.contents buf + +let ssl_inited = ref false + +let https_request ~meth ~host ~path ?(headers=[]) ?(body="") () = + if not !ssl_inited then ( + Ssl.init (); + ssl_inited := true); + let he = Unix.gethostbyname host in + let addr = he.h_addr_list.(0) in + let sockaddr = Unix.ADDR_INET (addr, 443) in + let ctx = Ssl.create_context Ssl.TLSv1_2 Ssl.Client_context in + let sock = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in + Unix.connect sock sockaddr; + let ssl = Ssl.embed_socket sock ctx in + Ssl.set_client_SNI_hostname ssl host; + Ssl.connect ssl; + let extra_headers = + List.fold_left (fun acc (k, v) -> acc ^ k ^ ": " ^ v ^ "\r\n") "" headers + in + let content_len = if body <> "" then + Printf.sprintf "Content-Length: %d\r\n" (String.length body) + else "" in + let req = + Printf.sprintf "%s %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: meat/1.0\r\nConnection: close\r\n%s%s\r\n%s" + meth path host extra_headers content_len body + in + ignore (Ssl.write ssl (Bytes.of_string req) 0 (String.length req)); + let buf = Buffer.create 8192 in + let chunk = Bytes.create 4096 in + (try + while true do + let n = Ssl.read ssl chunk 0 4096 in + if n = 0 then raise Exit; + Buffer.add_subbytes buf chunk 0 n + done + with _ -> ()); + (try Ssl.shutdown_connection ssl with _ -> ()); + Unix.close sock; + let response = Buffer.contents buf in + let rlen = String.length response in + let header_end = + let rec find pos = + if pos + 3 >= rlen then rlen + else if + response.[pos] = '\r' + && response.[pos + 1] = '\n' + && response.[pos + 2] = '\r' + && response.[pos + 3] = '\n' + then pos + else find (pos + 1) + in + find 0 + in + let resp_headers = String.sub response 0 header_end in + let body_start = min (header_end + 4) rlen in + let resp_body = String.sub response body_start (rlen - body_start) in + if + contains_sub + (String.lowercase_ascii resp_headers) + "transfer-encoding: chunked" + then decode_chunked resp_body + else resp_body + +let https_get ~host ~path = + https_request ~meth:"GET" ~host ~path + ~headers:[("User-Agent", "git/2.0")] () + +let https_post ~host ~path ~body = + https_request ~meth:"POST" ~host ~path + ~headers:[ + ("Content-Type", "application/json"); + ("Accept", "application/json"); + ("Authorization", "Basic " ^ b64_encode "aWVSALXpZv:X8gPHnzL52wFEekuxsfQ9cSh"); + ] ~body () + +let parse_pktline body = + let len = String.length body in + let i = ref 0 in + let refs = ref [] in + let hex_val c = + match c with + | '0' .. '9' -> Char.code c - Char.code '0' + | 'a' .. 'f' -> Char.code c - Char.code 'a' + 10 + | 'A' .. 'F' -> Char.code c - Char.code 'A' + 10 + | _ -> 0 + in + let read_pkt_len () = + if !i + 4 > len then 0 + else + let a = hex_val body.[!i] + and b = hex_val body.[!i + 1] + and c = hex_val body.[!i + 2] + and d = hex_val body.[!i + 3] in + i := !i + 4; + (a * 4096) + (b * 256) + (c * 16) + d + in + let plen = read_pkt_len () in + if plen > 4 then i := !i + (plen - 4); + ignore (read_pkt_len ()); + let continue = ref true in + while !continue do + let plen = read_pkt_len () in + if plen = 0 then continue := false + else + let payload_len = plen - 4 in + if !i + payload_len <= len && payload_len >= 41 then ( + let payload = String.sub body !i payload_len in + i := !i + payload_len; + let sha = String.sub payload 0 40 in + let rest = String.sub payload 41 (String.length payload - 41) in + let refname = + let s = + match String.index_opt rest '\000' with + | Some idx -> String.sub rest 0 idx + | None -> rest + in + match String.index_opt s '\n' with + | Some idx -> String.sub s 0 idx + | None -> s + in + refs := (refname, sha) :: !refs) + else i := !i + max 0 payload_len + done; + List.rev !refs + +let derelativise base = List.map (fun a -> base ^ "/" ^ a) + +let filter_dirs fullpath dirs = + dirs |> derelativise fullpath + |> List.filter (fun d -> (Unix.stat d).st_kind = Unix.S_DIR) + +let readdir d = try Sys.readdir d with Sys_error _ -> [||] + +let walk entry = + let open List in + let rec loop dir : string list = + let contents = readdir dir |> Array.to_list in + let is_flake = mem "flake.nix" contents in + if dir = entry then + let subdirs = contents |> filter_dirs dir in + flatten (map loop subdirs) + else if is_flake then + let subdirs = contents |> filter_dirs dir in + let children = flatten (map loop subdirs) in + [ dir ] @ children + else [] + in + loop entry + +let countdepth s = + s |> String.fold_left (fun acc el -> acc + if el = '/' then 1 else 0) 0 + +let compdepth a b = + let ad = countdepth a and bd = countdepth b in + let dif = ad - bd in + match dif with 0 -> 0 | _ -> dif / abs dif + +let fmt_dir d = String.split_on_char '/' d |> List.rev |> List.hd |> Common.all_caps diff --git a/lib/json.ml b/lib/json.ml new file mode 100644 index 0000000..5dd5297 --- /dev/null +++ b/lib/json.ml @@ -0,0 +1,8 @@ +let parse_json src = Yojson.Basic.from_string src + +let jfield key = function + | `Assoc pairs -> List.assoc_opt key pairs + | _ -> None + +let jstring = function `String s -> Some s | _ -> None +let jassoc = function `Assoc pairs -> Some pairs | _ -> None diff --git a/lib/meat.ml b/lib/meat.ml index 9a17705..2d481e1 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -1,213 +1,10 @@ -let header = "\n ----- MEAT ----------------------------------------\n" -let footer = "\n ---------------------------------------------------\n" - -let help = - {| - YUM - CONSUME DELICIOUS MEATS - COOK - ONLY PREPARE MEATS - POKE - TASTE SUSPICIOUS MEATS - GUT - CLEAN MEAT STORES - FRESH - HUNT FRESH MEATS - TRADE - SEND MEATS FAR AWAY - ..-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)) - | _ -> "" - -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" - >>= fun () -> - do_cmd @@ "sudo " ^ tmpdir ^ "/build/bin/switch-to-configuration switch" - >|= fun () -> Unix.unlink @@ tmpdir ^ "/build" - -let do_remote () = - meat_print "tbd"; - Ok () - -let trade () = - print_string header; - meat_print "TRADING FOREIGN MEATS.."; - do_remote () |> function - | Error _ -> print_string "FAILED TO TRADE MEATS." - | _ -> - (); - print_string footer - -let yum () = - print_string header; - meat_print "CONSUMING DELICIOUS MEATS.."; - ( do_build () |> function - | Error _ -> print_string "FAILED TO CONSUME MEATS." - | _ -> () ); - 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 - 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 - 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" |> ignore; - 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 *) -let all_flag () = - if Array.length argv >= 3 then - match Array.get argv 2 with "-a" | "--all" -> true | _ -> false - else false - -let sub_flag () = - if Array.length argv >= 3 then - match Array.get argv 2 with "-s" | "--sub" -> true | _ -> false - else false - -let derelativise base = List.map (fun a -> base ^ "/" ^ a) - -let filter_dirs fullpath dirs = - dirs |> derelativise fullpath - |> List.filter (fun d -> (Unix.stat d).st_kind = S_DIR) - -let readdir d = try Sys.readdir d with Sys_error _ -> [||] - -let walk entry = - let open List in - let rec loop dir : string list = - let contents = readdir dir |> Array.to_list in - let is_flake = mem "flake.nix" contents in - if dir = entry then - let subdirs = contents |> filter_dirs dir in - flatten (map loop subdirs) - else if is_flake then - let subdirs = contents |> filter_dirs dir in - let children = flatten (map loop subdirs) in - [ dir ] @ children - else [] - in - loop entry - -let countdepth s = - s |> String.fold_left (fun acc el -> acc + if el = '/' then 1 else 0) 0 - -let compdepth a b = - let ad = countdepth a and bd = countdepth b in - let dif = ad - bd in - match dif with 0 -> 0 | _ -> dif / abs dif - -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) -let fmt_dir d = String.split_on_char '/' d |> List.rev |> List.hd |> all_caps - -let submeats s = - s - |> List.iter (fun d -> - meat_print ("PROCESSING SUBMEAT " ^ fmt_dir 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 "MEATS" in - let base_dir = root ^ "/flakes" in - (match (sub_flag (), all_flag ()) with - | false, false -> - (* no flags, plain flake inputs *) - if argv_len >= 3 then - let open Array in - let flakes = sub argv 2 (argv_len - 2) in - flakes - |> 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) - 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 |> ignore - | true, _ when argv_len >= 4 -> - (* sub flag, update inputs as subflakes *) - let subflakes = - match argv_len with - | 4 -> [ argv.(3) ] - | _ -> Array.sub argv 4 (argv_len - 4) |> Array.to_list - in - let open List in - let sf_full = subflakes |> derelativise base_dir in - sf_full |> map walk |> flatten |> sort compdepth |> rev |> append sf_full - |> submeats; - print_string footer; - meat_print "PROCESSING FRESH MEATS.."; - subflakes - |> iter (fun f -> - do_cmd ~args:false @@ "nix flake update " ^ all_low f - ^ " --flake $MEATS" - |> ignore) - | _ -> print_string help); - print_string footer; - print_newline () - -let help () = print_string (header ^ help ^ footer ^ "\n") +let yum = Commands.Yum.run +let cook = Commands.Cook.run +let poke = Commands.Poke.run +let gut = Commands.Gut.run +let trade = Commands.Trade.run +let look = Commands.Look.run +let fresh = Commands.Fresh.run +let hunt = Commands.Hunt.run +let help = Commands.Help.run +let meat_print = Common.meat_print From 945892f51d84d2c77d8b831e4ce8afa33117419f Mon Sep 17 00:00:00 2001 From: atagen Date: Tue, 24 Mar 2026 21:48:12 +1100 Subject: [PATCH 42/44] ritual --- bin/main.ml | 1 + flake.lock | 93 +++++++++--------------------------------- lib/commands/ritual.ml | 39 ++++++++++++++++++ lib/common.ml | 5 ++- lib/meat.ml | 1 + nix/default.nix | 2 +- 6 files changed, 65 insertions(+), 76 deletions(-) create mode 100644 lib/commands/ritual.ml diff --git a/bin/main.ml b/bin/main.ml index 6aa19f9..11c0cca 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -13,6 +13,7 @@ let () = | "look" -> look () | "fresh" -> fresh () | "hunt" -> hunt () + | "ritual" -> ritual () | _ -> help () else help () | None -> diff --git a/flake.lock b/flake.lock index 2964faf..843a72b 100644 --- a/flake.lock +++ b/flake.lock @@ -1,50 +1,15 @@ { "nodes": { - "flake-compat": { - "locked": { - "lastModified": 1733328505, - "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-parts": { - "inputs": { - "nixpkgs-lib": "nixpkgs-lib" - }, - "locked": { - "lastModified": 1743550720, - "narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "c621e8422220273271f52058f618c94e405bb0f5", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, "ndg": { "inputs": { - "flake-compat": "flake-compat", - "flake-parts": "flake-parts", "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1748103964, - "narHash": "sha256-aRFl6I3x1aKzeOBaD/OJHYv+OQ+qE+3FR9uKhIvfW+A=", + "lastModified": 1773478949, + "narHash": "sha256-8rMpSs2OWGaDlDFO5FS6Pf9WutHBXxM2omPr6hfKydI=", "owner": "feel-co", "repo": "ndg", - "rev": "c556c4cbcba61474bf8a342a31a2d94cbefd8986", + "rev": "c3bc1541668e6f6632a7005c7e4963c0a5dedc7b", "type": "github" }, "original": { @@ -70,11 +35,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1748217807, - "narHash": "sha256-P3u2PXxMlo49PutQLnk2PhI/imC69hFl1yY4aT5Nax8=", + "lastModified": 1774078191, + "narHash": "sha256-nyxxxW1/2ouu9dU0I02ul5pHrmUrE1JVFhfFlmYe3Lw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "3108eaa516ae22c2360928589731a4f1581526ef", + "rev": "09061f748ee21f68a089cd5d91ec1859cd93d0be", "type": "github" }, "original": { @@ -84,44 +49,26 @@ "type": "github" } }, - "nixpkgs-lib": { - "locked": { - "lastModified": 1743296961, - "narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", - "type": "github" - } - }, "nixpkgs_2": { "locked": { - "lastModified": 1745930157, - "narHash": "sha256-y3h3NLnzRSiUkYpnfvnS669zWZLoqqI6NprtLQ+5dck=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "46e634be05ce9dc6d4db8e664515ba10b78151ae", - "type": "github" + "lastModified": 1773282481, + "narHash": "sha256-oFe06TmOy8UUT1f7xMHqDpSYq2Fy1mkIsXZUvdnyfeY=", + "rev": "fe416aaedd397cacb33a610b33d60ff2b431b127", + "type": "tarball", + "url": "https://releases.nixos.org/nixos/unstable/nixos-26.05pre962285.fe416aaedd39/nixexprs.tar.xz?lastModified=1773282481&rev=fe416aaedd397cacb33a610b33d60ff2b431b127" }, "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" + "type": "tarball", + "url": "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz" } }, "nixpkgs_3": { "locked": { - "lastModified": 1748217807, - "narHash": "sha256-P3u2PXxMlo49PutQLnk2PhI/imC69hFl1yY4aT5Nax8=", + "lastModified": 1774078191, + "narHash": "sha256-nyxxxW1/2ouu9dU0I02ul5pHrmUrE1JVFhfFlmYe3Lw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "3108eaa516ae22c2360928589731a4f1581526ef", + "rev": "09061f748ee21f68a089cd5d91ec1859cd93d0be", "type": "github" }, "original": { @@ -144,11 +91,11 @@ "nixpkgs": "nixpkgs_3" }, "locked": { - "lastModified": 1748163740, - "narHash": "sha256-WOK9w5gtdpy4RefaiRtr6YqFaPxR0OrmI2PleZnn4O4=", + "lastModified": 1760178630, + "narHash": "sha256-oxRMTQtzIO1yFRhY++Ss8+ea1cTH40bD/+FAE+m5NFk=", "ref": "refs/heads/main", - "rev": "4d711e5002bd22adbe6d786560be0fde6cbcf81e", - "revCount": 1, + "rev": "8a6aa536039f1b207888b1369c5cabf0b131e07b", + "revCount": 5, "type": "git", "url": "https://git.atagen.co/atagen/unf" }, diff --git a/lib/commands/ritual.ml b/lib/commands/ritual.ml new file mode 100644 index 0000000..739995f --- /dev/null +++ b/lib/commands/ritual.ml @@ -0,0 +1,39 @@ +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 sh -c '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 diff --git a/lib/common.ml b/lib/common.ml index c8a87b9..ca7ead8 100644 --- a/lib/common.ml +++ b/lib/common.ml @@ -10,6 +10,7 @@ let help_text = FRESH - HUNT FRESH MEATS LOOK - LOOK FOR FRESHER MEATS HUNT - HUNT FOR MEATS IN NIXPKGS + RITUAL - PERFORM RITUAL THEN CONSUME TRADE - SEND MEATS FAR AWAY ..-A - ..ALL MEATS|} open Sys @@ -43,8 +44,8 @@ let do_build () = >>= 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" + do_cmd @@ "sudo sh -c '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 () = diff --git a/lib/meat.ml b/lib/meat.ml index 2d481e1..29a35d1 100644 --- a/lib/meat.ml +++ b/lib/meat.ml @@ -6,5 +6,6 @@ let trade = Commands.Trade.run let look = Commands.Look.run let fresh = Commands.Fresh.run let hunt = Commands.Hunt.run +let ritual = Commands.Ritual.run let help = Commands.Help.run let meat_print = Common.meat_print diff --git a/nix/default.nix b/nix/default.nix index f5274ad..a6004a4 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -13,5 +13,5 @@ ocamlPackages.buildDunePackage { src = ./..; nativeBuildInputs = [ git ]; - inherit buildInputs; + buildInputs = buildInputs; } From e598b04caea500642e4cedaf577798ee4bf16f05 Mon Sep 17 00:00:00 2001 From: atagen Date: Sat, 23 Nov 2024 16:49:05 +1100 Subject: [PATCH 43/44] ocaml --- .envrc | 1 + .gitea/workflows/nix.yaml | 11 ++ .gitignore | 5 + README.md | 1 + bin/.ocamlformat | 0 bin/dune | 4 + bin/main.ml | 21 ++++ dune-project | 26 +++++ flake.lock | 110 ++++++++++++++++++ flake.nix | 99 ++++++++++++++++ lib/.ocamlformat | 0 lib/commands/cook.ml | 9 ++ lib/commands/fresh.ml | 17 +++ lib/commands/gut.ml | 5 + lib/commands/help.ml | 1 + lib/commands/hunt.ml | 61 ++++++++++ lib/commands/look.ml | 114 +++++++++++++++++++ lib/commands/poke.ml | 9 ++ lib/commands/ritual.ml | 39 +++++++ lib/commands/trade.ml | 8 ++ lib/commands/yum.ml | 7 ++ lib/common.ml | 61 ++++++++++ lib/dune | 4 + lib/http.ml | 232 ++++++++++++++++++++++++++++++++++++++ lib/json.ml | 8 ++ lib/meat.ml | 11 ++ meat.opam | 31 +++++ nix/default.nix | 17 +++ nix/module.nix | 32 ++++++ test/dune | 2 + test/test_meat.ml | 0 31 files changed, 946 insertions(+) create mode 100644 .envrc create mode 100644 .gitea/workflows/nix.yaml create mode 100644 .gitignore create mode 100644 README.md create mode 100644 bin/.ocamlformat create mode 100644 bin/dune create mode 100644 bin/main.ml create mode 100644 dune-project create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 lib/.ocamlformat create mode 100644 lib/commands/cook.ml create mode 100644 lib/commands/fresh.ml create mode 100644 lib/commands/gut.ml create mode 100644 lib/commands/help.ml create mode 100644 lib/commands/hunt.ml create mode 100644 lib/commands/look.ml create mode 100644 lib/commands/poke.ml create mode 100644 lib/commands/ritual.ml create mode 100644 lib/commands/trade.ml create mode 100644 lib/commands/yum.ml create mode 100644 lib/common.ml create mode 100644 lib/dune create mode 100644 lib/http.ml create mode 100644 lib/json.ml create mode 100644 lib/meat.ml create mode 100644 meat.opam create mode 100644 nix/default.nix create mode 100644 nix/module.nix create mode 100644 test/dune create mode 100644 test/test_meat.ml diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitea/workflows/nix.yaml b/.gitea/workflows/nix.yaml new file mode 100644 index 0000000..d5443ef --- /dev/null +++ b/.gitea/workflows/nix.yaml @@ -0,0 +1,11 @@ +name: Nix Build +on: [push] + +jobs: + all-in-one: + runs-on: [native] + name: nix build + steps: + - uses: actions/checkout@v4 + - run: nix build --no-link . + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9a62042 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +_build +.direnv/ +result +justfile +todo diff --git a/README.md b/README.md new file mode 100644 index 0000000..a13e7e8 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +this is chopped dont look at it diff --git a/bin/.ocamlformat b/bin/.ocamlformat new file mode 100644 index 0000000..e69de29 diff --git a/bin/dune b/bin/dune new file mode 100644 index 0000000..b1f555a --- /dev/null +++ b/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name meat) + (name main) + (libraries meat)) diff --git a/bin/main.ml b/bin/main.ml new file mode 100644 index 0000000..11c0cca --- /dev/null +++ b/bin/main.ml @@ -0,0 +1,21 @@ +open Meat + +let () = + match Sys.getenv_opt "MEATS" with + | Some _ -> + if Array.length Sys.argv >= 2 then + match String.lowercase_ascii (Array.get Sys.argv 1) with + | "yum" -> yum () + | "cook" -> cook () + | "poke" -> poke () + | "gut" -> gut () + | "trade" -> trade () + | "look" -> look () + | "fresh" -> fresh () + | "hunt" -> hunt () + | "ritual" -> ritual () + | _ -> help () + else help () + | None -> + meat_print "NO PATH TO RUNESTONE FOUND!"; + help () diff --git a/dune-project b/dune-project new file mode 100644 index 0000000..256991c --- /dev/null +++ b/dune-project @@ -0,0 +1,26 @@ +(lang dune 3.16) + +(name meat) + +(generate_opam_files true) + +(source + (github username/reponame)) + +(authors "Author Name ") + +(maintainers "Maintainer Name ") + +(license LICENSE) + +(documentation https://url/to/documentation) + +(package + (name meat) + (synopsis "A short synopsis") + (description "A longer description") + (depends ocaml dune) + (tags + ("add topics" "to describe" your project))) + +; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..843a72b --- /dev/null +++ b/flake.lock @@ -0,0 +1,110 @@ +{ + "nodes": { + "ndg": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1773478949, + "narHash": "sha256-8rMpSs2OWGaDlDFO5FS6Pf9WutHBXxM2omPr6hfKydI=", + "owner": "feel-co", + "repo": "ndg", + "rev": "c3bc1541668e6f6632a7005c7e4963c0a5dedc7b", + "type": "github" + }, + "original": { + "owner": "feel-co", + "repo": "ndg", + "type": "github" + } + }, + "nix-systems": { + "locked": { + "lastModified": 1689347949, + "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", + "owner": "nix-systems", + "repo": "default-linux", + "rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default-linux", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1774078191, + "narHash": "sha256-nyxxxW1/2ouu9dU0I02ul5pHrmUrE1JVFhfFlmYe3Lw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "09061f748ee21f68a089cd5d91ec1859cd93d0be", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1773282481, + "narHash": "sha256-oFe06TmOy8UUT1f7xMHqDpSYq2Fy1mkIsXZUvdnyfeY=", + "rev": "fe416aaedd397cacb33a610b33d60ff2b431b127", + "type": "tarball", + "url": "https://releases.nixos.org/nixos/unstable/nixos-26.05pre962285.fe416aaedd39/nixexprs.tar.xz?lastModified=1773282481&rev=fe416aaedd397cacb33a610b33d60ff2b431b127" + }, + "original": { + "type": "tarball", + "url": "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1774078191, + "narHash": "sha256-nyxxxW1/2ouu9dU0I02ul5pHrmUrE1JVFhfFlmYe3Lw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "09061f748ee21f68a089cd5d91ec1859cd93d0be", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nix-systems": "nix-systems", + "nixpkgs": "nixpkgs", + "unf": "unf" + } + }, + "unf": { + "inputs": { + "ndg": "ndg", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1760178630, + "narHash": "sha256-oxRMTQtzIO1yFRhY++Ss8+ea1cTH40bD/+FAE+m5NFk=", + "ref": "refs/heads/main", + "rev": "8a6aa536039f1b207888b1369c5cabf0b131e07b", + "revCount": 5, + "type": "git", + "url": "https://git.atagen.co/atagen/unf" + }, + "original": { + "type": "git", + "url": "https://git.atagen.co/atagen/unf" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..33d7c3a --- /dev/null +++ b/flake.nix @@ -0,0 +1,99 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + nix-systems.url = "github:nix-systems/default-linux"; + unf.url = "git+https://git.atagen.co/atagen/unf"; + }; + + outputs = + inputs: + with inputs; + let + version = builtins.toString self.lastModified; + collectPkgs = builtins.attrValues; + forEachSystem = + function: + nixpkgs.lib.genAttrs (import nix-systems) ( + system: function nixpkgs.legacyPackages.${system} system + ); + deps = forEachSystem ( + pkgs: _: { + build = collectPkgs { + inherit (pkgs.ocamlPackages) + dune_3 + ocaml + yojson + ssl + ; + inherit (pkgs.openssl) dev; + }; + dev = collectPkgs { + inherit (pkgs.ocamlPackages) + utop + ocaml-lsp + ocamlformat + ocamlformat-rpc-lib + ; + }; + } + ); + in + { + devShells = forEachSystem ( + pkgs: sys: { + default = pkgs.mkShell { + packages = pkgs.lib.mapAttrsToList (_: v: v) deps.${sys}; + shellHook = + let + justFile = '' + default: + @just --list + + @build: + nix build .#debug --offline + + @release: + nix build --offline + + @test: + printf "\\n\\n\\t************ running nix+dune tests ************\\n\\n\\n" + nix flake check --offline + ''; + in + '' + printf '${justFile}' > justfile + ''; + }; + } + ); + + packages = forEachSystem ( + pkgs: sys: { + default = pkgs.callPackage ./nix/default.nix { + buildInputs = deps.${sys}.build; + inherit version; + }; + docs = pkgs.callPackage unf.lib.pak-chooie { + inherit self; + projectName = "meat"; + newPath = "https://git.atagen.co/atagen/meat/src"; + modules = [ + self.nixosModules.meat + ]; + }; + } + ); + + nixosModules.meat = + { + pkgs, + lib, + ... + }: + { + imports = [ ./nix/module.nix ]; + programs.meat.package = self.packages.${pkgs.stdenv.hostPlatform.system}.default; + }; + + }; +} diff --git a/lib/.ocamlformat b/lib/.ocamlformat new file mode 100644 index 0000000..e69de29 diff --git a/lib/commands/cook.ml b/lib/commands/cook.ml new file mode 100644 index 0000000..4c79b1c --- /dev/null +++ b/lib/commands/cook.ml @@ -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 diff --git a/lib/commands/fresh.ml b/lib/commands/fresh.ml new file mode 100644 index 0000000..d4c4a52 --- /dev/null +++ b/lib/commands/fresh.ml @@ -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 () diff --git a/lib/commands/gut.ml b/lib/commands/gut.ml new file mode 100644 index 0000000..8a5594c --- /dev/null +++ b/lib/commands/gut.ml @@ -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 diff --git a/lib/commands/help.ml b/lib/commands/help.ml new file mode 100644 index 0000000..f29a0e7 --- /dev/null +++ b/lib/commands/help.ml @@ -0,0 +1 @@ +let run () = print_string (Common.header ^ Common.help_text ^ Common.footer ^ "\n") diff --git a/lib/commands/hunt.ml b/lib/commands/hunt.ml new file mode 100644 index 0000000..655feee --- /dev/null +++ b/lib/commands/hunt.ml @@ -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 diff --git a/lib/commands/look.ml b/lib/commands/look.ml new file mode 100644 index 0000000..c1df668 --- /dev/null +++ b/lib/commands/look.ml @@ -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 diff --git a/lib/commands/poke.ml b/lib/commands/poke.ml new file mode 100644 index 0000000..800e39d --- /dev/null +++ b/lib/commands/poke.ml @@ -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 diff --git a/lib/commands/ritual.ml b/lib/commands/ritual.ml new file mode 100644 index 0000000..739995f --- /dev/null +++ b/lib/commands/ritual.ml @@ -0,0 +1,39 @@ +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 sh -c '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 diff --git a/lib/commands/trade.ml b/lib/commands/trade.ml new file mode 100644 index 0000000..80e6dfa --- /dev/null +++ b/lib/commands/trade.ml @@ -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 diff --git a/lib/commands/yum.ml b/lib/commands/yum.ml new file mode 100644 index 0000000..08514cc --- /dev/null +++ b/lib/commands/yum.ml @@ -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 diff --git a/lib/common.ml b/lib/common.ml new file mode 100644 index 0000000..ca7ead8 --- /dev/null +++ b/lib/common.ml @@ -0,0 +1,61 @@ +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 + RITUAL - PERFORM RITUAL THEN CONSUME + 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 sh -c '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) diff --git a/lib/dune b/lib/dune new file mode 100644 index 0000000..016c372 --- /dev/null +++ b/lib/dune @@ -0,0 +1,4 @@ +(include_subdirs qualified) +(library + (name meat) + (libraries unix ssl yojson)) diff --git a/lib/http.ml b/lib/http.ml new file mode 100644 index 0000000..f681505 --- /dev/null +++ b/lib/http.ml @@ -0,0 +1,232 @@ +let read_file path = + let ic = open_in path in + let n = in_channel_length ic in + let s = really_input_string ic n in + close_in ic; + s + +let contains_sub haystack needle = + let hl = String.length haystack and nl = String.length needle in + if nl > hl then false + else + let rec check i = + if i + nl > hl then false + else if String.sub haystack i nl = needle then true + else check (i + 1) + in + check 0 + +let decode_chunked body = + let len = String.length body in + let buf = Buffer.create (len / 2) in + let i = ref 0 in + (try + while !i < len do + let line_end = + let rec find j = + if j >= len then raise Exit else if body.[j] = '\r' then j + else find (j + 1) + in + find !i + in + let size_str = String.sub body !i (line_end - !i) in + let size_str = + match String.index_opt size_str ';' with + | Some idx -> String.sub size_str 0 idx + | None -> size_str + in + let size = int_of_string ("0x" ^ String.trim size_str) in + if size = 0 then raise Exit; + i := line_end + 2; + if !i + size <= len then + Buffer.add_string buf (String.sub body !i size); + i := !i + size + 2 + done + with Exit -> ()); + Buffer.contents buf + +let b64_encode src = + let tbl = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" in + let len = String.length src in + let buf = Buffer.create (len * 4 / 3 + 4) in + let i = ref 0 in + while !i + 2 < len do + let a = Char.code src.[!i] and b = Char.code src.[!i+1] and c = Char.code src.[!i+2] in + Buffer.add_char buf tbl.[(a lsr 2) land 0x3f]; + Buffer.add_char buf tbl.[((a lsl 4) lor (b lsr 4)) land 0x3f]; + Buffer.add_char buf tbl.[((b lsl 2) lor (c lsr 6)) land 0x3f]; + Buffer.add_char buf tbl.[c land 0x3f]; + i := !i + 3 + done; + (match len - !i with + | 2 -> + let a = Char.code src.[!i] and b = Char.code src.[!i+1] in + Buffer.add_char buf tbl.[(a lsr 2) land 0x3f]; + Buffer.add_char buf tbl.[((a lsl 4) lor (b lsr 4)) land 0x3f]; + Buffer.add_char buf tbl.[(b lsl 2) land 0x3f]; + Buffer.add_char buf '=' + | 1 -> + let a = Char.code src.[!i] in + Buffer.add_char buf tbl.[(a lsr 2) land 0x3f]; + Buffer.add_char buf tbl.[(a lsl 4) land 0x3f]; + Buffer.add_string buf "==" + | _ -> ()); + Buffer.contents buf + +let ssl_inited = ref false + +let https_request ~meth ~host ~path ?(headers=[]) ?(body="") () = + if not !ssl_inited then ( + Ssl.init (); + ssl_inited := true); + let he = Unix.gethostbyname host in + let addr = he.h_addr_list.(0) in + let sockaddr = Unix.ADDR_INET (addr, 443) in + let ctx = Ssl.create_context Ssl.TLSv1_2 Ssl.Client_context in + let sock = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in + Unix.connect sock sockaddr; + let ssl = Ssl.embed_socket sock ctx in + Ssl.set_client_SNI_hostname ssl host; + Ssl.connect ssl; + let extra_headers = + List.fold_left (fun acc (k, v) -> acc ^ k ^ ": " ^ v ^ "\r\n") "" headers + in + let content_len = if body <> "" then + Printf.sprintf "Content-Length: %d\r\n" (String.length body) + else "" in + let req = + Printf.sprintf "%s %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: meat/1.0\r\nConnection: close\r\n%s%s\r\n%s" + meth path host extra_headers content_len body + in + ignore (Ssl.write ssl (Bytes.of_string req) 0 (String.length req)); + let buf = Buffer.create 8192 in + let chunk = Bytes.create 4096 in + (try + while true do + let n = Ssl.read ssl chunk 0 4096 in + if n = 0 then raise Exit; + Buffer.add_subbytes buf chunk 0 n + done + with _ -> ()); + (try Ssl.shutdown_connection ssl with _ -> ()); + Unix.close sock; + let response = Buffer.contents buf in + let rlen = String.length response in + let header_end = + let rec find pos = + if pos + 3 >= rlen then rlen + else if + response.[pos] = '\r' + && response.[pos + 1] = '\n' + && response.[pos + 2] = '\r' + && response.[pos + 3] = '\n' + then pos + else find (pos + 1) + in + find 0 + in + let resp_headers = String.sub response 0 header_end in + let body_start = min (header_end + 4) rlen in + let resp_body = String.sub response body_start (rlen - body_start) in + if + contains_sub + (String.lowercase_ascii resp_headers) + "transfer-encoding: chunked" + then decode_chunked resp_body + else resp_body + +let https_get ~host ~path = + https_request ~meth:"GET" ~host ~path + ~headers:[("User-Agent", "git/2.0")] () + +let https_post ~host ~path ~body = + https_request ~meth:"POST" ~host ~path + ~headers:[ + ("Content-Type", "application/json"); + ("Accept", "application/json"); + ("Authorization", "Basic " ^ b64_encode "aWVSALXpZv:X8gPHnzL52wFEekuxsfQ9cSh"); + ] ~body () + +let parse_pktline body = + let len = String.length body in + let i = ref 0 in + let refs = ref [] in + let hex_val c = + match c with + | '0' .. '9' -> Char.code c - Char.code '0' + | 'a' .. 'f' -> Char.code c - Char.code 'a' + 10 + | 'A' .. 'F' -> Char.code c - Char.code 'A' + 10 + | _ -> 0 + in + let read_pkt_len () = + if !i + 4 > len then 0 + else + let a = hex_val body.[!i] + and b = hex_val body.[!i + 1] + and c = hex_val body.[!i + 2] + and d = hex_val body.[!i + 3] in + i := !i + 4; + (a * 4096) + (b * 256) + (c * 16) + d + in + let plen = read_pkt_len () in + if plen > 4 then i := !i + (plen - 4); + ignore (read_pkt_len ()); + let continue = ref true in + while !continue do + let plen = read_pkt_len () in + if plen = 0 then continue := false + else + let payload_len = plen - 4 in + if !i + payload_len <= len && payload_len >= 41 then ( + let payload = String.sub body !i payload_len in + i := !i + payload_len; + let sha = String.sub payload 0 40 in + let rest = String.sub payload 41 (String.length payload - 41) in + let refname = + let s = + match String.index_opt rest '\000' with + | Some idx -> String.sub rest 0 idx + | None -> rest + in + match String.index_opt s '\n' with + | Some idx -> String.sub s 0 idx + | None -> s + in + refs := (refname, sha) :: !refs) + else i := !i + max 0 payload_len + done; + List.rev !refs + +let derelativise base = List.map (fun a -> base ^ "/" ^ a) + +let filter_dirs fullpath dirs = + dirs |> derelativise fullpath + |> List.filter (fun d -> (Unix.stat d).st_kind = Unix.S_DIR) + +let readdir d = try Sys.readdir d with Sys_error _ -> [||] + +let walk entry = + let open List in + let rec loop dir : string list = + let contents = readdir dir |> Array.to_list in + let is_flake = mem "flake.nix" contents in + if dir = entry then + let subdirs = contents |> filter_dirs dir in + flatten (map loop subdirs) + else if is_flake then + let subdirs = contents |> filter_dirs dir in + let children = flatten (map loop subdirs) in + [ dir ] @ children + else [] + in + loop entry + +let countdepth s = + s |> String.fold_left (fun acc el -> acc + if el = '/' then 1 else 0) 0 + +let compdepth a b = + let ad = countdepth a and bd = countdepth b in + let dif = ad - bd in + match dif with 0 -> 0 | _ -> dif / abs dif + +let fmt_dir d = String.split_on_char '/' d |> List.rev |> List.hd |> Common.all_caps diff --git a/lib/json.ml b/lib/json.ml new file mode 100644 index 0000000..5dd5297 --- /dev/null +++ b/lib/json.ml @@ -0,0 +1,8 @@ +let parse_json src = Yojson.Basic.from_string src + +let jfield key = function + | `Assoc pairs -> List.assoc_opt key pairs + | _ -> None + +let jstring = function `String s -> Some s | _ -> None +let jassoc = function `Assoc pairs -> Some pairs | _ -> None diff --git a/lib/meat.ml b/lib/meat.ml new file mode 100644 index 0000000..29a35d1 --- /dev/null +++ b/lib/meat.ml @@ -0,0 +1,11 @@ +let yum = Commands.Yum.run +let cook = Commands.Cook.run +let poke = Commands.Poke.run +let gut = Commands.Gut.run +let trade = Commands.Trade.run +let look = Commands.Look.run +let fresh = Commands.Fresh.run +let hunt = Commands.Hunt.run +let ritual = Commands.Ritual.run +let help = Commands.Help.run +let meat_print = Common.meat_print diff --git a/meat.opam b/meat.opam new file mode 100644 index 0000000..f89d30f --- /dev/null +++ b/meat.opam @@ -0,0 +1,31 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "A short synopsis" +description: "A longer description" +maintainer: ["Maintainer Name "] +authors: ["Author Name "] +license: "LICENSE" +tags: ["add topics" "to describe" "your" "project"] +homepage: "https://github.com/username/reponame" +doc: "https://url/to/documentation" +bug-reports: "https://github.com/username/reponame/issues" +depends: [ + "ocaml" + "dune" {>= "3.16"} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/username/reponame.git" diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..a6004a4 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,17 @@ +{ + ocamlPackages, + buildInputs, + git, + version, + ... +}: +ocamlPackages.buildDunePackage { + pname = "meat"; + version = "0.1-delicious-${version}"; + + minimalOCamlVersion = "5.2"; + + src = ./..; + nativeBuildInputs = [ git ]; + buildInputs = buildInputs; +} diff --git a/nix/module.nix b/nix/module.nix new file mode 100644 index 0000000..a45e9ef --- /dev/null +++ b/nix/module.nix @@ -0,0 +1,32 @@ +{ + pkgs, + lib, + config, + ... +}: +let + inherit (lib) mkEnableOption mkOption types; + cfg = config.programs.meat; +in +{ + options.programs.meat = { + enable = mkEnableOption "meat"; + flake = mkOption { + type = with types; either path str; + description = "path to your system flake"; + }; + package = mkOption { + type = types.package; + description = "your ideal meat"; + }; + }; + config = lib.mkIf cfg.enable { + environment.sessionVariables.MEATS = cfg.flake; + environment.systemPackages = [ + cfg.package + pkgs.nh # for now.. + pkgs.nix-output-monitor + pkgs.dix + ]; + }; +} diff --git a/test/dune b/test/dune new file mode 100644 index 0000000..249a645 --- /dev/null +++ b/test/dune @@ -0,0 +1,2 @@ +(test + (name test_meat)) diff --git a/test/test_meat.ml b/test/test_meat.ml new file mode 100644 index 0000000..e69de29 From 329dcaf7aef65676c691f86122449cac78d17c9d Mon Sep 17 00:00:00 2001 From: atagen Date: Tue, 19 May 2026 23:39:49 +1000 Subject: [PATCH 44/44] nu --- bin/.ocamlformat | 0 bin/dune | 4 - bin/main.ml | 21 --- dune-project | 26 ---- flake.lock | 26 ++-- flake.nix | 60 ++------- lib/.ocamlformat | 0 lib/commands/cook.ml | 9 -- lib/commands/fresh.ml | 17 --- lib/commands/gut.ml | 5 - lib/commands/help.ml | 1 - lib/commands/hunt.ml | 61 --------- lib/commands/look.ml | 114 ----------------- lib/commands/poke.ml | 9 -- lib/commands/ritual.ml | 39 ------ lib/commands/trade.ml | 8 -- lib/commands/yum.ml | 7 - lib/common.ml | 61 --------- lib/dune | 4 - lib/http.ml | 232 --------------------------------- lib/json.ml | 8 -- lib/meat.ml | 11 -- meat.nu | 285 +++++++++++++++++++++++++++++++++++++++++ meat.opam | 31 ----- nix/default.nix | 38 ++++-- nix/module.nix | 13 +- test/dune | 2 - test/test_meat.ml | 0 28 files changed, 351 insertions(+), 741 deletions(-) delete mode 100644 bin/.ocamlformat delete mode 100644 bin/dune delete mode 100644 bin/main.ml delete mode 100644 dune-project delete mode 100644 lib/.ocamlformat delete mode 100644 lib/commands/cook.ml delete mode 100644 lib/commands/fresh.ml delete mode 100644 lib/commands/gut.ml delete mode 100644 lib/commands/help.ml delete mode 100644 lib/commands/hunt.ml delete mode 100644 lib/commands/look.ml delete mode 100644 lib/commands/poke.ml delete mode 100644 lib/commands/ritual.ml delete mode 100644 lib/commands/trade.ml delete mode 100644 lib/commands/yum.ml delete mode 100644 lib/common.ml delete mode 100644 lib/dune delete mode 100644 lib/http.ml delete mode 100644 lib/json.ml delete mode 100644 lib/meat.ml create mode 100644 meat.nu delete mode 100644 meat.opam delete mode 100644 test/dune delete mode 100644 test/test_meat.ml diff --git a/bin/.ocamlformat b/bin/.ocamlformat deleted file mode 100644 index e69de29..0000000 diff --git a/bin/dune b/bin/dune deleted file mode 100644 index b1f555a..0000000 --- a/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name meat) - (name main) - (libraries meat)) diff --git a/bin/main.ml b/bin/main.ml deleted file mode 100644 index 11c0cca..0000000 --- a/bin/main.ml +++ /dev/null @@ -1,21 +0,0 @@ -open Meat - -let () = - match Sys.getenv_opt "MEATS" with - | Some _ -> - if Array.length Sys.argv >= 2 then - match String.lowercase_ascii (Array.get Sys.argv 1) with - | "yum" -> yum () - | "cook" -> cook () - | "poke" -> poke () - | "gut" -> gut () - | "trade" -> trade () - | "look" -> look () - | "fresh" -> fresh () - | "hunt" -> hunt () - | "ritual" -> ritual () - | _ -> help () - else help () - | None -> - meat_print "NO PATH TO RUNESTONE FOUND!"; - help () diff --git a/dune-project b/dune-project deleted file mode 100644 index 256991c..0000000 --- a/dune-project +++ /dev/null @@ -1,26 +0,0 @@ -(lang dune 3.16) - -(name meat) - -(generate_opam_files true) - -(source - (github username/reponame)) - -(authors "Author Name ") - -(maintainers "Maintainer Name ") - -(license LICENSE) - -(documentation https://url/to/documentation) - -(package - (name meat) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - ("add topics" "to describe" your project))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html diff --git a/flake.lock b/flake.lock index 843a72b..863dc62 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1773478949, - "narHash": "sha256-8rMpSs2OWGaDlDFO5FS6Pf9WutHBXxM2omPr6hfKydI=", + "lastModified": 1779030999, + "narHash": "sha256-PLR0pNxIN3JPs/rSVnXTIPXzkPLaGAdt/wjPq7+k1PE=", "owner": "feel-co", "repo": "ndg", - "rev": "c3bc1541668e6f6632a7005c7e4963c0a5dedc7b", + "rev": "b363612b524436520c85100192ec2bdab9a675c0", "type": "github" }, "original": { @@ -35,11 +35,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1774078191, - "narHash": "sha256-nyxxxW1/2ouu9dU0I02ul5pHrmUrE1JVFhfFlmYe3Lw=", + "lastModified": 1778869304, + "narHash": "sha256-30sZNZoA1cqF5JNO9fVX+wgiQYjB7HJqqJ4ztCDeBZE=", "owner": "nixos", "repo": "nixpkgs", - "rev": "09061f748ee21f68a089cd5d91ec1859cd93d0be", + "rev": "d233902339c02a9c334e7e593de68855ad26c4cb", "type": "github" }, "original": { @@ -51,11 +51,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1773282481, - "narHash": "sha256-oFe06TmOy8UUT1f7xMHqDpSYq2Fy1mkIsXZUvdnyfeY=", - "rev": "fe416aaedd397cacb33a610b33d60ff2b431b127", + "lastModified": 1775036866, + "narHash": "sha256-ByAX1LkhCwZ94+KnFAmnJSMAvui7kgCxjHgUHsWAbfI=", + "rev": "6201e203d09599479a3b3450ed24fa81537ebc4e", "type": "tarball", - "url": "https://releases.nixos.org/nixos/unstable/nixos-26.05pre962285.fe416aaedd39/nixexprs.tar.xz?lastModified=1773282481&rev=fe416aaedd397cacb33a610b33d60ff2b431b127" + "url": "https://releases.nixos.org/nixos/unstable/nixos-26.05pre972949.6201e203d095/nixexprs.tar.xz?lastModified=1775036866&rev=6201e203d09599479a3b3450ed24fa81537ebc4e" }, "original": { "type": "tarball", @@ -64,11 +64,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1774078191, - "narHash": "sha256-nyxxxW1/2ouu9dU0I02ul5pHrmUrE1JVFhfFlmYe3Lw=", + "lastModified": 1778869304, + "narHash": "sha256-30sZNZoA1cqF5JNO9fVX+wgiQYjB7HJqqJ4ztCDeBZE=", "owner": "nixos", "repo": "nixpkgs", - "rev": "09061f748ee21f68a089cd5d91ec1859cd93d0be", + "rev": "d233902339c02a9c334e7e593de68855ad26c4cb", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 33d7c3a..263e27e 100644 --- a/flake.nix +++ b/flake.nix @@ -10,67 +10,26 @@ with inputs; let version = builtins.toString self.lastModified; - collectPkgs = builtins.attrValues; forEachSystem = function: nixpkgs.lib.genAttrs (import nix-systems) ( system: function nixpkgs.legacyPackages.${system} system ); - deps = forEachSystem ( - pkgs: _: { - build = collectPkgs { - inherit (pkgs.ocamlPackages) - dune_3 - ocaml - yojson - ssl - ; - inherit (pkgs.openssl) dev; - }; - dev = collectPkgs { - inherit (pkgs.ocamlPackages) - utop - ocaml-lsp - ocamlformat - ocamlformat-rpc-lib - ; - }; - } - ); in { devShells = forEachSystem ( - pkgs: sys: { + pkgs: _: { default = pkgs.mkShell { - packages = pkgs.lib.mapAttrsToList (_: v: v) deps.${sys}; - shellHook = - let - justFile = '' - default: - @just --list - - @build: - nix build .#debug --offline - - @release: - nix build --offline - - @test: - printf "\\n\\n\\t************ running nix+dune tests ************\\n\\n\\n" - nix flake check --offline - ''; - in - '' - printf '${justFile}' > justfile - ''; + packages = [ + pkgs.nushell + ]; }; } ); packages = forEachSystem ( - pkgs: sys: { + pkgs: _: { default = pkgs.callPackage ./nix/default.nix { - buildInputs = deps.${sys}.build; inherit version; }; docs = pkgs.callPackage unf.lib.pak-chooie { @@ -88,11 +47,18 @@ { pkgs, lib, + config, ... }: + let + cfg = config.programs.meat; + in { imports = [ ./nix/module.nix ]; - programs.meat.package = self.packages.${pkgs.stdenv.hostPlatform.system}.default; + programs.meat.package = self.packages.${pkgs.stdenv.hostPlatform.system}.default.overrideAttrs { + differ = cfg.differ; + monitor = cfg.monitor; + }; }; }; diff --git a/lib/.ocamlformat b/lib/.ocamlformat deleted file mode 100644 index e69de29..0000000 diff --git a/lib/commands/cook.ml b/lib/commands/cook.ml deleted file mode 100644 index 4c79b1c..0000000 --- a/lib/commands/cook.ml +++ /dev/null @@ -1,9 +0,0 @@ -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 diff --git a/lib/commands/fresh.ml b/lib/commands/fresh.ml deleted file mode 100644 index d4c4a52..0000000 --- a/lib/commands/fresh.ml +++ /dev/null @@ -1,17 +0,0 @@ -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 () diff --git a/lib/commands/gut.ml b/lib/commands/gut.ml deleted file mode 100644 index 8a5594c..0000000 --- a/lib/commands/gut.ml +++ /dev/null @@ -1,5 +0,0 @@ -let run () = - print_string Common.header; - Common.meat_print "CLEANING MEAT STORES.."; - Common.do_cmd "nh clean all" |> ignore; - print_string Common.footer diff --git a/lib/commands/help.ml b/lib/commands/help.ml deleted file mode 100644 index f29a0e7..0000000 --- a/lib/commands/help.ml +++ /dev/null @@ -1 +0,0 @@ -let run () = print_string (Common.header ^ Common.help_text ^ Common.footer ^ "\n") diff --git a/lib/commands/hunt.ml b/lib/commands/hunt.ml deleted file mode 100644 index 655feee..0000000 --- a/lib/commands/hunt.ml +++ /dev/null @@ -1,61 +0,0 @@ -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 diff --git a/lib/commands/look.ml b/lib/commands/look.ml deleted file mode 100644 index c1df668..0000000 --- a/lib/commands/look.ml +++ /dev/null @@ -1,114 +0,0 @@ -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 diff --git a/lib/commands/poke.ml b/lib/commands/poke.ml deleted file mode 100644 index 800e39d..0000000 --- a/lib/commands/poke.ml +++ /dev/null @@ -1,9 +0,0 @@ -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 diff --git a/lib/commands/ritual.ml b/lib/commands/ritual.ml deleted file mode 100644 index 739995f..0000000 --- a/lib/commands/ritual.ml +++ /dev/null @@ -1,39 +0,0 @@ -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 sh -c '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 diff --git a/lib/commands/trade.ml b/lib/commands/trade.ml deleted file mode 100644 index 80e6dfa..0000000 --- a/lib/commands/trade.ml +++ /dev/null @@ -1,8 +0,0 @@ -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 diff --git a/lib/commands/yum.ml b/lib/commands/yum.ml deleted file mode 100644 index 08514cc..0000000 --- a/lib/commands/yum.ml +++ /dev/null @@ -1,7 +0,0 @@ -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 diff --git a/lib/common.ml b/lib/common.ml deleted file mode 100644 index ca7ead8..0000000 --- a/lib/common.ml +++ /dev/null @@ -1,61 +0,0 @@ -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 - RITUAL - PERFORM RITUAL THEN CONSUME - 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 sh -c '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) diff --git a/lib/dune b/lib/dune deleted file mode 100644 index 016c372..0000000 --- a/lib/dune +++ /dev/null @@ -1,4 +0,0 @@ -(include_subdirs qualified) -(library - (name meat) - (libraries unix ssl yojson)) diff --git a/lib/http.ml b/lib/http.ml deleted file mode 100644 index f681505..0000000 --- a/lib/http.ml +++ /dev/null @@ -1,232 +0,0 @@ -let read_file path = - let ic = open_in path in - let n = in_channel_length ic in - let s = really_input_string ic n in - close_in ic; - s - -let contains_sub haystack needle = - let hl = String.length haystack and nl = String.length needle in - if nl > hl then false - else - let rec check i = - if i + nl > hl then false - else if String.sub haystack i nl = needle then true - else check (i + 1) - in - check 0 - -let decode_chunked body = - let len = String.length body in - let buf = Buffer.create (len / 2) in - let i = ref 0 in - (try - while !i < len do - let line_end = - let rec find j = - if j >= len then raise Exit else if body.[j] = '\r' then j - else find (j + 1) - in - find !i - in - let size_str = String.sub body !i (line_end - !i) in - let size_str = - match String.index_opt size_str ';' with - | Some idx -> String.sub size_str 0 idx - | None -> size_str - in - let size = int_of_string ("0x" ^ String.trim size_str) in - if size = 0 then raise Exit; - i := line_end + 2; - if !i + size <= len then - Buffer.add_string buf (String.sub body !i size); - i := !i + size + 2 - done - with Exit -> ()); - Buffer.contents buf - -let b64_encode src = - let tbl = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" in - let len = String.length src in - let buf = Buffer.create (len * 4 / 3 + 4) in - let i = ref 0 in - while !i + 2 < len do - let a = Char.code src.[!i] and b = Char.code src.[!i+1] and c = Char.code src.[!i+2] in - Buffer.add_char buf tbl.[(a lsr 2) land 0x3f]; - Buffer.add_char buf tbl.[((a lsl 4) lor (b lsr 4)) land 0x3f]; - Buffer.add_char buf tbl.[((b lsl 2) lor (c lsr 6)) land 0x3f]; - Buffer.add_char buf tbl.[c land 0x3f]; - i := !i + 3 - done; - (match len - !i with - | 2 -> - let a = Char.code src.[!i] and b = Char.code src.[!i+1] in - Buffer.add_char buf tbl.[(a lsr 2) land 0x3f]; - Buffer.add_char buf tbl.[((a lsl 4) lor (b lsr 4)) land 0x3f]; - Buffer.add_char buf tbl.[(b lsl 2) land 0x3f]; - Buffer.add_char buf '=' - | 1 -> - let a = Char.code src.[!i] in - Buffer.add_char buf tbl.[(a lsr 2) land 0x3f]; - Buffer.add_char buf tbl.[(a lsl 4) land 0x3f]; - Buffer.add_string buf "==" - | _ -> ()); - Buffer.contents buf - -let ssl_inited = ref false - -let https_request ~meth ~host ~path ?(headers=[]) ?(body="") () = - if not !ssl_inited then ( - Ssl.init (); - ssl_inited := true); - let he = Unix.gethostbyname host in - let addr = he.h_addr_list.(0) in - let sockaddr = Unix.ADDR_INET (addr, 443) in - let ctx = Ssl.create_context Ssl.TLSv1_2 Ssl.Client_context in - let sock = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in - Unix.connect sock sockaddr; - let ssl = Ssl.embed_socket sock ctx in - Ssl.set_client_SNI_hostname ssl host; - Ssl.connect ssl; - let extra_headers = - List.fold_left (fun acc (k, v) -> acc ^ k ^ ": " ^ v ^ "\r\n") "" headers - in - let content_len = if body <> "" then - Printf.sprintf "Content-Length: %d\r\n" (String.length body) - else "" in - let req = - Printf.sprintf "%s %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: meat/1.0\r\nConnection: close\r\n%s%s\r\n%s" - meth path host extra_headers content_len body - in - ignore (Ssl.write ssl (Bytes.of_string req) 0 (String.length req)); - let buf = Buffer.create 8192 in - let chunk = Bytes.create 4096 in - (try - while true do - let n = Ssl.read ssl chunk 0 4096 in - if n = 0 then raise Exit; - Buffer.add_subbytes buf chunk 0 n - done - with _ -> ()); - (try Ssl.shutdown_connection ssl with _ -> ()); - Unix.close sock; - let response = Buffer.contents buf in - let rlen = String.length response in - let header_end = - let rec find pos = - if pos + 3 >= rlen then rlen - else if - response.[pos] = '\r' - && response.[pos + 1] = '\n' - && response.[pos + 2] = '\r' - && response.[pos + 3] = '\n' - then pos - else find (pos + 1) - in - find 0 - in - let resp_headers = String.sub response 0 header_end in - let body_start = min (header_end + 4) rlen in - let resp_body = String.sub response body_start (rlen - body_start) in - if - contains_sub - (String.lowercase_ascii resp_headers) - "transfer-encoding: chunked" - then decode_chunked resp_body - else resp_body - -let https_get ~host ~path = - https_request ~meth:"GET" ~host ~path - ~headers:[("User-Agent", "git/2.0")] () - -let https_post ~host ~path ~body = - https_request ~meth:"POST" ~host ~path - ~headers:[ - ("Content-Type", "application/json"); - ("Accept", "application/json"); - ("Authorization", "Basic " ^ b64_encode "aWVSALXpZv:X8gPHnzL52wFEekuxsfQ9cSh"); - ] ~body () - -let parse_pktline body = - let len = String.length body in - let i = ref 0 in - let refs = ref [] in - let hex_val c = - match c with - | '0' .. '9' -> Char.code c - Char.code '0' - | 'a' .. 'f' -> Char.code c - Char.code 'a' + 10 - | 'A' .. 'F' -> Char.code c - Char.code 'A' + 10 - | _ -> 0 - in - let read_pkt_len () = - if !i + 4 > len then 0 - else - let a = hex_val body.[!i] - and b = hex_val body.[!i + 1] - and c = hex_val body.[!i + 2] - and d = hex_val body.[!i + 3] in - i := !i + 4; - (a * 4096) + (b * 256) + (c * 16) + d - in - let plen = read_pkt_len () in - if plen > 4 then i := !i + (plen - 4); - ignore (read_pkt_len ()); - let continue = ref true in - while !continue do - let plen = read_pkt_len () in - if plen = 0 then continue := false - else - let payload_len = plen - 4 in - if !i + payload_len <= len && payload_len >= 41 then ( - let payload = String.sub body !i payload_len in - i := !i + payload_len; - let sha = String.sub payload 0 40 in - let rest = String.sub payload 41 (String.length payload - 41) in - let refname = - let s = - match String.index_opt rest '\000' with - | Some idx -> String.sub rest 0 idx - | None -> rest - in - match String.index_opt s '\n' with - | Some idx -> String.sub s 0 idx - | None -> s - in - refs := (refname, sha) :: !refs) - else i := !i + max 0 payload_len - done; - List.rev !refs - -let derelativise base = List.map (fun a -> base ^ "/" ^ a) - -let filter_dirs fullpath dirs = - dirs |> derelativise fullpath - |> List.filter (fun d -> (Unix.stat d).st_kind = Unix.S_DIR) - -let readdir d = try Sys.readdir d with Sys_error _ -> [||] - -let walk entry = - let open List in - let rec loop dir : string list = - let contents = readdir dir |> Array.to_list in - let is_flake = mem "flake.nix" contents in - if dir = entry then - let subdirs = contents |> filter_dirs dir in - flatten (map loop subdirs) - else if is_flake then - let subdirs = contents |> filter_dirs dir in - let children = flatten (map loop subdirs) in - [ dir ] @ children - else [] - in - loop entry - -let countdepth s = - s |> String.fold_left (fun acc el -> acc + if el = '/' then 1 else 0) 0 - -let compdepth a b = - let ad = countdepth a and bd = countdepth b in - let dif = ad - bd in - match dif with 0 -> 0 | _ -> dif / abs dif - -let fmt_dir d = String.split_on_char '/' d |> List.rev |> List.hd |> Common.all_caps diff --git a/lib/json.ml b/lib/json.ml deleted file mode 100644 index 5dd5297..0000000 --- a/lib/json.ml +++ /dev/null @@ -1,8 +0,0 @@ -let parse_json src = Yojson.Basic.from_string src - -let jfield key = function - | `Assoc pairs -> List.assoc_opt key pairs - | _ -> None - -let jstring = function `String s -> Some s | _ -> None -let jassoc = function `Assoc pairs -> Some pairs | _ -> None diff --git a/lib/meat.ml b/lib/meat.ml deleted file mode 100644 index 29a35d1..0000000 --- a/lib/meat.ml +++ /dev/null @@ -1,11 +0,0 @@ -let yum = Commands.Yum.run -let cook = Commands.Cook.run -let poke = Commands.Poke.run -let gut = Commands.Gut.run -let trade = Commands.Trade.run -let look = Commands.Look.run -let fresh = Commands.Fresh.run -let hunt = Commands.Hunt.run -let ritual = Commands.Ritual.run -let help = Commands.Help.run -let meat_print = Common.meat_print diff --git a/meat.nu b/meat.nu new file mode 100644 index 0000000..c0ecbfb --- /dev/null +++ b/meat.nu @@ -0,0 +1,285 @@ +#!/usr/bin/env nu + +const HEADER = " + ----- MEAT ---------------------------------------- +" + +const FOOTER = " + --------------------------------------------------- +" + +const 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 + RITUAL - PERFORM RITUAL THEN CONSUME + TRADE - SEND MEATS FAR AWAY + ..-A - ..ALL MEATS" + +def meat-print [text: string] { + print $"\n \t($text)\n" +} + +def with-frame [body: closure] { + print -n $HEADER + do $body + print -n $FOOTER +} + +def hn []: nothing -> string { + ^hostname | str trim +} + +def flake-target []: nothing -> string { + $"($env.MEATS)#nixosConfigurations.(hn).config.system.build.toplevel" +} + +def system-attr []: nothing -> string { + $"nixosConfigurations.(hn).config.system.build.toplevel" +} + +def nix-conf-attr []: nothing -> string { + $"nixosConfigurations.(hn).config.environment.etc.\"nix/nix.conf\"" +} + +def nix-build-nom [out: string, source: string, attr: string, extras: list = []] { + ^nix-build --log-format internal-json -v --out-link $out $source -A $attr ...$extras out+err>| ^$env.MONITOR --json +} + +def activate [build_path: string] { + ^sudo $nu.current-exe -c $"nix-env --set -p /nix/var/nix/profiles/system ($build_path); ($build_path)/bin/switch-to-configuration switch" +} + +def do-build [extras: list = []] { + let tmpdir = ^mktemp -d -t "meat-build.XXXXXX" | str trim + let build = $"($tmpdir)/build" + nix-build-nom $build $"($env.MEATS)/entry.nix" (system-attr) $extras + ^$env.DIFFER /nix/var/nix/profiles/system $build + activate $build + try { rm $build } +} + +def cmd-help [] { + print -n $"($HEADER)($HELP_TEXT)($FOOTER)\n" +} + +def cmd-yum [...args: string] { + with-frame { + meat-print "CONSUMING DELICIOUS MEATS.." + try { do-build $args } catch { print "FAILED TO CONSUME MEATS." } + } +} + +def cmd-cook [...args: string] { + with-frame { + meat-print "PREPARING DELICIOUS MEATS.." + try { ^nix build --no-link (flake-target) ...$args } + } +} + +def cmd-poke [...args: string] { + with-frame { + meat-print "PREPARING SUSPICIOUS MEATS.." + try { ^nix build --no-link (flake-target) --show-trace ...$args } + } +} + +def cmd-gut [...args: string] { + with-frame { + meat-print "CLEANING MEAT STORES.." + try { ^nh clean all ...$args } + } +} + +def cmd-trade [] { + with-frame { + meat-print "TRADING FOREIGN MEATS.." + meat-print "tbd" + } +} + +def cmd-fresh [...flakes: string] { + with-frame { + meat-print "HUNTING FRESH MEATS.." + let root = $env.MEATS + if ($flakes | is-empty) { + try { ^nix flake update --flake $root } + } else { + for f in $flakes { + if ($f | str downcase) == "meat" { + meat-print "PROCESSING REAL MEAT.." + } else { + meat-print $"PROCESSING FRESH MEAT ($f | str upcase).." + } + try { ^nix flake update $f --flake $root } + } + } + } + print "" +} + +def lookup-input [nodes: record, name: string, node_ref: any] { + let node_name = if (($node_ref | describe) == "string") { $node_ref } else { $name } + let node = $nodes | get $node_name + let locked = $node.locked + let original = $node.original + let url = match $locked.type { + "github" => $"https://github.com/($locked.owner)/($locked.repo).git" + "git" => $original.url + _ => { error make { msg: $"unsupported type: ($locked.type)" } } + } + let target_ref = if ('ref' in $original) { $"refs/heads/($original.ref)" } else { "HEAD" } + let out = ^git ls-remote $url $target_ref | complete + if $out.exit_code != 0 { + error make { msg: "git ls-remote failed" } + } + let first_line = $out.stdout | str trim | lines | get 0? + if ($first_line | is-empty) { + error make { msg: "no refs returned" } + } + let latest = $first_line | split row "\t" | first + { name: $name, locked: $locked.rev, latest: $latest } +} + +def cmd-look [] { + with-frame { + meat-print "LOOK FOR NEW MEATS.." + let lock = open --raw $"($env.MEATS)/flake.lock" | from json + let nodes = $lock.nodes + let root_inputs = $nodes.root.inputs + let stale = $root_inputs | transpose name node_ref | each { |row| + try { + let r = lookup-input $nodes $row.name $row.node_ref + if $r.latest != $r.locked { + meat-print $"($r.name | str upcase) MEAT RIPE!" + $r.name + } else { null } + } catch { + meat-print $"NO FIND ($row.name | str upcase).." + null + } + } | compact + if ($stale | is-empty) { + meat-print "NO MEAT FRESHER" + } + } +} + +def truncate-desc [s: string, n: int]: nothing -> string { + if (($s | str length) > $n) { + ($s | str substring 0..$n) + ".." + } else { + $s + } +} + +def cmd-hunt [...query: string] { + with-frame { + if ($query | is-empty) { + meat-print "WHAT MEAT YOU SEEK?" + return + } + let q = $query | str join " " + meat-print $"HUNTING FOR ($q | str upcase).." + let body = { + 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: $q, + fields: ["package_attr_name^9", "package_pname^6", "package_description^1.3", "package_longDescription^1"] + } } + ] + } + } + } + try { + let resp = ( + http post + --user "aWVSALXpZv" + --password "X8gPHnzL52wFEekuxsfQ9cSh" + --content-type "application/json" + "https://nixos-search-7-1733963800.us-east-1.bonsaisearch.net/nixos-*-unstable-*/_search" + $body + ) + let hits = $resp.hits?.hits? | default [] + if ($hits | is-empty) { + meat-print "NO MEATS FOUND!" + } else { + for hit in $hits { + let src = $hit._source + let name = $src.package_attr_name? | default "?" + let ver = $src.package_pversion? | default "" + let desc = $src.package_description? | default "" + let ver_str = if ($ver | is-empty) { "" } else { $" \(($ver)\)" } + print $" \tnixpkgs#($name)($ver_str)" + if not ($desc | is-empty) { + print $" \t (truncate-desc $desc 60)" + } + } + } + } catch { |e| + meat-print $"HUNT FAILED: ($e.msg)" + } + } +} + +def cmd-ritual [] { + with-frame { + meat-print "PREPARING RITUAL GROUND.." + let tmpdir = ^mktemp -d -t "meat-chew.XXXXXX" | str trim + let meats = $env.MEATS + let nix_conf = $"($tmpdir)/nix.conf" + let build = $"($tmpdir)/build" + try { + nix-build-nom $nix_conf $"($meats)/entry.nix" (nix-conf-attr) + meat-print "CONSUMING MEATS.." + with-env { NIX_USER_CONF_FILES: $nix_conf } { + nix-build-nom $build $"($meats)/entry.nix" (system-attr) + } + ^$env.DIFFER /nix/var/nix/profiles/system $build + activate $build + try { rm $nix_conf } + try { rm $build } + } catch { + print "FAILED TO CONSUME MEATS." + } + } +} + +def cmd-shelter [new_closure: string] { + activate $new_closure +} + +def main [...args: string] { + if ($env.MEATS? | is-empty) { + meat-print "NO PATH TO RUNESTONE FOUND!" + cmd-help + return + } + let sub = $args | get 0? | default "" | str downcase + let rest = $args | skip 1 + match $sub { + "yum" => { cmd-yum ...$rest } + "cook" => { cmd-cook ...$rest } + "poke" => { cmd-poke ...$rest } + "gut" => { cmd-gut ...$rest } + "trade" => { cmd-trade } + "look" => { cmd-look } + "fresh" => { cmd-fresh ...$rest } + "hunt" => { cmd-hunt ...$rest } + "ritual" => { cmd-ritual } + "shelter" => { cmd-shelter $rest } + _ => { cmd-help } + } +} diff --git a/meat.opam b/meat.opam deleted file mode 100644 index f89d30f..0000000 --- a/meat.opam +++ /dev/null @@ -1,31 +0,0 @@ -# This file is generated by dune, edit dune-project instead -opam-version: "2.0" -synopsis: "A short synopsis" -description: "A longer description" -maintainer: ["Maintainer Name "] -authors: ["Author Name "] -license: "LICENSE" -tags: ["add topics" "to describe" "your" "project"] -homepage: "https://github.com/username/reponame" -doc: "https://url/to/documentation" -bug-reports: "https://github.com/username/reponame/issues" -depends: [ - "ocaml" - "dune" {>= "3.16"} - "odoc" {with-doc} -] -build: [ - ["dune" "subst"] {dev} - [ - "dune" - "build" - "-p" - name - "-j" - jobs - "@install" - "@runtest" {with-test} - "@doc" {with-doc} - ] -] -dev-repo: "git+https://github.com/username/reponame.git" diff --git a/nix/default.nix b/nix/default.nix index a6004a4..2215000 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,17 +1,39 @@ { - ocamlPackages, - buildInputs, - git, + lib, + stdenvNoCC, + nushell, + makeBinaryWrapper, version, + differ, + monitor, ... }: -ocamlPackages.buildDunePackage { +stdenvNoCC.mkDerivation { pname = "meat"; version = "0.1-delicious-${version}"; - minimalOCamlVersion = "5.2"; - src = ./..; - nativeBuildInputs = [ git ]; - buildInputs = buildInputs; + + nativeBuildInputs = [ makeBinaryWrapper ]; + + dontBuild = true; + + installPhase = '' + runHook preInstall + install -Dm644 meat.nu $out/share/meat/meat.nu + mkdir -p $out/bin + makeWrapper ${nushell}/bin/nu $out/bin/meat \ + --add-flags "$out/share/meat/meat.nu" \ + --set DIFFER ${ + lib.makeBinPath [ + differ + ] + } + --set MONITOR ${ + lib.makeBinPath [ + monitor + ] + } + runHook postInstall + ''; } diff --git a/nix/module.nix b/nix/module.nix index a45e9ef..b2d6079 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -19,14 +19,21 @@ in type = types.package; description = "your ideal meat"; }; + differ = mkOption { + type = types.package; + description = "diffing tool to use"; + default = pkgs.dix; + }; + monitor = mkOption { + type = types.package; + description = "nix monitoring tool to use"; + default = pkgs.nix-output-monitor; + }; }; config = lib.mkIf cfg.enable { environment.sessionVariables.MEATS = cfg.flake; environment.systemPackages = [ cfg.package - pkgs.nh # for now.. - pkgs.nix-output-monitor - pkgs.dix ]; }; } diff --git a/test/dune b/test/dune deleted file mode 100644 index 249a645..0000000 --- a/test/dune +++ /dev/null @@ -1,2 +0,0 @@ -(test - (name test_meat)) diff --git a/test/test_meat.ml b/test/test_meat.ml deleted file mode 100644 index e69de29..0000000