Skip to content

Commit

Permalink
expose graphviz-file arg from nix
Browse files Browse the repository at this point in the history
  • Loading branch information
rizo committed May 28, 2024
1 parent 0258eb9 commit 623a937
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions nix/api.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 }:
Expand Down Expand Up @@ -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 ? { }

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

Expand All @@ -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;
Expand Down Expand Up @@ -325,6 +342,7 @@ in {
constraints = config.constraints;
vars = config.vars;
opamFiles = config.opamFiles;
graphvizPath = config.graphviz-file;
};

pkgs = allPkgs;
Expand Down
8 changes: 6 additions & 2 deletions nix/core.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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} \
Expand Down
2 changes: 1 addition & 1 deletion src/onix_lock_graphviz/Onix_lock_graphviz.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 623a937

Please sign in to comment.