From b38c4d9a2feabc0a06247a09819686f346c2557c Mon Sep 17 00:00:00 2001 From: DavHau Date: Sat, 8 Jul 2023 13:03:12 +0200 Subject: [PATCH] examples(nodejs): add example nodejs-no-lock --- v1/nix/modules/drvs/nodejs-no-lock/app.ts | 2 + .../modules/drvs/nodejs-no-lock/default.nix | 46 +++++++++++++++++++ .../nodejs-no-lock/lock-x86_64-linux.json | 33 +++++++++++++ .../modules/drvs/nodejs-no-lock/package.json | 7 +++ 4 files changed, 88 insertions(+) create mode 100644 v1/nix/modules/drvs/nodejs-no-lock/app.ts create mode 100644 v1/nix/modules/drvs/nodejs-no-lock/default.nix create mode 100644 v1/nix/modules/drvs/nodejs-no-lock/lock-x86_64-linux.json create mode 100644 v1/nix/modules/drvs/nodejs-no-lock/package.json diff --git a/v1/nix/modules/drvs/nodejs-no-lock/app.ts b/v1/nix/modules/drvs/nodejs-no-lock/app.ts new file mode 100644 index 00000000..ad656e63 --- /dev/null +++ b/v1/nix/modules/drvs/nodejs-no-lock/app.ts @@ -0,0 +1,2 @@ +let message: string = 'Hello, World!'; +console.log(message); diff --git a/v1/nix/modules/drvs/nodejs-no-lock/default.nix b/v1/nix/modules/drvs/nodejs-no-lock/default.nix new file mode 100644 index 00000000..04f427e5 --- /dev/null +++ b/v1/nix/modules/drvs/nodejs-no-lock/default.nix @@ -0,0 +1,46 @@ +{ + lib, + config, + ... +}: let + l = lib // builtins; + system = config.deps.stdenv.system; +in { + imports = [ + ../../drv-parts/nodejs-package-json + ../../drv-parts/nodejs-granular + ]; + + mkDerivation = { + src = lib.cleanSource ./.; + checkPhase = '' + ./app.js | ${config.deps.gnugrep}/bin/grep -q "Hello, World!" + ''; + doCheck = true; + }; + + nodejs-granular = { + buildScript = '' + tsc ./app.ts + mv app.js app.js.tmp + echo "#!${config.deps.nodejs}/bin/node" > app.js + cat app.js.tmp >> app.js + chmod +x ./app.js + patchShebangs . + ''; + }; + + deps = {nixpkgs, ...}: { + inherit + (nixpkgs) + gnugrep + stdenv + ; + }; + + name = l.mkForce "app"; + version = l.mkForce "0.0.0"; + + lock.lockFileRel = + l.mkForce "/v1/nix/modules/drvs/nodejs-no-lock/lock-${system}.json"; +} diff --git a/v1/nix/modules/drvs/nodejs-no-lock/lock-x86_64-linux.json b/v1/nix/modules/drvs/nodejs-no-lock/lock-x86_64-linux.json new file mode 100644 index 00000000..cbfcae53 --- /dev/null +++ b/v1/nix/modules/drvs/nodejs-no-lock/lock-x86_64-linux.json @@ -0,0 +1,33 @@ +{ + "package-lock": { + "name": "tmp.BeJiEGlOfL", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "dependencies": { + "typescript": "^5.1.6" + } + }, + "node_modules/typescript": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz", + "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + } + }, + "dependencies": { + "typescript": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz", + "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==" + } + } + } +} \ No newline at end of file diff --git a/v1/nix/modules/drvs/nodejs-no-lock/package.json b/v1/nix/modules/drvs/nodejs-no-lock/package.json new file mode 100644 index 00000000..d790ff43 --- /dev/null +++ b/v1/nix/modules/drvs/nodejs-no-lock/package.json @@ -0,0 +1,7 @@ +{ + "name": "app", + "dependencies": { + "typescript": "^5.1.6" + }, + "bin": "app.js" +}