-
Notifications
You must be signed in to change notification settings - Fork 12
/
build-racket.nix
119 lines (115 loc) · 5.33 KB
/
build-racket.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
{ pkgs ? import ./pkgs {}
, callPackage ? pkgs.callPackage
, callPackageFull ? pkgs.callPackageFull
, catalog ? ./catalog.rktd
, racket-package-overlays ? [ (import ./build-racket-racket2nix-overlay.nix) (import ./build-racket-install-check-overlay.nix) (import ./build-racket-default-overlay.nix) ]
, racket-packages ? callPackageFull ./racket-packages.nix {}
}:
callPackage ({buildEnv, cacert, lib, nix, racket2nix, runCommand}: let
default = { inherit catalog racket-package-overlays racket-packages; };
apply-overlays = rpkgs: overlays: if overlays == [] then rpkgs else
apply-overlays (rpkgs.extend (builtins.head overlays)) (builtins.tail overlays);
attrs = rec {
buildThinRacketNix = { package, pname }:
let
sha256 = runCommand "${pname}.sha256" { buildInputs = [ nix ]; inherit package; } ''
printf '%s' $(nix-hash --base32 --type sha256 $package) > $out
'';
path = runCommand pname {
inherit package; outputHashMode = "recursive"; outputHashAlgo = "sha256";
outputHash = builtins.readFile sha256;
preferLocalBuild = true;
allowSubstitutes = false;
} ''
cp -a $package $out
'';
in runCommand "${pname}.nix" {
buildInputs = [ cacert racket2nix nix ];
inherit path;
preferLocalBuild = true;
allowSubstitutes = false;
} ''
racket2nix --thin $path > $out
'';
buildThinRacket = { package, racket-packages ? default.racket-packages
, overlays ? default.racket-package-overlays
, attrOverrides ? (oldAttrs: {})
, pname ? builtins.readFile (runCommand "pname" {
inherit package;
preferLocalBuild = true;
allowSubstitutes = false;
} ''
printf '%s' $(basename $(stripHash "$package")) > $out
'')
}: let
base = { inherit pname racket-packages overlays; }; in let
nix = buildThinRacketNix { inherit package pname; };
overlays = base.overlays ++ [ (import nix) ];
racket-packages = apply-overlays base.racket-packages overlays;
buildEnv = buildEnv rec {
name = "${pname}-env";
buildInputs = [ self ] ++ (self.propagatedBuildInputs or []);
paths = buildInputs;
};
self = (racket-packages."${pname}".overrideAttrs (oldAttrs: {
passthru = oldAttrs.passthru or {} // { inherit nix overlays racket-packages buildEnv; };
})).overrideAttrs attrOverrides;
in self;
buildThinRacketPackage = package: buildThinRacket { inherit package; };
buildRacketNix = { catalog, flat, package, pname ? "racket-package" }:
runCommand "${pname}.nix" {
inherit package;
buildInputs = [ cacert racket2nix nix ];
flatArg = lib.optionalString flat "--flat";
preferLocalBuild = true;
allowSubstitutes = false;
} ''
racket2nix $flatArg --catalog ${catalog} $package > $out
'';
buildRacket = lib.makeOverridable ({ catalog ? default.catalog, flat ? false, package, pname ? false
, attrOverrides ? (oldAttrs: {}), overlays ? default.racket-package-overlays
, buildNix ? !(builtins.isString package) || flat
}:
let
nix = if !buildNix then null else
buildRacketNix { inherit catalog flat package; } // lib.optionalAttrs (builtins.isString pname) { inherit pname; };
self = let
pname = if buildNix then ((callPackageFull nix {}).overrideAttrs attrOverrides).pname else package;
rpkgs = if buildNix then (callPackageFull nix {}).racket-packages else default.racket-packages;
racket-packages = apply-overlays rpkgs overlays;
in
(racket-packages."${pname}".overrideAttrs (oldAttrs: {
passthru = oldAttrs.passthru or {} // { inherit racket-packages; };
})).overrideAttrs attrOverrides;
in self // {
# We put the deps both in paths and buildInputs, so you can use this either as just
# nix-shell -A buildEnv
# and get the environment-variable-only environment, or you can use it as
# nix-shell -p $(nix-build -A buildEnv)
# and get the symlink tree environment.
buildEnv = buildEnv rec {
name = "${self.pname}-env";
buildInputs = [ self ] ++ (self.propagatedBuildInputs or []);
paths = buildInputs;
};
inherit nix;
} //
lib.optionalAttrs (! flat) { flat = buildRacket { inherit catalog package; flat = true; }; }
);
buildRacketPackage = package: buildRacket { inherit package; };
buildRacketCatalog = packages: let
buildOneCatalog = package: runCommand "subcatalog.rktd" {
buildInputs = [ cacert racket2nix nix ];
inherit catalog package packages;
} ''
racket2nix --export-catalog --no-process-catalog --catalog $catalog $package $packages --export-catalog > $out
'';
in runCommand "catalog.rktd" {
buildInputs = [ cacert racket2nix nix ];
catalogs = map buildOneCatalog packages;
} ''
racket2nix --export-catalog --no-process-catalog $(printf -- '--catalog %s ' $catalogs) > $out
'';
};
in
attrs) {}