From 623a93754358d9d5cdc6550240638ec437998432 Mon Sep 17 00:00:00 2001 From: Rizo Date: Tue, 28 May 2024 10:26:50 +0100 Subject: [PATCH] expose graphviz-file arg from nix --- README.md | 4 ++++ nix/api.nix | 18 ++++++++++++++++++ nix/core.nix | 8 ++++++-- src/onix_lock_graphviz/Onix_lock_graphviz.ml | 2 +- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c8863a7..859565b 100644 --- a/README.md +++ b/README.md @@ -270,6 +270,10 @@ onix.env { # Example: `opam-lock = ./my-project.opam.locked;` opam-lock = null; + # The path to the graphviz "dot" file with a dependency graph. + # Example: `graphviz-file = ./onix-lock.dot;` + graphviz-file = null; + # Package variables. vars = { "with-test" = false; diff --git a/nix/api.nix b/nix/api.nix index ea56de2..1e0ddb2 100644 --- a/nix/api.nix +++ b/nix/api.nix @@ -34,6 +34,10 @@ let "onix: env-file argument must be a path or a null value, found: ${ builtins.toJSON envFile }"; + errInvalidGraphvizFile = path: + "onix: graphviz-file argument must be a path or a null value, found: ${ + builtins.toJSON path + }"; errInvalidVars = "onix: vars argument must be an attrset"; errInvalidOverlay = "onix: overlay must be a function or a null value"; errRequiredRootPath = @@ -144,6 +148,12 @@ let else throw errInvalidOverlay; + validateGraphvizFile = path: + if isString path || isPath path || isNull path then + path + else + throw (errInvalidGraphvizFile path); + # Process arguments. processRootPath = { gitignore, rootPath }: @@ -256,6 +266,11 @@ in { # The path to the opam lock file. , opam-lock ? null + # The path to the graphviz "dot" file that will be generated. This file + # will contain the dependency tree graph. If "null" (the default), the file will + # not be generated. + , graphviz-file ? null + # Package variables. , vars ? { } @@ -276,6 +291,7 @@ in { vars = validateVars vars; env-file = validateEnvFile env-file; opam-lock = validateLock opam-lock; + graphviz-file = validateGraphvizFile graphviz-file; overlay = validateOverlay overlay; }; @@ -292,6 +308,7 @@ in { processPathRelativeToRoot validatedArgs.rootPath validatedArgs.lock; opam-lock = processPathRelativeToRoot validatedArgs.rootPath validatedArgs.opam-lock; + graphviz-file = processPathRelativeToRoot validatedArgs.rootPath validatedArgs.graphviz-file; vars = processVars validatedArgs.vars; env-file = processPathRelativeToRoot validatedArgs.rootPath validatedArgs.env-file; @@ -325,6 +342,7 @@ in { constraints = config.constraints; vars = config.vars; opamFiles = config.opamFiles; + graphvizPath = config.graphviz-file; }; pkgs = allPkgs; diff --git a/nix/core.nix b/nix/core.nix index b3d4e18..8644c15 100644 --- a/nix/core.nix +++ b/nix/core.nix @@ -283,7 +283,7 @@ let in { lock = - { lockPath, opamLockPath, opamFiles, repositoryUrls, constraints, vars }: + { lockPath, opamLockPath, opamFiles, repositoryUrls, constraints, vars, graphvizPath }: let repositoryUrlsArg = lib.strings.concatStringsSep "," (map (repositoryUrl: if repositoryUrl ? "rev" then @@ -308,11 +308,15 @@ in { " --lock-file=${lockPath}"; opamLockPathOpt = if isNull opamLockPath then "" else " --opam-lock-file=${opamLockPath}"; + graphvizPathOpt = if isNull graphvizPath then + "" + else + " --graphviz-file=${graphvizPath}"; in pkgs.mkShell { buildInputs = [ onix ]; shellHook = '' - onix lock${lockPathOpt}${opamLockPathOpt} \ + onix lock${lockPathOpt}${opamLockPathOpt}${graphvizPathOpt} \ --repository-urls='${repositoryUrlsArg}' \ --resolutions='${mkResolutionsArg constraints}' \ --with-test=${builtins.toJSON vars.with-test} \ diff --git a/src/onix_lock_graphviz/Onix_lock_graphviz.ml b/src/onix_lock_graphviz/Onix_lock_graphviz.ml index 524a554..f9fef27 100644 --- a/src/onix_lock_graphviz/Onix_lock_graphviz.ml +++ b/src/onix_lock_graphviz/Onix_lock_graphviz.ml @@ -56,4 +56,4 @@ let gen ~graphviz_file_path (lock_file : Lock_file.t) = let out = Format.formatter_of_out_channel chan in Fmt.pf out "%a" pp pkgs); Logs.info (fun log -> - log "Created an opam lock file at %S." graphviz_file_path) + log "Created an graphviz file at %S." graphviz_file_path)