diff --git a/nixd/lib/Controller/LifeTime.cpp b/nixd/lib/Controller/LifeTime.cpp index fb693ca1a..2b44cdf23 100644 --- a/nixd/lib/Controller/LifeTime.cpp +++ b/nixd/lib/Controller/LifeTime.cpp @@ -36,6 +36,20 @@ opt DefaultNixOSOptionsExpr{ "= (import ) ++ [ ({...}: { " "nixpkgs.hostPlatform = builtins.currentSystem;} ) ] ; })).options")}; +opt DefaultDevenvOptionsExpr{ + "devenv-options-expr", + desc("Default expression interpreted as devenv option declarations"), + cat(NixdCategory), + init("let\n" + " currentSystem = builtins.currentSystem;\n" + " flake = builtins.getFlake \"github:cachix/devenv\";\n" + "in\n" + " if builtins.hasAttr currentSystem flake.outputs.packages\n" + " then " + "flake.outputs.packages.${currentSystem}.devenv-module-options." + "options\n" + " else {}")}; + opt EnableSemanticTokens{"semantic-tokens", desc("Enable/Disable semantic tokens"), init(true), cat(NixdCategory)}; @@ -48,6 +62,18 @@ std::string getDefaultNixpkgsExpr() { return DefaultNixpkgsExpr; } +// Check if devenv executable is present +bool isDevenvAvailable() { + return std::system("which devenv > /dev/null 2>&1") == 0; +} + +std::string getDefaultDevenvOptionsExpr() { + if (LitTest && !DefaultDevenvOptionsExpr.getNumOccurrences()) { + return "{ }"; + } + return DefaultDevenvOptionsExpr; +} + std::string getDefaultNixOSOptionsExpr() { if (LitTest && !DefaultNixOSOptionsExpr.getNumOccurrences()) { return "{ }"; @@ -192,6 +218,20 @@ void Controller:: Err.takeError()); std::exit(-1); } + + // Launch devenv worker only if devenv is available + if (isDevenvAvailable()) { + std::lock_guard _(OptionsLock); + startOption("devenv", Options["devenv"]); + + if (AttrSetClient *Client = Options["devenv"]->client()) { + evalExprWithProgress(*Client, getDefaultDevenvOptionsExpr(), + "devenv options"); + } + } else { + lspserver::log("devenv not found, skipping devenv initialization"); + } + fetchConfig(); }