This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
forked from purs-nix/purs-nix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-pkgs.nix
155 lines (142 loc) · 4.58 KB
/
build-pkgs.nix
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
with builtins;
{ pkgs, utils }:
let
l = p.lib; p = pkgs; u = utils;
build =
{ name
, ...
}@args:
if l.hasAttrByPath [ "src" "flake" ] args then
l.recursiveUpdate
(getFlake args.src.flake.url)
.packages
.${p.system}
.${args.src.flake.package or "default"}
{ purs-nix-info = { inherit name; } // args.src; }
else
let
legacy =
l.warnIf (args?repo)
''
Package: "${name}" is being specified with a deprecated API.
see: https://github.com/purs-nix/purs-nix/blob/ps-0.15/docs/adding-packages.md
''
args?repo;
ref =
let
get-ref = a: b:
a.ref
or (if b?version then "refs/tags/v" + b.version
else null
);
in
if legacy
then get-ref args args
else get-ref args.src.git args.info;
info' = args.info or null;
src =
let
fetch-git = { repo, rev, ... }:
fetchGit
({ url = repo;
inherit rev;
}
// (if ref == null then {} else { inherit ref; })
);
in
if legacy then
fetch-git args
else
let src' = args.src; in
if src'?git then
fetch-git src'.git
else if src'?path then
filterSource
(path: type:
type == "directory"
|| l.hasSuffix ".purs" path
|| l.hasSuffix ".js" path
|| (if isPath info'
then l.hasSuffix (toString args.info) path
else false
)
)
src'.path
else
abort "'src' has no 'flake', 'git', or 'path' attribute";
info =
if isPath info' then
let
check-arg = "_accepts-future-args-check";
f = import (src + toString info');
in
if (l.functionArgs f)?${check-arg} then
abort "${name}: The info function expects a '${check-arg}' attribute. The purpose of this attribute is to ensure the info function will not break if new arguments are added. If you're encountering this error, it's likely the fix you're looking for is to use the `...` syntax."
else
f { inherit build ps-pkgs ps-pkgs-ns pkgs;
inherit (l) licenses;
# make sure the function can accept new arguments in the future
${check-arg} = null;
}
else if legacy then
args
else
args.info;
dependencies = info.dependencies or [];
ps-src = info.src or "src";
version = info.version or null;
add-optional = attribute:
if info?${attribute} then { ${attribute} = info.${attribute}; } else {};
in
p.stdenv.mkDerivation
({ inherit src;
phases = [ "unpackPhase" "installPhase" ];
passthru =
{ purs-nix-info =
{ inherit dependencies name;
src = ps-src;
}
// (if legacy then
{ inherit (args) repo rev; }
else if args.src?git then
{ inherit (args.src.git) repo rev; }
else if l.hasAttrByPath [ "pursuit" "repo" ] info then
{ inherit (info.pursuit) repo; }
else
{}
)
// add-optional "version"
// add-optional "foreign"
// add-optional "pursuit";
};
installPhase =
(if legacy then args else info).install or "ln -s $src/${ps-src} $out";
}
// u.make-name name version
);
build-set = f:
l.fix
(self:
mapAttrs
(n: v: build (v // { name = n; }))
(f self)
);
ps-pkgs =
build-set
(import ./ps-pkgs.nix { inherit ps-pkgs-ns; });
ps-pkgs-ns =
let
f = self:
import ./ps-pkgs-ns.nix
{ inherit ps-pkgs;
ps-pkgs-ns = self;
};
in
l.fix
(self:
mapAttrs
(ns: mapAttrs (n: v: build (v // { name = "${ns}.${n}"; })))
(f self)
);
in
{ inherit build build-set ps-pkgs ps-pkgs-ns; }