aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgen-index.js48
-rw-r--r--npmPackages/index.nix1
2 files changed, 49 insertions, 0 deletions
diff --git a/gen-index.js b/gen-index.js
new file mode 100755
index 0000000..3024f7c
--- /dev/null
+++ b/gen-index.js
@@ -0,0 +1,48 @@
+#!/usr/bin/env node
+
+const fs = require('fs');
+const path = require('path');
+const process = require('process');
+
+var packages = {};
+
+function normalize(name) {
+ return name.replace('/', '-').replace('@', '').replace('.', '-');
+}
+
+function findPackages(dir) {
+ fs.readdirSync(dir).forEach(function(entry) {
+ const p = path.join(dir, entry);
+ const name = normalize(dir);
+ if (fs.lstatSync(p).isDirectory()) {
+ findPackages(p);
+ } else if (entry === 'default.nix' && dir !== '.') {
+ packages[name] = dir;
+ }
+ });
+}
+
+process.chdir(path.join(path.dirname(process.argv[1]), 'npmPackages'));
+findPackages('.');
+
+const names = Object.keys(packages).sort();
+
+const index = fs.createWriteStream('index.nix');
+index.once('open', (fd) => {
+ fs.writeSync(fd, '# XXX this file is automatically generated.\n');
+ fs.writeSync(fd, 'self: super:\n');
+ fs.writeSync(fd, 'let\n');
+ fs.writeSync(fd, ' inherit (super) callPackage;\n');
+ fs.writeSync(fd, 'in {\n');
+ for (var i = 0; i < names.length; i++) {
+ var path = packages[names[i]];
+ if (path[0] === '@') {
+ path = `(./. + "${path}")`;
+ } else {
+ path = `./${path}`;
+ }
+ fs.writeSync(fd, ` ${names[i]} = callPackage ${path} {};\n`);
+ }
+ fs.writeSync(fd, '}\n');
+ fs.closeSync(fd);
+});
diff --git a/npmPackages/index.nix b/npmPackages/index.nix
index 27880b5..6aeebb4 100644
--- a/npmPackages/index.nix
+++ b/npmPackages/index.nix
@@ -1,3 +1,4 @@
+# XXX this file is automatically generated.
self: super:
let
inherit (super) callPackage;