-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathc.nix
More file actions
71 lines (66 loc) · 1.61 KB
/
c.nix
File metadata and controls
71 lines (66 loc) · 1.61 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
{
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
{
options.language.c = with lib; {
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 = "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
]
++ (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)));
env =
(lib.optionals hasLibraries [
{
name = "LD_LIBRARY_PATH";
prefix = "$DEVSHELL_DIR/lib";
}
{
name = "LDFLAGS";
eval = "-L$DEVSHELL_DIR/lib";
}
{
name = "LIBRARY_PATH";
eval = "-L$DEVSHELL_DIR/lib";
}
])
++ lib.optionals hasIncludes [
{
name = "C_INCLUDE_PATH";
prefix = "$DEVSHELL_DIR/include";
}
{
name = "PKG_CONFIG_PATH";
prefix = "$DEVSHELL_DIR/lib/pkgconfig";
}
];
};
}