diff --git a/extra/language/c.nix b/extra/language/c.nix index 413c69e9..103c1ef6 100644 --- a/extra/language/c.nix +++ b/extra/language/c.nix @@ -9,52 +9,67 @@ in with lib; { options.language.c = { + compiler = mkOption { + type = strOrPackage; + default = pkgs.clang; + defaultText = "pkgs.clang"; + description = '' + Which C compiler to use. + + For gcc, use pkgs.gcc-unwrapped. + ''; + }; + + linker = mkOption { + type = strOrPackage; + default = pkgs.binutils; + defaultText = "pkgs.binutils"; + description = "Which linker package to use"; + }; + libraries = mkOption { type = types.listOf strOrPackage; default = [ ]; description = "Use this when another language dependens on a dynamic library"; + example = lib.literalExample '' + [ pkgs.glibc ] + ''; }; + pkg-config = mkEnableOption "use pkg-config"; + includes = mkOption { type = types.listOf strOrPackage; default = [ ]; description = "C dependencies from nixpkgs"; }; - compiler = mkOption { - type = strOrPackage; - default = pkgs.clang; - defaultText = "pkgs.clang"; - description = "Which C compiler to use"; - }; }; config = { devshell.packages = - [ cfg.compiler ] + [ cfg.compiler cfg.linker ] ++ (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))) + (lib.optional cfg.pkg-config pkgs.pkg-config) ; env = (lib.optionals hasLibraries [ { - name = "LD_LIBRARY_PATH"; - prefix = "$DEVSHELL_DIR/lib"; + name = "LIBRARY_PATH"; + value = lib.concatStringsSep ":" (map (x: "${lib.getLib x}/lib") cfg.libraries); } ]) - ++ lib.optionals hasIncludes [ - { - name = "LD_INCLUDE_PATH"; - prefix = "$DEVSHELL_DIR/include"; - } - { - name = "PKG_CONFIG_PATH"; - prefix = "$DEVSHELL_DIR/lib/pkgconfig"; - } - ]; + ++ (lib.optional hasIncludes { + name = "LD_INCLUDE_PATH"; + prefix = "$DEVSHELL_DIR/include"; + }) + ++ (lib.optional cfg.pkg-config { + name = "PKG_CONFIG_PATH"; + value = lib.concatStringsSep ":" (map (x: "${lib.getLib x}/lib/pkgconfig") cfg.libraries); + }) + ; }; }