remove reliance on nh for most things

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

View File

@ -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 ()

220
flake.lock generated
View File

@ -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"
}
}
},

190
flake.nix
View File

@ -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;
};
};
}

View File

@ -2,65 +2,78 @@ let header = "\n ----- MEAT ----------------------------------------\n"
let footer = "\n ---------------------------------------------------\n"
let help =
"\n\
\tYUM - CONSUME DELICIOUS MEATS\n\
\tCOOK - ONLY PREPARE MEATS\n\
\tPOKE - TASTE SUSPICIOUS MEATS\n\
\tGUT - CLEAN MEAT STORES\n\
\tLOOK - INSPECT MEAT\n\
\tFRESH - HUNT FRESH MEATS\n\
\t..N - ..MEATS OF N\n\
\t..-S N - ..SUBMEAT N\n\
\t..-A - ..ALL MEATS\n"
{|
YUM - CONSUME DELICIOUS MEATS
COOK - ONLY PREPARE MEATS
POKE - TASTE SUSPICIOUS MEATS
GUT - CLEAN MEAT STORES
FRESH - HUNT FRESH MEATS
..-A - ..ALL MEATS|}
(* \tLOOK - LOOK FOR FRESHER MEATS *)
open Sys
(* TODO rewrite all of this to use its own build and activation routines *)
(* pipe into nom for user output, then use dix at the end *)
let pass_args () =
let len = Array.length argv and sconcat acc el = acc ^ " " ^ el in
match len with
| 3 -> argv.(2)
| n when n > 3 ->
print_int (n - 1);
Array.fold_left sconcat "" (Array.sub argv 2 (n - 2))
Array.fold_left sconcat " " (Array.sub argv 2 (n - 2))
| _ -> ""
let do_cmd ?(args = true) cmd =
match command (if args then cmd ^ pass_args () else cmd) with _ -> ()
match command (if args then cmd ^ " " ^ pass_args () else cmd) with | 0 -> Ok(()) | e -> Error(e)
let meat_print text = print_endline ("\n \t" ^ text ^ "\n")
let do_build () =
let (>>=) = Result.bind in
let (>|=) = Fun.flip Result.map in
let tmpdir = Filename.temp_dir "meat-build" "" in
let build_target = Unix.getenv "MEATS" ^ "#nixosConfigurations." ^ Unix.gethostname () ^ ".config.system.build.toplevel" in
do_cmd @@ "nix build --out-link " ^ tmpdir ^ "/build " ^ build_target >>=
fun () -> do_cmd @@ "sudo " ^ tmpdir ^ "/build/bin/switch-to-configuration switch" >>=
fun () -> do_cmd @@ "sudo " ^ tmpdir ^ "/build/bin/switch-to-configuration boot" >|=
fun () -> Unix.unlink @@ tmpdir ^ "/build"
let yum () =
print_string header;
meat_print "CONSUMING DELICIOUS MEATS..";
do_cmd "nh os switch";
print_string footer
do_build () |> function | Error _ -> print_string "FAILED TO CONSUME MEATS"; print_string footer | _ -> print_string footer
let cook () =
print_string header;
meat_print "PREPARING DELICIOUS MEATS..";
do_cmd "nh os build";
let build_target = Unix.getenv "MEATS" ^ "#nixosConfigurations." ^ Unix.gethostname () ^ ".config.system.build.toplevel" in
do_cmd @@ "nix build --no-link" ^ build_target |> ignore;
print_string footer
let poke () =
print_string header;
meat_print "PREPARING SUSPICIOUS MEATS..";
do_cmd "nh os build -- --show-trace";
let build_target = Unix.getenv "MEATS" ^ "#nixosConfigurations." ^ Unix.gethostname () ^ ".config.system.build.toplevel" in
do_cmd @@ "nix build --no-link" ^ build_target ^ " --show-trace" |> ignore;
print_string footer
let gut () =
print_string header;
meat_print "CLEANING MEAT STORES..";
do_cmd "nh clean all";
do_cmd "nh clean all" |> ignore;
print_string footer
let look () =
print_string header;
meat_print "INSPECTING MEAT..";
meat_print "CONSUMING MEATS:";
do_cmd "nix flake metadata $NH_FLAKE";
meat_print "PRODUCING MEATS:";
do_cmd "nix flake show $NH_FLAKE";
print_string footer
(* TODO pending fuiska lib.. *)
(* let look () = *)
(* print_string header; *)
(* meat_print "INSPECTING MEAT.."; *)
(* meat_print "CONSUMING MEATS:"; *)
(* let meats = Unix.getenv "MEATS" in *)
(* do_cmd @@ "nix flake metadata" ^ meats |> ignore; *)
(* meat_print "PRODUCING MEATS:"; *)
(* do_cmd "nix flake show $MEATS"; *)
(* print_string footer; *)
(* let all_flag () = Array.mem "-a" argv || Array.mem "--all" argv
let sub_flag () = Array.mem "-s" argv || Array.mem "--subflake" argv *)
@ -114,13 +127,13 @@ let submeats s =
s
|> List.iter (fun d ->
meat_print ("PROCESSING SUBMEAT " ^ fmt_dir d ^ "..");
do_cmd ~args:false ("nix flake update --flake " ^ d))
do_cmd ~args:false @@ "nix flake update --flake " ^ d |> ignore)
let fresh () =
print_string header;
meat_print "HUNTING FRESH MEATS..";
let argv_len = Array.length argv in
let root = Sys.getenv "NH_FLAKE" in
let root = Sys.getenv "MEATS" in
let base_dir = root ^ "/flakes" in
(match (sub_flag (), all_flag ()) with
| false, false ->
@ -132,14 +145,14 @@ let fresh () =
|> iter (fun f ->
if all_low f = "meat" then meat_print "PROCESSING REAL MEAT.."
else meat_print ("PROCESSING FRESH MEAT " ^ all_caps f ^ "..");
do_cmd ~args:false ("nix flake update " ^ f ^ " --flake " ^ root))
else do_cmd ("nix flake update --flake " ^ root)
do_cmd ~args:false @@ "nix flake update " ^ f ^ " --flake " ^ root |> ignore)
else do_cmd @@ "nix flake update --flake " ^ root |> ignore
| _, true ->
(* all flag, update all subflakes and main flake inputs *)
walk base_dir |> List.sort compdepth |> List.rev |> submeats;
print_string footer;
meat_print "PROCESSING FRESH MEATS..";
do_cmd ~args:false ("nix flake update --flake " ^ root)
do_cmd ~args:false @@ "nix flake update --flake " ^ root |> ignore
| true, _ when argv_len >= 4 ->
(* sub flag, update inputs as subflakes *)
let subflakes =
@ -155,8 +168,8 @@ let fresh () =
meat_print "PROCESSING FRESH MEATS..";
subflakes
|> iter (fun f ->
do_cmd ~args:false
("nix flake update " ^ all_low f ^ " --flake $NH_FLAKE"))
do_cmd ~args:false @@
"nix flake update " ^ all_low f ^ " --flake $MEATS" |> ignore)
| _ -> print_string help);
print_string footer;
print_newline ()

View File

@ -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;
}

View File

@ -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;
};
}

View File

@ -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..
];
};
}