mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-11-23 09:04:37 +03:00
feat(v1): add module nodejs-package-json
This commit is contained in:
parent
17a0b6279e
commit
d40329a29a
70
v1/nix/modules/drv-parts/nodejs-package-json/default.nix
Normal file
70
v1/nix/modules/drv-parts/nodejs-package-json/default.nix
Normal 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;
|
||||
};
|
||||
};
|
||||
}
|
24
v1/nix/modules/drv-parts/nodejs-package-json/interface.nix
Normal file
24
v1/nix/modules/drv-parts/nodejs-package-json/interface.nix
Normal 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 = [];
|
||||
};
|
||||
};
|
||||
}
|
@ -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 {};
|
||||
};
|
||||
}
|
||||
|
32
v1/nix/modules/drvs/prettier-no-lock/default.nix
Normal file
32
v1/nix/modules/drvs/prettier-no-lock/default.nix
Normal 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";
|
||||
}
|
Loading…
Reference in New Issue
Block a user