From e99e002920bad15c4ed58dcc34b00d82c0eabb31 Mon Sep 17 00:00:00 2001 From: DavHau Date: Thu, 7 Oct 2021 11:50:40 +0700 Subject: [PATCH 1/2] Squashed commit of add_yarn_lock: commit 3415d7f6f834dc3e52cf6898ec02b58ac7df4089 Merge: fca3973 daa71d3 Author: DavHau Date: Wed Oct 6 10:33:52 2021 +0700 Merge remote-tracking branch 'happysalada/add_yarn_lock' into dev commit daa71d3e537dafa71ac9179370f0d39d5ee55fb1 Author: happysalada Date: Wed Oct 6 00:01:26 2021 +0900 yarn.lock: initial translator commit 8f4632ab5e9669b34a79a2fff2cce82d68eda47e Author: happysalada Date: Tue Oct 5 20:52:00 2021 +0900 translators: add yarn.lock --- flake.lock | 17 +++ flake.nix | 23 +++- src/default.nix | 4 + .../nodejs/pure/yarn-lock/default.nix | 124 ++++++++++++++++++ .../nodejs/pure/yarn-lock/parser.nix | 76 +++++++++++ 5 files changed, 238 insertions(+), 6 deletions(-) create mode 100644 src/translators/nodejs/pure/yarn-lock/default.nix create mode 100644 src/translators/nodejs/pure/yarn-lock/parser.nix diff --git a/flake.lock b/flake.lock index fc75203f..6753a770 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "nix-parsec": { + "flake": false, + "locked": { + "lastModified": 1614150306, + "narHash": "sha256-h5fZgIhwvekg5WTNDdrV5EJ4zxXvlSqITmPVuz/OM+w=", + "owner": "nprindle", + "repo": "nix-parsec", + "rev": "a28e73fce98227cc46edfdbb8518697c0982e034", + "type": "github" + }, + "original": { + "owner": "nprindle", + "repo": "nix-parsec", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1631015389, @@ -49,6 +65,7 @@ }, "root": { "inputs": { + "nix-parsec": "nix-parsec", "nixpkgs": "nixpkgs", "node2nix": "node2nix", "npmlock2nix": "npmlock2nix" diff --git a/flake.nix b/flake.nix index 9e658ef5..98732d12 100644 --- a/flake.nix +++ b/flake.nix @@ -3,11 +3,18 @@ inputs = { nixpkgs.url = "nixpkgs/nixos-unstable"; + + # required for translator nodejs/pure/package-lock + nix-parsec = { url = "github:nprindle/nix-parsec"; flake = false; }; + + # required for builder nodejs/node2nix node2nix = { url = "github:svanderburg/node2nix"; flake = false; }; + + # required for translator nodejs/pure/npmlock2nix npmlock2nix = { url = "github:nix-community/npmlock2nix"; flake = false; }; }; - outputs = { self, nixpkgs, node2nix, npmlock2nix }: + outputs = { self, nix-parsec, nixpkgs, node2nix, npmlock2nix }: let lib = nixpkgs.lib; @@ -19,9 +26,10 @@ ); externalSourcesFor = forAllSystems (system: pkgs: pkgs.runCommand "dream2nix-vendored" {} '' - mkdir -p $out/{npmlock2nix,node2nix} + mkdir -p $out/{npmlock2nix,node2nix,nix-parsec} cp ${npmlock2nix}/{internal.nix,LICENSE} $out/npmlock2nix/ cp ${node2nix}/{nix/node-env.nix,LICENSE} $out/node2nix/ + cp ${nix-parsec}/{parsec,lexer}.nix $out/nix-parsec/ ''); dream2nixFor = forAllSystems (system: pkgs: import ./src rec { @@ -52,10 +60,13 @@ ); devShell = forAllSystems (system: pkgs: pkgs.mkShell { - buildInputs = with pkgs; [ - cntr - nixUnstable - ]; + + buildInputs = with pkgs; + (with pkgs; [ + nixUnstable + ]) + ++ lib.optionals stdenv.isLinux [ cntr ]; + shellHook = '' export NIX_PATH=nixpkgs=${nixpkgs} export d2nExternalSources=${externalSourcesFor."${system}"} diff --git a/src/default.nix b/src/default.nix index deb4313d..e577953b 100644 --- a/src/default.nix +++ b/src/default.nix @@ -29,6 +29,10 @@ let externals = { npmlock2nix = pkgs.callPackage "${externalSources}/npmlock2nix/internal.nix" {}; node2nix = nodejs: pkgs.callPackage "${externalSources}/node2nix/node-env.nix" { inherit nodejs; }; + nix-parsec = rec { + lexer = import "${externalSources}/nix-parsec/lexer.nix" { inherit parsec; }; + parsec = import "${externalSources}/nix-parsec/parsec.nix"; + }; }; config = builtins.fromJSON (builtins.readFile ./config.json); diff --git a/src/translators/nodejs/pure/yarn-lock/default.nix b/src/translators/nodejs/pure/yarn-lock/default.nix new file mode 100644 index 00000000..70b634c6 --- /dev/null +++ b/src/translators/nodejs/pure/yarn-lock/default.nix @@ -0,0 +1,124 @@ +{ + lib, + + externals, + translatorName, + utils, + ... +}: + +{ + translate = + { + inputDirectories, + inputFiles, + ... + }: + let + yarnLock = + if inputDirectories != [] then + "${lib.elemAt inputDirectories 0}/yarn.lock" + else + lib.elemAt inputFiles 0; + parser = import ./parser.nix { inherit lib; inherit (externals) nix-parsec;}; + parsedLock = lib.foldAttrs (n: a: n // a) {} (parser.parseLock yarnLock).value; + nameFromLockName = lockName: + let + version = lib.last (lib.splitString "@" lockName); + in + lib.removeSuffix "@${version}" lockName; + sources = lib.mapAttrs' (dependencyName: dependencyAttrs: + let + name = nameFromLockName dependencyName; + in + lib.nameValuePair ("${name}#${dependencyAttrs.version}") ( + if ! lib.hasInfix "@github:" dependencyName then + { + version = dependencyAttrs.version; + hash = dependencyAttrs.integrity; + url = dependencyAttrs.resolved; + type = "fetchurl"; + } + else + let + gitUrlInfos = lib.splitString "/" dependencyAttrs.resolved; + in + { + type = "github"; + rev = lib.elemAt gitUrlInfos 6; + owner = lib.elemAt gitUrlInfos 3; + repo = lib.elemAt gitUrlInfos 4; + } + )) parsedLock; + dependencyGraph = lib.mapAttrs' (dependencyName: dependencyAttrs: + let + name = nameFromLockName dependencyName; + dependencies = dependencyAttrs.dependencies or [] ++ dependencyAttrs.optionalDependencies or []; + graph = lib.forEach dependencies (dependency: + builtins.head ( + lib.mapAttrsToList (name: value: + let + yarnName = "${name}@${value}"; + version = parsedLock."${yarnName}".version; + in + "${name}#${version}" + ) dependency + ) + ); + in + lib.nameValuePair ("${name}#${dependencyAttrs.version}") graph) parsedLock; + in + # TODO: produce dream lock like in /specifications/dream-lock-example.json + + rec { + inherit sources; + + generic = { + buildSystem = "nodejs"; + producedBy = translatorName; + mainPackage = "test"; + inherit dependencyGraph; + sourcesCombinedHash = null; + }; + + # build system specific attributes + buildSystem = { + + # example + nodejsVersion = 14; + }; + }; + + + # From a given list of paths, this function returns all paths which can be processed by this translator. + # This allows the framework to detect if the translator is compatible with the given inputs + # to automatically select the right translator. + compatiblePaths = + { + inputDirectories, + inputFiles, + }@args: + { + inputDirectories = lib.filter + (utils.containsMatchingFile [ ''.*yarn\.lock'' ''.*package.json'' ]) + args.inputDirectories; + + inputFiles = + lib.filter (f: builtins.match ''.*yarn\.lock'' f != null) args.inputFiles; + }; + + + # If the translator requires additional arguments, specify them here. + # There are only two types of arguments: + # - string argument (type = "argument") + # - boolean flag (type = "flag") + # String arguments contain a default value and examples. Flags do not. + specialArgs = { + + # optionalDependencies = { + # description = "Whether to include optional dependencies"; + # type = "flag"; + # }; + + }; +} diff --git a/src/translators/nodejs/pure/yarn-lock/parser.nix b/src/translators/nodejs/pure/yarn-lock/parser.nix new file mode 100644 index 00000000..f1401e0f --- /dev/null +++ b/src/translators/nodejs/pure/yarn-lock/parser.nix @@ -0,0 +1,76 @@ +# Example: parse a yarn.lock file +# +# Load in nix repl and test, e.g.: +# +# nix-repl> parseConfigFile ./yarn.lock +# { type = "success"; value = ...; } + +{ lib, nix-parsec }: + +with nix-parsec.parsec; + +rec { + inherit (nix-parsec) parsec; + + # Skip spaces and line comments and newlines + spaceComments = nix-parsec.lexer.space + (skipWhile1 (c: c == " " || c == "\t" || c == "\n")) + (nix-parsec.lexer.skipLineComment "#") + fail; + + charInsideQuotes = c: c != "\""; + charOutsideQuotes = c: c != "\"" && c != "\n" && c != " " && c != "," && c != ":"; + unquotedString = takeWhile1 charOutsideQuotes; + newLine = string "\n"; + + # use the nix-parsec quotedString + quotedString = between (string "\"") (string "\"") (takeWhile1 charInsideQuotes); + + # TODO add the relevant fmap to add the attributes + version = skipThen (string " version ") (thenSkip quotedString newLine); + # TODO instead of nextLine use an exact count of space and newline ?:w + resolved = skipThen (string " resolved ") (thenSkip quotedString newLine); + integrity = skipThen (string " integrity ") (thenSkip unquotedString newLine); + + dependencyList = thenSkip (sepBy singleDependency newLine) newLine; + dependencies = skipThen (string " dependencies:\n") dependencyList; + optionalDependencies = skipThen (string " optionalDependencies:\n") dependencyList; + + singleDependency = bind (skipThen (string " ") (alt quotedString unquotedString)) (parsed_dependency: + skipThen (string " ") ( + bind quotedString (parsed_version: + pure { "${parsed_dependency}" = parsed_version; } + ) + ) + ); + + dependencyNames = thenSkip (sepBy (alt quotedString unquotedString) (string ", ")) (string ":\n"); + + dependencyAttrs = bind version (parsedVersion: + bind resolved (parsedResolved: + bind (optional integrity) (parsedIntegrity: + bind (optional dependencies) (parsedDependencies: + bind (optional optionalDependencies) (parsedOptionalDependencies: + pure ( + { version = parsedVersion; resolved = parsedResolved; } + // + (if parsedIntegrity == [ ] then { } else { integrity = builtins.head parsedIntegrity; }) + // + (if parsedDependencies == [ ] then { } else { dependencies = builtins.head parsedDependencies; }) + // + (if parsedOptionalDependencies == [ ] then { } else { optionalDependencies = builtins.head parsedOptionalDependencies; }) + ) + ))))); + namesToAttrsList = namesList: dependencyAttrs: map (dependencyName: lib.nameValuePair dependencyName dependencyAttrs) namesList; + + group = + bind dependencyNames (namesList: + fmap (parsedAttrs: builtins.listToAttrs (namesToAttrsList namesList parsedAttrs)) + dependencyAttrs); + + configFile = + (skipThen spaceComments + (thenSkip (sepBy group newLine) eof)); + + parseLock = path: nix-parsec.parsec.runParser configFile (builtins.readFile path); +} From 40d3a3e46bf96dcae18051f7209b6f4ad3505e57 Mon Sep 17 00:00:00 2001 From: DavHau Date: Wed, 6 Oct 2021 13:32:53 +0700 Subject: [PATCH 2/2] different improvements: - templating for default.nix - templates for translators - fixup nodejs translators --- flake.nix | 1 - src/apps/cli/cli.py | 61 +++++++++++++------ src/apps/cli/default.nix | 10 +++ src/builders/nodejs/node2nix/default.nix | 11 +++- src/default.nix | 2 +- src/templates/translators/impure.nix | 27 ++++---- src/templates/translators/pure.nix | 27 ++++---- src/translators/default.nix | 2 +- .../nodejs/pure/npmlock2nix/default.nix | 16 +---- .../nodejs/pure/yarn-lock/default.nix | 15 ++--- src/{utils.nix => utils/default.nix} | 5 ++ src/utils/readDreamLock.nix | 28 +++++++++ 12 files changed, 132 insertions(+), 73 deletions(-) rename src/{utils.nix => utils/default.nix} (94%) create mode 100644 src/utils/readDreamLock.nix diff --git a/flake.nix b/flake.nix index 98732d12..02d45469 100644 --- a/flake.nix +++ b/flake.nix @@ -69,7 +69,6 @@ shellHook = '' export NIX_PATH=nixpkgs=${nixpkgs} - export d2nExternalSources=${externalSourcesFor."${system}"} ''; }); }; diff --git a/src/apps/cli/cli.py b/src/apps/cli/cli.py index 8dfa2378..4d9ff09a 100644 --- a/src/apps/cli/cli.py +++ b/src/apps/cli/cli.py @@ -45,6 +45,7 @@ class PackageCommand(Command): flag=False, multiple=True ), + option("force", None, "override existing files", flag=True), ] def handle(self): @@ -65,14 +66,20 @@ class PackageCommand(Command): output = './.' if not os.path.isdir(output): os.mkdir(output) - existingFiles = set(os.listdir(output)) - if any(f in existingFiles for f in ('default.nix', 'dream.lock')): - print( - f"output directory {output} already contains a default.nix " - "or dream.lock. Delete first!", - file=sys.stderr, - ) - exit(1) + filesToCreate = ('default.nix', 'dream.lock') + if self.option('force'): + for f in filesToCreate: + if os.path.isfile(f): + os.remove(f) + else: + existingFiles = set(os.listdir(output)) + if any(f in existingFiles for f in filesToCreate): + print( + f"output directory {output} already contains a 'default.nix' " + "or 'dream.lock'. Delete first, or user '--force'.", + file=sys.stderr, + ) + exit(1) output = os.path.realpath(output) outputDreamLock = f"{output}/dream.lock" outputDefaultNix = f"{output}/default.nix" @@ -96,8 +103,9 @@ class PackageCommand(Command): else: # check if source path exists if not os.path.exists(source): - raise print(f"Input path '{path}' does not exist", file=sys.stdout) + print(f"Input source '{source}' does not exist", file=sys.stdout) exit(1) + source = os.path.realpath(source) # select translator translatorsSorted = sorted( @@ -118,10 +126,22 @@ class PackageCommand(Command): 0 ) translator = chosen - translator = list(filter( - lambda t: [t['subsystem'], t['type'], t['name']] == translator.split(' (')[0].split('.'), - translatorsSorted, - ))[0] + translator = list(filter( + lambda t: [t['subsystem'], t['type'], t['name']] == translator.split(' (')[0].split('.'), + translatorsSorted, + ))[0] + else: + translator = translator.split('.') + if len(translator) == 3: + translator = list(filter( + lambda t: [t['subsystem'], t['type'], t['name']] == translator, + translatorsSorted, + ))[0] + elif len(translator) == 1: + translator = list(filter( + lambda t: [t['name']] == translator, + translatorsSorted, + ))[0] # raise error if any specified extra arg is unknown unknown_extra_args = set(specified_extra_args.keys()) - set(translator['specialArgs'].keys()) @@ -211,10 +231,11 @@ class PackageCommand(Command): type="unknown", version="unknown", ) - for field in ('versionField',): - if field in mainSource: - del mainSource[field] - mainSource['version'] = sourceSpec[sourceSpec['versionField']] + else: + for field in ('versionField',): + if field in mainSource: + del mainSource[field] + mainSource['version'] = sourceSpec[sourceSpec['versionField']] lock['sources'][mainPackage] = mainSource # clean up dependency graph @@ -290,8 +311,10 @@ class PackageCommand(Command): # create default.nix template = callNixFunction( - 'apps.apps.cli2.templateDefaultNix', - dream2nixLocationRelative=os.path.relpath(dream2nix_src, output) + 'apps.apps.cli.templateDefaultNix', + dream2nixLocationRelative=os.path.relpath(dream2nix_src, output), + dreamLock = lock, + sourcePathRelative = os.path.relpath(source, os.path.dirname(outputDefaultNix)) ) # with open(f"{dream2nix_src}/apps/cli2/templateDefault.nix") as template: with open(outputDefaultNix, 'w') as defaultNix: diff --git a/src/apps/cli/default.nix b/src/apps/cli/default.nix index 7449afbb..345bb397 100644 --- a/src/apps/cli/default.nix +++ b/src/apps/cli/default.nix @@ -29,7 +29,12 @@ in templateDefaultNix = { dream2nixLocationRelative, + dreamLock, + sourcePathRelative, }: + let + mainPackage = dreamLock.generic.mainPackage; + in '' { dream2nix ? import ${dream2nixLocationRelative} {}, @@ -37,6 +42,11 @@ in (dream2nix.riseAndShine { dreamLock = ./dream.lock; + ${lib.optionalString (dreamLock.sources."${mainPackage}".type == "unknown") '' + sourceOverrides = oldSources: { + "${mainPackage}" = ./${sourcePathRelative}; + }; + ''} }).package.overrideAttrs (old: { }) diff --git a/src/builders/nodejs/node2nix/default.nix b/src/builders/nodejs/node2nix/default.nix index 8eeac3ac..ac4dacb2 100644 --- a/src/builders/nodejs/node2nix/default.nix +++ b/src/builders/nodejs/node2nix/default.nix @@ -1,18 +1,23 @@ # builder imported from node2nix { - externals, - node2nix ? externals.node2nix, lib, pkgs, + + # dream2nix inputs + externals, + node2nix ? externals.node2nix, + utils, ... }: { fetchedSources, dreamLock, -}: +}@args: let + dreamLock = utils.readDreamLock { inherit (args) dreamLock; }; + mainPackageName = dreamLock.generic.mainPackage; nodejsVersion = dreamLock.buildSystem.nodejsVersion; diff --git a/src/default.nix b/src/default.nix index e577953b..bc3abdb4 100644 --- a/src/default.nix +++ b/src/default.nix @@ -14,7 +14,7 @@ let b = builtins; - utils = pkgs.callPackage ./utils.nix {}; + utils = callPackageDream ./utils {}; callPackageDream = f: args: pkgs.callPackage f (args // { inherit callPackageDream; diff --git a/src/templates/translators/impure.nix b/src/templates/translators/impure.nix index 3d2d9318..c43c9b24 100644 --- a/src/templates/translators/impure.nix +++ b/src/templates/translators/impure.nix @@ -42,12 +42,15 @@ inputFiles, }@args: { - inputDirectories = []; # TODO: insert regex here that matches valid input file names # examples: - # - ".*(requirements).*\\.txt" - # - ".*(package-lock\\.json)" - inputFiles = lib.filter (f: builtins.match "# TODO: your regex" f != null) args.inputFiles; + # - ''.*requirements.*\.txt'' + # - ''.*package-lock\.json'' + inputDirectories = lib.filter + (utils.containsMatchingFile [ ''TODO: regex1'' ''TODO: regex2'' ]) + args.inputDirectories; + + inputFiles = []; }; @@ -58,8 +61,14 @@ # String arguments contain a default value and examples. Flags do not. specialArgs = { + # Example: boolean option + # Flags always default to 'false' if not specified by the user + dev-dependenices = { + description = "Include dev dependencies"; + type = "flag"; + }; + # Example: string option - # This will be exposed by the translate CLI command as --arg_the-answer the-answer = { default = "42"; description = "The Answer to the Ultimate Question of Life"; @@ -70,13 +79,5 @@ type = "argument"; }; - # Example: boolean option - # This will be exposed by the translate CLI command as --flag_example-flag - # The default value of boolean flags is always false - flat-earth = { - description = "Is the earth flat"; - type = "flag"; - }; - }; } diff --git a/src/templates/translators/pure.nix b/src/templates/translators/pure.nix index 6c3bba9d..9186e73b 100644 --- a/src/templates/translators/pure.nix +++ b/src/templates/translators/pure.nix @@ -49,12 +49,15 @@ inputFiles, }@args: { - inputDirectories = []; # TODO: insert regex here that matches valid input file names # examples: - # - ".*(requirements).*\\.txt" - # - ".*(package-lock\\.json)" - inputFiles = lib.filter (f: builtins.match "# TODO: your regex" f != null) args.inputFiles; + # - ''.*requirements.*\.txt'' + # - ''.*package-lock\.json'' + inputDirectories = lib.filter + (utils.containsMatchingFile [ ''TODO: regex1'' ''TODO: regex2'' ]) + args.inputDirectories; + + inputFiles = []; }; @@ -65,8 +68,14 @@ # String arguments contain a default value and examples. Flags do not. specialArgs = { + # Example: boolean option + # Flags always default to 'false' if not specified by the user + dev-dependenices = { + description = "Include dev dependencies"; + type = "flag"; + }; + # Example: string option - # This will be exposed by the translate CLI command as --arg_the-answer the-answer = { default = "42"; description = "The Answer to the Ultimate Question of Life"; @@ -77,13 +86,5 @@ type = "argument"; }; - # Example: boolean option - # This will be exposed by the translate CLI command as --flag_example-flag - # The default value of boolean flags is always false - flat-earth = { - description = "Is the earth flat"; - type = "flag"; - }; - }; } diff --git a/src/translators/default.nix b/src/translators/default.nix index 710642b8..16a84709 100644 --- a/src/translators/default.nix +++ b/src/translators/default.nix @@ -51,7 +51,7 @@ let jsonInputFile=$(realpath $1) outputFile=$(${pkgs.jq}/bin/jq '.outputFile' -c -r $jsonInputFile) - nix eval --impure --raw --expr " + nix eval --show-trace --impure --raw --expr " builtins.toJSON ( (import ${dream2nixWithExternals} {}).translators.translators.${ lib.concatStringsSep "." translatorAttrPath diff --git a/src/translators/nodejs/pure/npmlock2nix/default.nix b/src/translators/nodejs/pure/npmlock2nix/default.nix index 64b26fe7..be6deb34 100644 --- a/src/translators/nodejs/pure/npmlock2nix/default.nix +++ b/src/translators/nodejs/pure/npmlock2nix/default.nix @@ -65,7 +65,7 @@ # handle github dependency if pdata ? from && pdata ? version then let - githubData = parseGithubDepedency pdata; + githubData = parseGithubDependency pdata; in [ rec { name = "${pname}#${version}"; @@ -77,7 +77,7 @@ depsExact = pdata.depsExact; }] # handle http(s) dependency - else + else [rec { name = "${pname}#${version}"; version = pdata.version; @@ -125,15 +125,6 @@ producedBy = translatorName; mainPackage = parsed.name; dependencyGraph = - { - "${parsed.name}" = - lib.mapAttrsToList - (pname: pdata: "${pname}#${getVersion pdata}") - (lib.filterAttrs - (pname: pdata: ! (pdata.dev or false) || dev) - parsed.dependencies); - } - // lib.listToAttrs (map (dep: lib.nameValuePair dep.name dep.depsExact) @@ -157,8 +148,7 @@ (utils.containsMatchingFile [ ''.*package-lock\.json'' ''.*package.json'' ]) args.inputDirectories; - inputFiles = - lib.filter (f: builtins.match ''.*package-lock\.json'' f != null) args.inputFiles; + inputFiles = []; }; specialArgs = { diff --git a/src/translators/nodejs/pure/yarn-lock/default.nix b/src/translators/nodejs/pure/yarn-lock/default.nix index 70b634c6..e6006fc0 100644 --- a/src/translators/nodejs/pure/yarn-lock/default.nix +++ b/src/translators/nodejs/pure/yarn-lock/default.nix @@ -15,11 +15,9 @@ ... }: let - yarnLock = - if inputDirectories != [] then - "${lib.elemAt inputDirectories 0}/yarn.lock" - else - lib.elemAt inputFiles 0; + b = builtins; + yarnLock = "${lib.elemAt inputDirectories 0}/yarn.lock"; + packageJSON = b.fromJSON (b.readFile "${lib.elemAt inputDirectories 0}/package.json"); parser = import ./parser.nix { inherit lib; inherit (externals) nix-parsec;}; parsedLock = lib.foldAttrs (n: a: n // a) {} (parser.parseLock yarnLock).value; nameFromLockName = lockName: @@ -36,7 +34,7 @@ { version = dependencyAttrs.version; hash = dependencyAttrs.integrity; - url = dependencyAttrs.resolved; + url = lib.head (lib.splitString "#" dependencyAttrs.resolved); type = "fetchurl"; } else @@ -76,7 +74,7 @@ generic = { buildSystem = "nodejs"; producedBy = translatorName; - mainPackage = "test"; + mainPackage = packageJSON.name; inherit dependencyGraph; sourcesCombinedHash = null; }; @@ -103,8 +101,7 @@ (utils.containsMatchingFile [ ''.*yarn\.lock'' ''.*package.json'' ]) args.inputDirectories; - inputFiles = - lib.filter (f: builtins.match ''.*yarn\.lock'' f != null) args.inputFiles; + inputFiles = []; }; diff --git a/src/utils.nix b/src/utils/default.nix similarity index 94% rename from src/utils.nix rename to src/utils/default.nix index 96a04e6f..3b51ef41 100644 --- a/src/utils.nix +++ b/src/utils/default.nix @@ -4,6 +4,9 @@ nix, runCommand, writeScriptBin, + + # dream2nix inputs + callPackageDream, ... }: let @@ -12,6 +15,8 @@ in rec { + readDreamLock = callPackageDream ./readDreamLock.nix {}; + isFile = path: (builtins.readDir (b.dirOf path))."${b.baseNameOf path}" == "regular"; isDir = path: (builtins.readDir (b.dirOf path))."${b.baseNameOf path}" == "directory"; diff --git a/src/utils/readDreamLock.nix b/src/utils/readDreamLock.nix new file mode 100644 index 00000000..ae74d5ed --- /dev/null +++ b/src/utils/readDreamLock.nix @@ -0,0 +1,28 @@ +{ + lib, + ... +}: +let + b = builtins; +in +{ + dreamLock, +}@args: +let + + lock = + if b.isPath dreamLock then + b.fromJSON (b.readFile dreamLock) + else + dreamLock; + + mainPackage = lock.generic.mainPackage; + + dependencyGraph = lock.generic.dependencyGraph; + +in +lib.recursiveUpdate + lock + { + generic.dependencyGraph."${mainPackage}" = dependencyGraph."${mainPackage}" or lib.attrNames dependencyGraph; + }