From 83c10b12d3818446cdbed4adba9af83ae8344965 Mon Sep 17 00:00:00 2001 From: Bruno Bigras Date: Wed, 2 Jun 2021 14:28:23 -0400 Subject: [PATCH] rust: add hasLibraries and hasIncludes --- extra/language/rust.nix | 44 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/extra/language/rust.nix b/extra/language/rust.nix index e0c7504b..d6caf7c9 100644 --- a/extra/language/rust.nix +++ b/extra/language/rust.nix @@ -1,10 +1,26 @@ { lib, config, pkgs, ... }: let cfg = config.language.rust; + strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; }; + + hasLibraries = lib.length cfg.libraries > 0; + hasIncludes = lib.length cfg.includes > 0; in with lib; { options.language.rust = { + libraries = mkOption { + type = types.listOf strOrPackage; + default = [ ]; + description = "Use this when another language dependens on a dynamic library"; + }; + + includes = mkOption { + type = types.listOf strOrPackage; + default = [ ]; + description = "Rust dependencies from nixpkgs"; + }; + packageSet = mkOption { # FIXME: how to make the selection possible in TOML? type = types.attrs; @@ -30,8 +46,32 @@ with lib; # Used by tools like rust-analyzer name = "RUST_SRC_PATH"; value = toString cfg.packageSet.rustPlatform.rustLibSrc; - }]; + }] + ++ + (lib.optionals hasLibraries [ + { + name = "LD_LIBRARY_PATH"; + prefix = "$DEVSHELL_DIR/lib"; + } + ]) + ++ lib.optionals hasIncludes [ + { + name = "LD_INCLUDE_PATH"; + prefix = "$DEVSHELL_DIR/include"; + } + { + name = "PKG_CONFIG_PATH"; + prefix = "$DEVSHELL_DIR/lib/pkgconfig"; + } + ]; - devshell.packages = map (tool: cfg.packageSet.${tool}) cfg.tools; + devshell.packages = + (lib.optionals hasLibraries (map lib.getLib cfg.libraries)) + ++ + # Assume we want pkg-config, because it's good + (lib.optionals hasIncludes ([ pkgs.pkg-config ] ++ (map lib.getDev cfg.includes))) + ++ + (map (tool: cfg.packageSet.${tool}) cfg.tools) + ; }; }