-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathc.nix
More file actions
75 lines (66 loc) · 1.82 KB
/
c.nix
File metadata and controls
75 lines (66 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{ lib, config, pkgs, ... }:
let
cfg = config.language.c;
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.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";
};
};
config = {
devshell.packages =
[ cfg.compiler cfg.linker ]
++
(lib.optionals hasLibraries (map lib.getLib cfg.libraries))
++
(lib.optional cfg.pkg-config pkgs.pkg-config)
;
env =
(lib.optionals hasLibraries [
{
name = "LIBRARY_PATH";
value = lib.concatStringsSep ":" (map (x: "${lib.getLib x}/lib") cfg.libraries);
}
])
++ (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);
})
;
};
}