mirror of
https://git.sr.ht/~bryan_bennett/flake_env
synced 2025-12-18 15:31:24 +01:00
Add flake input tracking
and restructure the whole codebase! Not fully tested due to #4; theoretically resolves #1
This commit is contained in:
parent
e3688e207e
commit
6ec3bd2378
7 changed files with 175 additions and 124 deletions
48
lib/flake_env__watches.re
Normal file
48
lib/flake_env__watches.re
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
open Core;
|
||||
open Yojson.Safe.Util;
|
||||
|
||||
module Unix = Core_unix;
|
||||
module StringSet = Set.Make(String);
|
||||
module Util = Flake_env__util;
|
||||
|
||||
[@deriving yojson]
|
||||
type watch = {
|
||||
exists: bool,
|
||||
modtime: int,
|
||||
path: string
|
||||
};
|
||||
|
||||
[@deriving yojson]
|
||||
type watches = array<watch>;
|
||||
|
||||
let get = () => {
|
||||
let direnv_watch_str = Sys.getenv("DIRENV_WATCHES") |> Option.value_exn(~message="Environment missing DIRENV_WATCHES");
|
||||
let proc_info = Unix.create_process(~prog="direnv", ~args=["show_dump", direnv_watch_str]);
|
||||
let sub_stdout = Unix.in_channel_of_descr(proc_info.stdout);
|
||||
|
||||
switch (Unix.waitpid(proc_info.pid)) {
|
||||
| Ok() => Ok(watches_of_yojson(Yojson.Safe.from_channel(sub_stdout)))
|
||||
| _ => Error("Failed to parse watches")
|
||||
}
|
||||
};
|
||||
|
||||
let get_path = (doc) => String.drop_prefix(doc |> member("path") |> to_string, 11);
|
||||
|
||||
let rec get_paths_from_doc = (doc, paths) => {
|
||||
let p = get_path(doc);
|
||||
let sub_paths = List.concat(
|
||||
doc |> member("inputs")
|
||||
|> to_assoc
|
||||
|> List.map(~f=((_k, v)) => get_paths_from_doc(v, paths)));
|
||||
List.concat([[p], sub_paths])
|
||||
};
|
||||
|
||||
let get_input_paths = () => {
|
||||
switch (Util.nix(["flake", "archive", "--json", "--no-write-lock-file"])) {
|
||||
| (Ok(), output) => get_paths_from_doc(Yojson.Safe.from_string(output), [])
|
||||
| (Error(_), _) => {
|
||||
Printf.eprintf("Failed to parse output of `nix flake archive --json`. Ignorning flake inputs. \n");
|
||||
[]
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue