-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
148 lines (138 loc) · 4.84 KB
/
default.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
{ pkgsFunc ? import (import dep/alamgu/thunk.nix + "/dep/nixpkgs")
, localSystem ? { system = builtins.currentSystem; }
, pkgs ? pkgsFunc { inherit localSystem; }
, nodejs ? pkgs.nodejs
}:
let
inherit (pkgs) lib;
yarn2nix = import ./dep/yarn2nix { inherit pkgs; };
inherit (import (import ./dep/alamgu/thunk.nix) {}) thunkSource;
yarnDepsNix = pkgs.runCommand "yarn-deps.nix" {} ''
${yarn2nix}/bin/yarn2nix --offline \
<(sed -e '/hw-app-alamgu/,/^$/d' ${./yarn.lock}) \
> $out
'';
yarnPackageNix = pkgs.runCommand "yarn-package.nix" {} ''
# We sed hw-app-alamgu to a constant here, so that the package.json can be whatever; we're overriding it anyways.
${yarn2nix}/bin/yarn2nix --template \
<(sed 's/"hw-app-alamgu".*$/"hw-app-alamgu": "0.1.1",/' ${./package.json}) \
> $out
'';
nixLib = yarn2nix.nixLib;
localOverrides = self: super:
let
registries = {
yarn = n: v: "https://registry.yarnpkg.com/${n}/-/${n}-${v}.tgz";
};
y = registries.yarn;
s = self;
in {
"usb@^2.9.0" = {
inherit (super."usb@^2.9.0") key;
drv = super."usb@^2.9.0".drv.overrideAttrs (attrs: {
nativeBuildInputs = with pkgs.buildPackages; [
python3 nodejs
];
buildInputs = with pkgs; [
libusb1
] ++ lib.optionals stdenv.hostPlatform.isLinux [
systemd
] ++ lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
darwin.apple_sdk.frameworks.AppKit
darwin.cctools
];
dontBuild = false;
buildPhase = ''
ln -s ${nixLib.linkNodeDeps { name=attrs.name; dependencies=attrs.passthru.nodeBuildInputs; }} node_modules
${nodejs}/lib/node_modules/npm/bin/node-gyp-bin/node-gyp rebuild --nodedir=${lib.getDev nodejs} # /include/node
'';
});
};
"node-hid@^2.1.2" = {
inherit (super."node-hid@^2.1.2") key;
drv = super."node-hid@^2.1.2".drv.overrideAttrs (attrs: {
nativeBuildInputs = with pkgs.buildPackages; [
python3 nodejs pkg-config
];
buildInputs = with pkgs; [
libusb1
] ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [
systemd
] ++ lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
darwin.apple_sdk.frameworks.AppKit
darwin.cctools
];
dontBuild = false;
buildPhase = ''
ln -s ${nixLib.linkNodeDeps { name=attrs.name; dependencies=attrs.passthru.nodeBuildInputs; }} node_modules
${nodejs}/lib/node_modules/npm/bin/node-gyp-bin/node-gyp rebuild --nodedir=${lib.getDev nodejs} # /include/node
'';
});
};
"hw-app-alamgu@0.1.1" = super._buildNodePackage rec {
key = "hw-app-alamgu";
version = "0.1.1";
src = thunkSource ./dep/hw-app-alamgu;
buildPhase = ''
ln -s $nodeModules node_modules
node $nodeModules/.bin/tsc
node $nodeModules/.bin/tsc -m ES6 --outDir lib-es
'';
nodeModules = nixLib.linkNodeDeps {
name = "hw-app-alamgu";
dependencies = nodeBuildInputs ++ [
(s."@types/node@^17.0.10")
(s."typescript@^4.5.5")
];
};
passthru = { inherit nodeModules; };
NODE_PATH = nodeModules;
nodeBuildInputs = [
(s."@ledgerhq/hw-transport@^6.30.2")
(s."fast-sha256@^1.3.0")
(s."typedoc@^0.22.7")
];
};
};
deps = nixLib.buildNodeDeps
(lib.composeExtensions
(pkgs.callPackage yarnDepsNix {
fetchgit = builtins.fetchGit;
})
localOverrides);
src0 = lib.sources.cleanSourceWith {
src = ./.;
filter = p: _: let
p' = baseNameOf p;
srcStr = builtins.toString ./.;
in !(lib.elem p' [ "node_modules" ".git" "dep" ]);
};
src = lib.sources.sourceFilesBySuffices src0 [
".js" ".cjs" ".ts" ".json"
];
in rec {
inherit deps yarnDepsNix yarnPackageNix thunkSource;
modules = nixLib.buildNodePackage ({
src = pkgs.runCommand "package-json" {} ''
mkdir $out
cp ${./package.json} $out/package.json
'';
} // nixLib.callTemplate yarnPackageNix deps);
package = nixLib.buildNodePackage (let
self = nixLib.callTemplate yarnPackageNix deps // {
inherit src;
buildPhase = ''
ln -s $nodeModules node_modules
node $nodeModules/.bin/tsc
'';
postInstall = ''
mkdir -p $out/bin
ln -s "$out/build/cli.js" "$out/bin/generic-cli"
'';
nodeModules = nixLib.linkNodeDeps {
name = "ledger-generic-cli";
dependencies = self.nodeBuildInputs;
};
};
in self);
}