feat(v1): add module nodejs-package-json

This commit is contained in:
DavHau 2023-05-29 16:35:39 +02:00
parent 17a0b6279e
commit d40329a29a
4 changed files with 130 additions and 1 deletions

View File

@ -0,0 +1,70 @@
{
config,
lib,
...
}: let
l = lib // builtins;
cfg = config.nodejs-package-json;
writers = import ../../../pkgs/writers {
inherit lib;
inherit
(config.deps)
bash
coreutils
gawk
path
writeScript
writeScriptBin
;
};
npmArgs = l.concatStringsSep " " (map (arg: "'${arg}'") cfg.npmArgs);
in {
imports = [
./interface.nix
../nodejs-package-lock
../lock
];
config = {
deps = {nixpkgs, ...}:
l.mapAttrs (_: l.mkDefault) {
inherit
(nixpkgs)
bash
coreutils
gawk
path
writeScript
writeScriptBin
;
inherit (nixpkgs.nodePackages) npm;
};
lock.fields.package-lock.script =
writers.writePureShellScript
(with config.deps; [
coreutils
npm
])
''
source=${cfg.source}
pushd $TMPDIR
cp -r $source/* ./
chmod -R +w ./
rm -f package-lock.json
npm install --package-lock-only ${npmArgs}
mv package-lock.json $out
popd
'';
nodejs-package-lock = {
packageLockFile = null;
packageLock = l.mkForce config.lock.content.package-lock;
};
};
}

View File

@ -0,0 +1,24 @@
{
config,
lib,
...
}: let
l = lib // builtins;
t = l.types;
in {
imports = [
../nodejs-package-lock/interface.nix
];
options.nodejs-package-json = l.mapAttrs (_: l.mkOption) {
source = {
type = t.either t.path t.package;
description = "Source of the package";
default = config.mkDerivation.src;
};
npmArgs = {
type = t.listOf t.str;
description = "extra arguments to pass to 'npm install'";
default = [];
};
};
}

View File

@ -45,6 +45,9 @@ in {
nodejs-package-lock = {
inherit dreamLock;
packageJson = l.fromJSON (l.readFile cfg.packageJsonFile);
packageLock = l.fromJSON (l.readFile cfg.packageLockFile);
packageLock =
if cfg.packageLockFile != null
then l.fromJSON (l.readFile cfg.packageLockFile)
else lib.mkDefault {};
};
}

View File

@ -0,0 +1,32 @@
{
lib,
config,
...
}: let
l = lib // builtins;
in {
imports = [
../../drv-parts/nodejs-package-json
../../drv-parts/nodejs-granular
];
mkDerivation = {
src = config.deps.fetchFromGitHub {
owner = "prettier";
repo = "prettier";
rev = config.version;
sha256 = "sha256-gHFzUjTHsEcxTJtFflqSOCthKW4Wa+ypuTeGxodmh0o=";
};
};
deps = {nixpkgs, ...}: {
inherit
(nixpkgs)
fetchFromGitHub
stdenv
;
};
name = l.mkForce "prettier";
version = l.mkForce "2.8.7";
}