on fd39d56 help sign in
haskell.nix/modules/package.nix
177 lines 4.6 kB history raw
1# package descriptions in hackage will look like:
2# { system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs }:
3# { flags = { flag1 = false; flags2 = true; ... };
4# package = { specVersion = "X.Y"; identifier = { name = "..."; version = "a.b.c.d"; };
5# license = "..."; copyright = "..."; maintainer = "..."; author = "...";
6# homepage = "..."; url = "..."; synopsis = "..."; description = "...";
7# buildType = "Simple"; # or Custom, Autoconf, ...
8# };
9# components = {
10# "..." = { depends = [ (hsPkgs.base) ... ]; };
11# exes = { "..." = { depends = ... };
12# "..." = { depends = ... }; };
13# tests = { "..." = { depends = ... }; ... };
14# };
16{ lib, config, pkgs, ... }:
18with lib;
19with types;
21let
22 # This is just like listOf, except that it filters out all null elements.
23 listOfFilteringNulls = elemType: listOf elemType // {
24 # Mostly copied from nixpkgs/lib/types.nix
25 merge = loc: defs:
26 map (x: x.value) (filter (x: x ? value && x.value != null) (concatLists (imap1 (n: def:
27 if isList def.value then
28 imap1 (m: def':
29 (mergeDefinitions
30 (loc ++ ["[definition ${toString n}-entry ${toString m}]"])
31 elemType
32 [{ inherit (def) file; value = def'; }]
33 ).optionalValue
34 ) def.value
35 else
36 throw "The option value `${showOption loc}` in `${def.file}` is not a list.") defs)));
37 };
38in {
39 # This is how the Nix expressions generated by *-to-nix receive
40 # their flags argument.
41 config._module.args.flags = config.flags;
43 options = {
44 # TODO: Add descriptions to everything.
45 flags = mkOption {
46 type = attrsOf bool;
47 };
49 package = {
50 specVersion = mkOption {
51 type = str;
52 };
54 identifier.name = mkOption {
55 type = str;
56 };
58 identifier.version = mkOption {
59 type = str;
60 };
62 license = mkOption {
63 type = str;
64 };
66 copyright = mkOption {
67 type = str;
68 };
70 maintainer = mkOption {
71 type = str;
72 };
74 author = mkOption {
75 type = str;
76 };
78 homepage = mkOption {
79 type = str;
80 };
82 url = mkOption {
83 type = str;
84 };
86 synopsis = mkOption {
87 type = str;
88 };
90 description = mkOption {
91 type = str;
92 };
94 buildType = mkOption {
95 type = str;
96 };
97 };
99 components = let
100 componentType = submodule {
101 options = {
102 depends = mkOption {
103 type = listOfFilteringNulls unspecified;
104 default = [];
105 };
106 libs = mkOption {
107 type = listOfFilteringNulls (nullOr package);
108 default = [];
109 };
110 frameworks = mkOption {
111 type = listOfFilteringNulls package;
112 default = [];
113 };
114 pkgconfig = mkOption {
115 type = listOfFilteringNulls package;
116 default = [];
117 };
118 build-tools = mkOption {
119 type = listOfFilteringNulls unspecified;
120 default = [];
121 };
122 configureFlags = mkOption {
123 type = listOfFilteringNulls str;
124 default = [];
125 };
126 };
127 };
128 in {
129 library = mkOption {
130 type = componentType;
131 };
132 sublibs = mkOption {
133 type = attrsOf componentType;
134 default = {};
135 };
136 foreignlibs = mkOption {
137 type = attrsOf componentType;
138 default = {};
139 };
140 exes = mkOption {
141 type = attrsOf componentType;
142 default = {};
143 };
144 tests = mkOption {
145 type = attrsOf componentType;
146 default = {};
147 };
148 benchmarks = mkOption {
149 type = attrsOf componentType;
150 default = {};
151 };
152 };
154 name = mkOption {
155 type = str;
156 default = "${config.package.identifier.name}-${config.package.identifier.version}";
157 defaultText = "\${config.package.identifier.name}-\${config.package.identifier.version}";
158 };
159 sha256 = mkOption {
160 type = nullOr str;
161 default = null;
162 };
163 src = mkOption {
164 type = either path package;
165 default = pkgs.fetchurl { url = "mirror://hackage/${config.name}.tar.gz"; inherit (config) sha256; };
166 defaultText = "pkgs.fetchurl { url = \"mirror://hackage/\${config.name}.tar.gz\"; inherit (config) sha256; };";
167 };
168 revision = mkOption {
169 type = nullOr int;
170 default = null;
171 };
172 revisionSha256 = mkOption {
173 type = nullOr str;
174 default = null;
175 };
176 };