#!/usr/bin/env nu # reflection/modules/env.nu — environment bootstrap for ontoref. # Sets: ONTOREF_ROOT, NICKEL_IMPORT_PATH, ONTOREF_ACTOR export-env { let root = ( $env.CURRENT_FILE | path expand # canonicalize — resolves ".." from relative `use ../modules/env.nu` paths | path dirname # reflection/modules | path dirname # reflection | path dirname # ) $env.ONTOREF_ROOT = $root if ($env.NICKEL_IMPORT_PATH? | is-empty) { let config_file = $"($root)/.ontoref/config.ncl" # Guard: config must exist and nickel must be in PATH before reading let paths = if ($config_file | path exists) and (which nickel | is-not-empty) { do { ^nickel export $config_file } | complete | if $in.exit_code == 0 { $in.stdout | from json | get nickel_import_paths | each { |p| $"($root)/($p)" } } else { [$root] } } else { [$root] } $env.NICKEL_IMPORT_PATH = ($paths | str join ":") } # Always ensure ~/.config/ontoref/schemas/ is on the import path when present. # `just install-daemon` places ontoref-project.ncl there; consumer .ontoref/project.ncl # files import it by bare name. Done unconditionally because the bash wrapper may # have pre-set NICKEL_IMPORT_PATH without including this canonical schemas dir. let schemas_dir = ($env.HOME | path join ".config" "ontoref" "schemas") if ($schemas_dir | path exists) and (not ($env.NICKEL_IMPORT_PATH | str contains $schemas_dir)) { $env.NICKEL_IMPORT_PATH = $"($env.NICKEL_IMPORT_PATH):($schemas_dir)" } if ($env.ONTOREF_ACTOR? | is-empty) { $env.ONTOREF_ACTOR = "developer" } }