diff --git a/default.nix b/default.nix index fa9b45d..9be7eb3 100644 --- a/default.nix +++ b/default.nix @@ -1,15 +1,17 @@ -{ callPackage -, fetchFromGitHub -, git -, idris2 -, lib -, installShellFiles -, makeWrapper -, nodejs -, stdenv -}: -let - nodeDependencies = (callPackage ./node2nix.nix { inherit nodejs; }).nodeDependencies; +{ + callPackage, + fetchFromGitHub, + git, + buildIdris, + lib, + installShellFiles, + makeWrapper, + nodejs, + stdenv, +}: let + libraries = map (p: p.library {}); + + nodeDependencies = (callPackage ./node2nix.nix {inherit nodejs;}).nodeDependencies; idrisAddsVersion = "0.3.0"; idrisAddsSrc = fetchFromGitHub { owner = "mattpolzin"; @@ -17,6 +19,11 @@ let rev = "${idrisAddsVersion}"; hash = "sha256-OSu381nUNZqFJs4HzmMxGda60k7xsa1GulQq7kU/R2o="; }; + idrisAddsPkg = buildIdris { + projectName = "idris-adds"; + src = idrisAddsSrc; + idrisLibraries = []; + }; elabUtilRev = "2fc2d188640ce6822b5e250db73b62f5a952ca4d"; elabUtilSrc = fetchFromGitHub { owner = "stefan-hoeck"; @@ -24,6 +31,11 @@ let rev = "${elabUtilRev}"; hash = "sha256-CYPrhB9y4CMk2Wiecpk+5isybcf3ZsbmaKdKOyo0JWk="; }; + elabUtilPkg = buildIdris { + projectName = "elab-util"; + src = elabUtilSrc; + idrisLibraries = []; + }; idrisJsonRev = "2e54a37ed3c35c2d12c8927c923ad253355812a8"; idrisJsonSrc = fetchFromGitHub { owner = "stefan-hoeck"; @@ -31,6 +43,11 @@ let rev = "${idrisJsonRev}"; hash = "sha256-+lwOdkovhOsvaSKH+jJY7uhr40JjXpUJ4ECR9qxZv14="; }; + idrisJsonPkg = buildIdris { + projectName = "json"; + src = idrisJsonSrc; + idrisLibraries = libraries [elabUtilPkg idrisParserPkg idrisParserJsonPkg]; + }; idrisParserRev = "0fde36cf11c12a61edcfe09d585c5a60426bc706"; idrisParserSrc = fetchFromGitHub { owner = "stefan-hoeck"; @@ -38,54 +55,45 @@ let rev = "${idrisParserRev}"; hash = "sha256-ShwVAUsobrwmuYszYld1RqlRUvnrACpyyqK2JKaIWYM="; }; -in -stdenv.mkDerivation (finalAttrs: { - pname = "harmony"; - version = "3.2.0"; - - nativeBuildInputs = [ idris2 installShellFiles makeWrapper ]; - buildInputs = [ nodejs git ]; - - src = ./.; - - IDRIS_ADDS_SRC = "${idrisAddsSrc}"; - IDRIS_ELAB_UTIL_SRC = "${elabUtilSrc}"; - IDRIS_PARSER_SRC = "${idrisParserSrc}"; - IDRIS_JSON_SRC = "${idrisJsonSrc}"; - - buildPhase = '' - runHook preBuild - - ln -s ${nodeDependencies}/lib/node_modules ./node_modules - export PATH="${nodeDependencies}/bin:$PATH" - - make build - - runHook postBuild - ''; + idrisParserPkg = buildIdris { + projectName = "parser"; + src = idrisParserSrc; + idrisLibraries = libraries [elabUtilPkg]; + }; + idrisParserJsonPkg = buildIdris rec { + projectName = "parser-json"; + src = idrisParserSrc; + sourceRoot = "${src.name}/json"; + idrisLibraries = libraries [idrisParserPkg elabUtilPkg]; + }; - installPhase = '' - runHook preInstall + harmonyPkg = buildIdris { + version = "3.2.0"; + projectName = "harmony"; + src = ./.; - mkdir -p $out/bin - cp harmony $out/bin/ + idrisLibraries = libraries [idrisAddsPkg elabUtilPkg idrisParserPkg idrisParserJsonPkg idrisJsonPkg]; + nativeBuildInputs = [installShellFiles makeWrapper]; + buildInputs = [nodejs git]; - wrapProgram $out/bin/harmony \ - --prefix PATH : ${lib.makeBinPath [ nodeDependencies git "$out" ]} \ - --prefix NODE_PATH : ${nodeDependencies}/lib/node_modules + IDRIS2_DATA = "./support"; - installShellCompletion --cmd harmony \ - --bash <($out/bin/harmony --bash-completion-script) \ - --zsh <($out/bin/harmony --zsh-completion-script) \ + postInstall = '' + wrapProgram $out/bin/harmony \ + --prefix PATH : ${lib.makeBinPath [nodeDependencies git "$out"]} \ + --prefix NODE_PATH : ${nodeDependencies}/lib/node_modules - runHook postInstall - ''; + installShellCompletion --cmd harmony \ + --bash <($out/bin/harmony --bash-completion-script) \ + --zsh <($out/bin/harmony --zsh-completion-script) \ + ''; - meta = with lib; { - description = "Harmony GitHub collaboration tool"; - homepage = "https://github.com/mattpolzin/harmony"; - license = licenses.mit; - mainProgram = "harmony"; + meta = with lib; { + description = "Harmony GitHub collaboration tool"; + homepage = "https://github.com/mattpolzin/harmony"; + license = licenses.mit; + mainProgram = "harmony"; + }; }; - -}) +in + harmonyPkg.executable diff --git a/flake.lock b/flake.lock index 561fe40..114656d 100644 --- a/flake.lock +++ b/flake.lock @@ -1,24 +1,158 @@ { "nodes": { + "alejandra": { + "inputs": { + "fenix": "fenix", + "flakeCompat": "flakeCompat", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1694541876, + "narHash": "sha256-lStDIPizbJipd1JpNKX1olBKzyIosyC2U/mVFwJPcZE=", + "owner": "kamadorueda", + "repo": "alejandra", + "rev": "e53c2c6c6c103dc3f848dbd9fbd93ee7c69c109f", + "type": "github" + }, + "original": { + "owner": "kamadorueda", + "repo": "alejandra", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "alejandra", + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1668234453, + "narHash": "sha256-FmuZThToBvRsqCauYJ3l8HJoGLAY5cMULeYEKIaGrRw=", + "owner": "nix-community", + "repo": "fenix", + "rev": "8f219f6b36e8d0d56afa7f67e6e3df63ef013cdb", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flakeCompat": { + "flake": false, + "locked": { + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "idris": { + "inputs": { + "flake-utils": "flake-utils", + "idris-emacs-src": "idris-emacs-src", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1704504523, + "narHash": "sha256-CM/0KWIeIxHunMpBd1y9gn1pwXp+0XLje0CqVumlCsc=", + "owner": "mattpolzin", + "repo": "Idris2", + "rev": "52814b4f52244d6aa6a647e6611b8517c817a43d", + "type": "github" + }, + "original": { + "owner": "mattpolzin", + "ref": "fix-install-output-buildIdris", + "repo": "Idris2", + "type": "github" + } + }, + "idris-emacs-src": { + "flake": false, + "locked": { + "lastModified": 1666078909, + "narHash": "sha256-oYNHFIpcrFfPb4sXJwEBFKeH+PB4AGCrAFrfBrSTCeo=", + "owner": "redfish64", + "repo": "idris2-mode", + "rev": "3bcb52a65c488f31c99d20f235f6050418a84c9d", + "type": "github" + }, + "original": { + "owner": "redfish64", + "repo": "idris2-mode", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1703455112, - "narHash": "sha256-WVw8zFsiUJ8wXNZUy/QXOmctS4tqOnhj+uAtmnKANyA=", + "lastModified": 1704842529, + "narHash": "sha256-OTeQA+F8d/Evad33JMfuXC89VMetQbsU4qcaePchGr4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "8999c9d930c526d9f8e8761847e5ee939744590d", + "rev": "eabe8d3eface69f5bb16c18f8662a702f50c20d5", "type": "github" }, "original": { "owner": "NixOS", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { + "alejandra": "alejandra", + "idris": "idris", "nixpkgs": "nixpkgs" } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1668182250, + "narHash": "sha256-PYGaOCiFvnJdVz+ZCaKF8geGdffXjJUNcMwaBHv0FT4=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "45ec315e01dc8dd1146dfeb65f0ef6e5c2efed78", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 1d11a93..056c629 100644 --- a/flake.nix +++ b/flake.nix @@ -2,22 +2,39 @@ description = "Harmony GitHub collaboration tool"; inputs = { - nixpkgs.url = github:NixOS/nixpkgs; + nixpkgs.url = github:NixOS/nixpkgs/nixpkgs-unstable; + + idris.url = github:mattpolzin/Idris2/fix-install-output-buildIdris; + idris.inputs.nixpkgs.follows = "nixpkgs"; + + alejandra.url = github:kamadorueda/alejandra; + alejandra.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs }: - let + # we grab Idris2 from nixpkgs unstable because it will already be built and cached. + # we use the idris2 compiler repo to grab the buildIdris function that isn't available + # in nixpkgs yet. + outputs = { + self, + nixpkgs, + alejandra, + idris, + }: let lib = nixpkgs.lib; forAllSystems = lib.genAttrs lib.systems.flakeExposed; - in - { - packages = forAllSystems (system: - { - harmony = with nixpkgs.legacyPackages.${system}; - callPackage ./default.nix {}; + in { + packages = forAllSystems ( + system: let + pkgs = nixpkgs.legacyPackages.${system}; + buildIdris = idris.buildIdris.${system}.override {inherit (pkgs) idris2;}; + in { + harmony = pkgs.callPackage ./default.nix { + inherit buildIdris; + }; default = self.packages.${system}.harmony; } ); + formatter = forAllSystems (system: alejandra.packages.${system}.default); }; } diff --git a/node-env.nix b/node-env.nix index bc1e366..3b829ff 100644 --- a/node-env.nix +++ b/node-env.nix @@ -1,12 +1,25 @@ # This file originates from node2nix - -{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile, writeShellScript}: - -let +{ + lib, + stdenv, + nodejs, + python2, + pkgs, + libtool, + runCommand, + writeTextFile, + writeShellScript, +}: let # Workaround to cope with utillinux in Nixpkgs 20.09 and util-linux in Nixpkgs master - utillinux = if pkgs ? utillinux then pkgs.utillinux else pkgs.util-linux; + utillinux = + if pkgs ? utillinux + then pkgs.utillinux + else pkgs.util-linux; - python = if nodejs ? python then nodejs.python else python2; + python = + if nodejs ? python + then nodejs.python + else python2; # Create a tar wrapper that filters all the 'Ignoring unknown extended header keyword' noise tarWrapper = runCommand "tarWrapper" {} '' @@ -21,13 +34,16 @@ let ''; # Function that generates a TGZ file from a NPM project - buildNodeSourceDist = - { name, version, src, ... }: - + buildNodeSourceDist = { + name, + version, + src, + ... + }: stdenv.mkDerivation { name = "node-tarball-${name}-${version}"; inherit src; - buildInputs = [ nodejs ]; + buildInputs = [nodejs]; buildPhase = '' export HOME=$TMPDIR tgzFile=$(npm pack | tail -n 1) # Hooks to the pack command will add output (https://docs.npmjs.com/misc/scripts) @@ -96,114 +112,130 @@ let mkdir -p node_modules cd node_modules '' - + (lib.concatMapStrings (dependency: - '' - if [ ! -e "${dependency.packageName}" ]; then - ${composePackage dependency} - fi - '' - ) dependencies) + + (lib.concatMapStrings ( + dependency: '' + if [ ! -e "${dependency.packageName}" ]; then + ${composePackage dependency} + fi + '' + ) + dependencies) + '' cd .. '' ); # Recursively composes the dependencies of a package - composePackage = { name, packageName, src, dependencies ? [], ... }@args: + composePackage = { + name, + packageName, + src, + dependencies ? [], + ... + } @ args: builtins.addErrorContext "while evaluating node package '${packageName}'" '' installPackage "${packageName}" "${src}" - ${includeDependencies { inherit dependencies; }} + ${includeDependencies {inherit dependencies;}} cd .. ${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."} ''; - pinpointDependencies = {dependencies, production}: - let - pinpointDependenciesFromPackageJSON = writeTextFile { - name = "pinpointDependencies.js"; - text = '' - var fs = require('fs'); - var path = require('path'); - - function resolveDependencyVersion(location, name) { - if(location == process.env['NIX_STORE']) { - return null; - } else { - var dependencyPackageJSON = path.join(location, "node_modules", name, "package.json"); - - if(fs.existsSync(dependencyPackageJSON)) { - var dependencyPackageObj = JSON.parse(fs.readFileSync(dependencyPackageJSON)); - - if(dependencyPackageObj.name == name) { - return dependencyPackageObj.version; - } - } else { - return resolveDependencyVersion(path.resolve(location, ".."), name); - } - } - } - - function replaceDependencies(dependencies) { - if(typeof dependencies == "object" && dependencies !== null) { - for(var dependency in dependencies) { - var resolvedVersion = resolveDependencyVersion(process.cwd(), dependency); - - if(resolvedVersion === null) { - process.stderr.write("WARNING: cannot pinpoint dependency: "+dependency+", context: "+process.cwd()+"\n"); - } else { - dependencies[dependency] = resolvedVersion; - } - } - } - } - - /* Read the package.json configuration */ - var packageObj = JSON.parse(fs.readFileSync('./package.json')); - - /* Pinpoint all dependencies */ - replaceDependencies(packageObj.dependencies); - if(process.argv[2] == "development") { - replaceDependencies(packageObj.devDependencies); - } - else { - packageObj.devDependencies = {}; - } - replaceDependencies(packageObj.optionalDependencies); - replaceDependencies(packageObj.peerDependencies); - - /* Write the fixed package.json file */ - fs.writeFileSync("package.json", JSON.stringify(packageObj, null, 2)); - ''; - }; - in - '' - node ${pinpointDependenciesFromPackageJSON} ${if production then "production" else "development"} + pinpointDependencies = { + dependencies, + production, + }: let + pinpointDependenciesFromPackageJSON = writeTextFile { + name = "pinpointDependencies.js"; + text = '' + var fs = require('fs'); + var path = require('path'); + + function resolveDependencyVersion(location, name) { + if(location == process.env['NIX_STORE']) { + return null; + } else { + var dependencyPackageJSON = path.join(location, "node_modules", name, "package.json"); + + if(fs.existsSync(dependencyPackageJSON)) { + var dependencyPackageObj = JSON.parse(fs.readFileSync(dependencyPackageJSON)); + + if(dependencyPackageObj.name == name) { + return dependencyPackageObj.version; + } + } else { + return resolveDependencyVersion(path.resolve(location, ".."), name); + } + } + } + + function replaceDependencies(dependencies) { + if(typeof dependencies == "object" && dependencies !== null) { + for(var dependency in dependencies) { + var resolvedVersion = resolveDependencyVersion(process.cwd(), dependency); + + if(resolvedVersion === null) { + process.stderr.write("WARNING: cannot pinpoint dependency: "+dependency+", context: "+process.cwd()+"\n"); + } else { + dependencies[dependency] = resolvedVersion; + } + } + } + } + + /* Read the package.json configuration */ + var packageObj = JSON.parse(fs.readFileSync('./package.json')); + + /* Pinpoint all dependencies */ + replaceDependencies(packageObj.dependencies); + if(process.argv[2] == "development") { + replaceDependencies(packageObj.devDependencies); + } + else { + packageObj.devDependencies = {}; + } + replaceDependencies(packageObj.optionalDependencies); + replaceDependencies(packageObj.peerDependencies); + + /* Write the fixed package.json file */ + fs.writeFileSync("package.json", JSON.stringify(packageObj, null, 2)); + ''; + }; + in '' + node ${pinpointDependenciesFromPackageJSON} ${ + if production + then "production" + else "development" + } - ${lib.optionalString (dependencies != []) - '' - if [ -d node_modules ] - then - cd node_modules - ${lib.concatMapStrings (dependency: pinpointDependenciesOfPackage dependency) dependencies} - cd .. - fi - ''} - ''; + ${lib.optionalString (dependencies != []) + '' + if [ -d node_modules ] + then + cd node_modules + ${lib.concatMapStrings (dependency: pinpointDependenciesOfPackage dependency) dependencies} + cd .. + fi + ''} + ''; # Recursively traverses all dependencies of a package and pinpoints all # dependencies in the package.json file to the versions that are actually # being used. - pinpointDependenciesOfPackage = { packageName, dependencies ? [], production ? true, ... }@args: - '' - if [ -d "${packageName}" ] - then - cd "${packageName}" - ${pinpointDependencies { inherit dependencies production; }} - cd .. - ${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."} - fi - ''; + pinpointDependenciesOfPackage = { + packageName, + dependencies ? [], + production ? true, + ... + } @ args: '' + if [ -d "${packageName}" ] + then + cd "${packageName}" + ${pinpointDependencies {inherit dependencies production;}} + cd .. + ${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."} + fi + ''; # Extract the Node.js source code which is used to compile packages with # native bindings @@ -414,183 +446,201 @@ let ''; }; - prepareAndInvokeNPM = {packageName, bypassCache, reconstructLock, npmFlags, production}: - let - forceOfflineFlag = if bypassCache then "--offline" else "--registry http://www.example.com"; - in - '' - # Pinpoint the versions of all dependencies to the ones that are actually being used - echo "pinpointing versions of dependencies..." - source $pinpointDependenciesScriptPath - - # Patch the shebangs of the bundled modules to prevent them from - # calling executables outside the Nix store as much as possible - patchShebangs . - - # Deploy the Node.js package by running npm install. Since the - # dependencies have been provided already by ourselves, it should not - # attempt to install them again, which is good, because we want to make - # it Nix's responsibility. If it needs to install any dependencies - # anyway (e.g. because the dependency parameters are - # incomplete/incorrect), it fails. - # - # The other responsibilities of NPM are kept -- version checks, build - # steps, postprocessing etc. + prepareAndInvokeNPM = { + packageName, + bypassCache, + reconstructLock, + npmFlags, + production, + }: let + forceOfflineFlag = + if bypassCache + then "--offline" + else "--registry http://www.example.com"; + in '' + # Pinpoint the versions of all dependencies to the ones that are actually being used + echo "pinpointing versions of dependencies..." + source $pinpointDependenciesScriptPath + + # Patch the shebangs of the bundled modules to prevent them from + # calling executables outside the Nix store as much as possible + patchShebangs . + + # Deploy the Node.js package by running npm install. Since the + # dependencies have been provided already by ourselves, it should not + # attempt to install them again, which is good, because we want to make + # it Nix's responsibility. If it needs to install any dependencies + # anyway (e.g. because the dependency parameters are + # incomplete/incorrect), it fails. + # + # The other responsibilities of NPM are kept -- version checks, build + # steps, postprocessing etc. + + export HOME=$TMPDIR + cd "${packageName}" + runHook preRebuild + + ${lib.optionalString bypassCache '' + ${lib.optionalString reconstructLock '' + if [ -f package-lock.json ] + then + echo "WARNING: Reconstruct lock option enabled, but a lock file already exists!" + echo "This will most likely result in version mismatches! We will remove the lock file and regenerate it!" + rm package-lock.json + else + echo "No package-lock.json file found, reconstructing..." + fi - export HOME=$TMPDIR - cd "${packageName}" - runHook preRebuild + node ${reconstructPackageLock} + ''} - ${lib.optionalString bypassCache '' - ${lib.optionalString reconstructLock '' - if [ -f package-lock.json ] - then - echo "WARNING: Reconstruct lock option enabled, but a lock file already exists!" - echo "This will most likely result in version mismatches! We will remove the lock file and regenerate it!" - rm package-lock.json - else - echo "No package-lock.json file found, reconstructing..." - fi + node ${addIntegrityFieldsScript} + ''} - node ${reconstructPackageLock} - ''} + npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${lib.optionalString production "--production"} rebuild - node ${addIntegrityFieldsScript} - ''} + runHook postRebuild - npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${lib.optionalString production "--production"} rebuild + if [ "''${dontNpmInstall-}" != "1" ] + then + # NPM tries to download packages even when they already exist if npm-shrinkwrap is used. + rm -f npm-shrinkwrap.json - runHook postRebuild + npm ${forceOfflineFlag} --nodedir=${nodeSources} --no-bin-links --ignore-scripts ${npmFlags} ${lib.optionalString production "--production"} install + fi - if [ "''${dontNpmInstall-}" != "1" ] - then - # NPM tries to download packages even when they already exist if npm-shrinkwrap is used. - rm -f npm-shrinkwrap.json - - npm ${forceOfflineFlag} --nodedir=${nodeSources} --no-bin-links --ignore-scripts ${npmFlags} ${lib.optionalString production "--production"} install - fi - - # Link executables defined in package.json - node ${linkBinsScript} - ''; + # Link executables defined in package.json + node ${linkBinsScript} + ''; # Builds and composes an NPM package including all its dependencies - buildNodePackage = - { name - , packageName - , version ? null - , dependencies ? [] - , buildInputs ? [] - , production ? true - , npmFlags ? "" - , dontNpmInstall ? false - , bypassCache ? false - , reconstructLock ? false - , preRebuild ? "" - , dontStrip ? true - , unpackPhase ? "true" - , buildPhase ? "true" - , meta ? {} - , ... }@args: - - let - extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "preRebuild" "unpackPhase" "buildPhase" "meta" ]; - in + buildNodePackage = { + name, + packageName, + version ? null, + dependencies ? [], + buildInputs ? [], + production ? true, + npmFlags ? "", + dontNpmInstall ? false, + bypassCache ? false, + reconstructLock ? false, + preRebuild ? "", + dontStrip ? true, + unpackPhase ? "true", + buildPhase ? "true", + meta ? {}, + ... + } @ args: let + extraArgs = removeAttrs args ["name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "preRebuild" "unpackPhase" "buildPhase" "meta"]; + in stdenv.mkDerivation ({ - name = "${name}${if version == null then "" else "-${version}"}"; - buildInputs = [ tarWrapper python nodejs ] - ++ lib.optional (stdenv.isLinux) utillinux - ++ lib.optional (stdenv.isDarwin) libtool - ++ buildInputs; + name = "${name}${ + if version == null + then "" + else "-${version}" + }"; + buildInputs = + [tarWrapper python nodejs] + ++ lib.optional (stdenv.isLinux) utillinux + ++ lib.optional (stdenv.isDarwin) libtool + ++ buildInputs; - inherit nodejs; + inherit nodejs; - inherit dontStrip; # Stripping may fail a build for some package deployments - inherit dontNpmInstall preRebuild unpackPhase buildPhase; + inherit dontStrip; # Stripping may fail a build for some package deployments + inherit dontNpmInstall preRebuild unpackPhase buildPhase; - compositionScript = composePackage args; - pinpointDependenciesScript = pinpointDependenciesOfPackage args; + compositionScript = composePackage args; + pinpointDependenciesScript = pinpointDependenciesOfPackage args; - passAsFile = [ "compositionScript" "pinpointDependenciesScript" ]; + passAsFile = ["compositionScript" "pinpointDependenciesScript"]; - installPhase = '' - source ${installPackage} + installPhase = '' + source ${installPackage} - # Create and enter a root node_modules/ folder - mkdir -p $out/lib/node_modules - cd $out/lib/node_modules + # Create and enter a root node_modules/ folder + mkdir -p $out/lib/node_modules + cd $out/lib/node_modules - # Compose the package and all its dependencies - source $compositionScriptPath + # Compose the package and all its dependencies + source $compositionScriptPath - ${prepareAndInvokeNPM { inherit packageName bypassCache reconstructLock npmFlags production; }} + ${prepareAndInvokeNPM {inherit packageName bypassCache reconstructLock npmFlags production;}} - # Create symlink to the deployed executable folder, if applicable - if [ -d "$out/lib/node_modules/.bin" ] - then - ln -s $out/lib/node_modules/.bin $out/bin - - # Fixup all executables - ls $out/bin/* | while read i - do - file="$(readlink -f "$i")" - chmod u+rwx "$file" - if isScript "$file" - then - sed -i 's/\r$//' "$file" # convert crlf to lf - fi - done - fi + # Create symlink to the deployed executable folder, if applicable + if [ -d "$out/lib/node_modules/.bin" ] + then + ln -s $out/lib/node_modules/.bin $out/bin + + # Fixup all executables + ls $out/bin/* | while read i + do + file="$(readlink -f "$i")" + chmod u+rwx "$file" + if isScript "$file" + then + sed -i 's/\r$//' "$file" # convert crlf to lf + fi + done + fi - # Create symlinks to the deployed manual page folders, if applicable - if [ -d "$out/lib/node_modules/${packageName}/man" ] - then - mkdir -p $out/share - for dir in "$out/lib/node_modules/${packageName}/man/"* - do - mkdir -p $out/share/man/$(basename "$dir") - for page in "$dir"/* - do - ln -s $page $out/share/man/$(basename "$dir") - done - done - fi + # Create symlinks to the deployed manual page folders, if applicable + if [ -d "$out/lib/node_modules/${packageName}/man" ] + then + mkdir -p $out/share + for dir in "$out/lib/node_modules/${packageName}/man/"* + do + mkdir -p $out/share/man/$(basename "$dir") + for page in "$dir"/* + do + ln -s $page $out/share/man/$(basename "$dir") + done + done + fi - # Run post install hook, if provided - runHook postInstall - ''; + # Run post install hook, if provided + runHook postInstall + ''; - meta = { - # default to Node.js' platforms - platforms = nodejs.meta.platforms; - } // meta; - } // extraArgs); + meta = + { + # default to Node.js' platforms + platforms = nodejs.meta.platforms; + } + // meta; + } + // extraArgs); # Builds a node environment (a node_modules folder and a set of binaries) - buildNodeDependencies = - { name - , packageName - , version ? null - , src - , dependencies ? [] - , buildInputs ? [] - , production ? true - , npmFlags ? "" - , dontNpmInstall ? false - , bypassCache ? false - , reconstructLock ? false - , dontStrip ? true - , unpackPhase ? "true" - , buildPhase ? "true" - , ... }@args: - - let - extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" ]; - in - stdenv.mkDerivation ({ - name = "node-dependencies-${name}${if version == null then "" else "-${version}"}"; - - buildInputs = [ tarWrapper python nodejs ] + buildNodeDependencies = { + name, + packageName, + version ? null, + src, + dependencies ? [], + buildInputs ? [], + production ? true, + npmFlags ? "", + dontNpmInstall ? false, + bypassCache ? false, + reconstructLock ? false, + dontStrip ? true, + unpackPhase ? "true", + buildPhase ? "true", + ... + } @ args: let + extraArgs = removeAttrs args ["name" "dependencies" "buildInputs"]; + in + stdenv.mkDerivation ({ + name = "node-dependencies-${name}${ + if version == null + then "" + else "-${version}" + }"; + + buildInputs = + [tarWrapper python nodejs] ++ lib.optional (stdenv.isLinux) utillinux ++ lib.optional (stdenv.isDarwin) libtool ++ buildInputs; @@ -598,10 +648,10 @@ let inherit dontStrip; # Stripping may fail a build for some package deployments inherit dontNpmInstall unpackPhase buildPhase; - includeScript = includeDependencies { inherit dependencies; }; + includeScript = includeDependencies {inherit dependencies;}; pinpointDependenciesScript = pinpointDependenciesOfPackage args; - passAsFile = [ "includeScript" "pinpointDependenciesScript" ]; + passAsFile = ["includeScript" "pinpointDependenciesScript"]; installPhase = '' source ${installPackage} @@ -626,7 +676,7 @@ let cd .. ${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."} - ${prepareAndInvokeNPM { inherit packageName bypassCache reconstructLock npmFlags production; }} + ${prepareAndInvokeNPM {inherit packageName bypassCache reconstructLock npmFlags production;}} # Expose the executables that were installed cd .. @@ -635,53 +685,57 @@ let mv ${packageName} lib ln -s $out/lib/node_modules/.bin $out/bin ''; - } // extraArgs); + } + // extraArgs); # Builds a development shell - buildNodeShell = - { name - , packageName - , version ? null - , src - , dependencies ? [] - , buildInputs ? [] - , production ? true - , npmFlags ? "" - , dontNpmInstall ? false - , bypassCache ? false - , reconstructLock ? false - , dontStrip ? true - , unpackPhase ? "true" - , buildPhase ? "true" - , ... }@args: - - let - nodeDependencies = buildNodeDependencies args; - extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "unpackPhase" "buildPhase" ]; - in + buildNodeShell = { + name, + packageName, + version ? null, + src, + dependencies ? [], + buildInputs ? [], + production ? true, + npmFlags ? "", + dontNpmInstall ? false, + bypassCache ? false, + reconstructLock ? false, + dontStrip ? true, + unpackPhase ? "true", + buildPhase ? "true", + ... + } @ args: let + nodeDependencies = buildNodeDependencies args; + extraArgs = removeAttrs args ["name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "unpackPhase" "buildPhase"]; + in stdenv.mkDerivation ({ - name = "node-shell-${name}${if version == null then "" else "-${version}"}"; - - buildInputs = [ python nodejs ] ++ lib.optional (stdenv.isLinux) utillinux ++ buildInputs; - buildCommand = '' - mkdir -p $out/bin - cat > $out/bin/shell < $out/bin/shell < { - inherit system; - }, system ? builtins.currentSystem, nodejs ? pkgs."nodejs_14"}: - -let +{ + pkgs ? + import { + inherit system; + }, + system ? builtins.currentSystem, + nodejs ? pkgs."nodejs_14", +}: let nodeEnv = import ./node-env.nix { inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript; inherit pkgs nodejs; - libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null; + libtool = + if pkgs.stdenv.isDarwin + then pkgs.darwin.cctools + else null; }; in -import ./node-packages.nix { - inherit (pkgs) fetchurl nix-gitignore stdenv lib fetchgit; - inherit nodeEnv; -} + import ./node-packages.nix { + inherit (pkgs) fetchurl nix-gitignore stdenv lib fetchgit; + inherit nodeEnv; + } diff --git a/package-lock.json b/package-lock.json index 1db9366..ca8a97a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,9 +50,9 @@ } }, "node_modules/@octokit/auth-app": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/@octokit/auth-app/-/auth-app-6.0.2.tgz", - "integrity": "sha512-HYuRX3Fvhs2y9i7a4F8f+A5HWfacRWmpERHGBEOtgvKVjJkOQZKUY2v6HiSszYecHAF8Ojqngp2iraSP3SvNpQ==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/@octokit/auth-app/-/auth-app-6.0.3.tgz", + "integrity": "sha512-9N7IlBAKEJR3tJgPSubCxIDYGXSdc+2xbkjYpk9nCyqREnH8qEMoMhiEB1WgoA9yTFp91El92XNXAi+AjuKnfw==", "dependencies": { "@octokit/auth-oauth-app": "^7.0.0", "@octokit/auth-oauth-user": "^4.0.0", @@ -61,7 +61,7 @@ "@octokit/types": "^12.0.0", "deprecation": "^2.3.1", "lru-cache": "^10.0.0", - "universal-github-app-jwt": "^1.1.1", + "universal-github-app-jwt": "^1.1.2", "universal-user-agent": "^6.0.0" }, "engines": { @@ -374,9 +374,9 @@ } }, "node_modules/@types/node": { - "version": "20.10.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.7.tgz", - "integrity": "sha512-fRbIKb8C/Y2lXxB5eVMj4IU7xpdox0Lh8bUPEdtLysaylsml1hOOx1+STloRs/B9nf7C6kPRmmg/V7aQW7usNg==", + "version": "20.10.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.8.tgz", + "integrity": "sha512-f8nQs3cLxbAFc00vEU59yf9UyGUftkPaLGfvbVOIDdx2i1b8epBqj2aNGyP19fiyXWvlmZ7qC1XLjAzw/OKIeA==", "dependencies": { "undici-types": "~5.26.4" }