This commit is contained in:
Yusuf Bera Ertan 2022-10-06 20:42:04 +03:00
parent 65120af9f6
commit fe38f28ba8
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
40 changed files with 760 additions and 834 deletions

View File

@ -51,7 +51,7 @@ in let
};
framework = import ./modules/framework.nix {
inherit apps lib dlib pkgs utils;
inherit apps lib dlib pkgs utils externals externalSources;
dream2nixConfig = config;
};

View File

@ -1,18 +1,17 @@
{lib, ...}: {
{
pkgs,
utils,
...
}: {
inputs = ["pname" "version"];
versionField = "version";
outputs = {
fetchurl,
runCommandLocal,
utils,
...
}: {
pname,
version,
...
} @ inp: let
}: let
b = builtins;
# See https://github.com/rust-lang/crates.io-index/blob/master/config.json#L2
url = "https://crates.io/api/v1/crates/${pname}/${version}/download";
@ -23,13 +22,13 @@
});
fetched = hash: let
fetched = fetchurl {
fetched = pkgs.fetchurl {
inherit url;
sha256 = hash;
name = "download-${pname}-${version}";
};
in
runCommandLocal "unpack-${pname}-${version}" {}
pkgs.runCommandLocal "unpack-${pname}-${version}" {}
''
mkdir -p $out
tar --strip-components 1 -xzf ${fetched} -C $out

View File

@ -1,4 +1,9 @@
{lib, ...}: let
{
pkgs,
lib,
utils,
...
}: let
b = builtins;
# check if a string is a git ref
@ -14,10 +19,6 @@ in {
versionField = "rev";
outputs = {
fetchgit,
utils,
...
}: {
url,
rev,
submodules ? true,
@ -78,7 +79,7 @@ in {
inherit submodules;
})
else
fetchgit
pkgs.fetchgit
(refAndRev
// {
inherit url;

View File

@ -1,4 +1,9 @@
{lib, ...}: {
{
pkgs,
lib,
utils,
...
}: {
inputs = [
"owner"
"repo"
@ -10,15 +15,11 @@
defaultUpdater = "githubNewestReleaseTag";
outputs = {
fetchFromGitHub,
utils,
...
}: {
owner,
repo,
rev,
...
} @ inp: let
}: let
b = builtins;
in {
calcHash = algo:
@ -27,7 +28,7 @@
});
fetched = hash:
fetchFromGitHub {
pkgs.fetchFromGitHub {
inherit owner repo rev hash;
};
};

View File

@ -1,4 +1,8 @@
{...}: {
{
pkgs,
utils,
...
}: {
inputs = [
"owner"
"repo"
@ -8,15 +12,11 @@
versionField = "rev";
outputs = {
fetchFromGitLab,
utils,
...
}: {
owner,
repo,
rev,
...
} @ inp: let
}: let
b = builtins;
in {
calcHash = algo:
@ -25,7 +25,7 @@
});
fetched = hash:
fetchFromGitLab {
pkgs.fetchFromGitLab {
inherit owner repo rev hash;
};
};

View File

@ -1,13 +1,14 @@
{lib, ...}: {
{
pkgs,
lib,
utils,
...
}: {
inputs = [
"url"
];
outputs = {
fetchurl,
utils,
...
}: {url, ...} @ inp: let
outputs = {url, ...}: let
b = builtins;
in {
calcHash = algo:
@ -19,12 +20,12 @@
drv =
if hash != null && lib.stringLength hash == 40
then
fetchurl {
pkgs.fetchurl {
inherit url;
sha1 = hash;
}
else
fetchurl {
pkgs.fetchurl {
inherit url hash;
};

View File

@ -1,4 +1,9 @@
{lib, ...}: let
{
pkgs,
lib,
utils,
...
}: let
b = builtins;
in rec {
inputs = ["pname" "version"];
@ -36,14 +41,9 @@ in rec {
# defaultUpdater = "";
outputs = {
python3,
utils,
fetchurl,
...
}: {
pname,
version,
} @ inp: let
}: let
b = builtins;
submodule = lib.last (lib.splitString "/" pname);
@ -56,7 +56,7 @@ in rec {
fetched = hash: let
source =
(fetchurl {
(pkgs.fetchurl {
inherit url;
sha256 = hash;
})

View File

@ -1,11 +1,9 @@
{...}: {
{utils, ...}: {
inputs = [
"path"
];
outputs = {utils, ...}: {path, ...} @ inp: let
b = builtins;
in {
outputs = {path, ...}: {
calcHash = algo: utils.hashPath "${path}";
fetched = hash: "${path}";

View File

@ -1,4 +1,8 @@
{...}: {
{
pkgs,
utils,
...
}: {
inputs = ["pname" "version"];
versionField = "version";
@ -6,15 +10,10 @@
defaultUpdater = "pypiNewestReleaseVersion";
outputs = {
fetchurl,
python3,
utils,
...
}: {
pname,
version,
extension ? "tar.gz",
} @ inp: let
}: let
b = builtins;
firstChar = builtins.substring 0 1 pname;
@ -29,7 +28,7 @@
fetched = hash: let
source =
(fetchurl {
(pkgs.fetchurl {
inherit url;
sha256 = hash;
})

View File

@ -90,11 +90,12 @@
dlib = import ./lib {inherit lib config;};
framework = import ./modules/framework.nix {
inherit lib dlib;
inherit lib dlib externalSources;
dream2nixConfig = config;
apps = throw "apps is not available before nixpkgs is imported";
pkgs = throw "pkgs is not available before nixpkgs is imported";
utils = throw "utils is not available before nixpkgs is imported";
externals = throw "externals is not available before nixpkgs is imported";
};
initD2N = initDream2nix config;

View File

@ -9,7 +9,7 @@
debian = "simple-debian";
racket = "simple-racket";
};
funcs = config.functions.subsystem-loading;
funcs = import ../subsystem-loading.nix config;
collectedModules = funcs.collect "builders";
in {
config = {

View File

@ -1,5 +1,5 @@
{config, ...}: let
funcs = config.functions.subsystem-loading;
funcs = import ../subsystem-loading.nix config;
collectedModules = funcs.collect "discoverers";
in {
config = {

View File

@ -2,13 +2,13 @@
dream2nixConfig,
pkgs,
dlib,
externals,
externalSources,
lib,
utils,
apps,
}: let
topLevel = import ./top-level.nix {
inherit apps lib dlib utils pkgs dream2nixConfig;
};
} @ args: let
topLevel = import ./top-level.nix args;
evaledModules = lib.evalModules {
modules = [topLevel] ++ (dream2nixConfig.modules or []);
};

View File

@ -1,6 +0,0 @@
{
imports = [
./implementation.nix
./interface.nix
];
}

View File

@ -1,35 +0,0 @@
{config, ...}: let
lib = config.lib;
t = lib.types;
in {
options.functions.subsystem-loading = {
collect = lib.mkOption {
type = t.functionTo t.anything;
description = ''
Discover modules in /src/subsystems/{subsystem}/{module-type}/{module-name}
'';
};
import_ = lib.mkOption {
type = t.functionTo t.anything;
description = ''
Imports discovered module files.
Adds name and subsystem attributes to each module derived from the path.
'';
};
instantiate = lib.mkOption {
type = t.functionTo t.anything;
description = ''
To keep module implementations simpler, additional generic logic is added
by a loader.
The loader is subsytem specific and needs to be passed as an argument.
'';
};
structureBySubsystem = lib.mkOption {
type = t.functionTo t.anything;
description = ''
re-structures the instantiated instances into a deeper attrset like:
{subsytem}.{module-name} = ...
'';
};
};
}

View File

@ -5,10 +5,12 @@ translators and builders.
This recurses through the following directory structure to discover and load
modules:
/src/subsystems/{subsystem}/{module-type}/{module-name}
This is not included in `config.functions` because it causes infinite recursion.
*/
{config, ...}: let
config: let
inherit (config) dlib lib;
subsystemsDir = lib.toString ../../subsystems;
subsystemsDir = lib.toString ../subsystems;
subsystems = dlib.dirNames subsystemsDir;
collect = moduleDirName:
@ -35,9 +37,12 @@ modules:
import_ = collectedModules:
lib.mapAttrs
(name: description:
(import description.path config)
// {inherit (description) name subsystem;})
(
name: description: let
attrs = {inherit (description) name subsystem;};
in
(import description.path (config // attrs)) // attrs
)
(
lib.foldl'
(
@ -54,13 +59,6 @@ modules:
collectedModules
);
instantiate = importedModules: loader:
lib.mapAttrs
(name: module:
(loader module)
// {inherit (module) name subsystem;})
importedModules;
structureBySubsystem = instances:
lib.foldl
lib.recursiveUpdate
@ -69,15 +67,9 @@ modules:
(tName: t: {"${t.subsystem}"."${tName}" = t;})
instances);
in {
/*
Expose the functions via via the modules system.
*/
config.functions.subsystem-loading = {
inherit
collect
import_
instantiate
structureBySubsystem
;
};
inherit
collect
import_
structureBySubsystem
;
}

View File

@ -1,6 +1,8 @@
{
apps,
dlib,
externals,
externalSources,
lib,
pkgs,
utils,
@ -14,7 +16,6 @@ in {
./functions.default-fetcher
./functions.combined-fetcher
./functions.translators
./functions.subsystem-loading
./builders
./discoverers
./discoverers.default-discoverer
@ -31,6 +32,12 @@ in {
dlib = lib.mkOption {
type = t.raw;
};
externals = lib.mkOption {
type = t.raw;
};
externalSources = lib.mkOption {
type = t.raw;
};
pkgs = lib.mkOption {
type = t.raw;
};
@ -42,7 +49,7 @@ in {
};
};
config = {
inherit apps dlib pkgs utils dream2nixConfig;
inherit apps dlib externals externalSources pkgs utils dream2nixConfig;
lib = lib // builtins;
};
}

View File

@ -1,5 +1,5 @@
{config, ...}: let
funcs = config.functions.subsystem-loading;
funcs = import ../subsystem-loading.nix config;
collectedModules = funcs.collect "translators";
in {
config = {

View File

@ -1,17 +1,15 @@
{lib, ...}: let
{
pkgs,
utils,
externals,
lib,
...
}: let
l = lib // builtins;
in {
type = "pure";
build = {
lib,
pkgs,
stdenv,
# dream2nix inputs
externals,
utils,
...
}: {
### FUNCTIONS
# AttrSet -> Bool) -> AttrSet -> [x]
getCyclicDependencies, # name: version: -> [ {name=; version=; } ]
@ -37,8 +35,6 @@ in {
produceDerivation,
...
} @ args: let
b = builtins;
compiler =
pkgs
.haskell

View File

@ -1,6 +1,7 @@
{
dlib,
lib,
name,
...
}: let
l = lib // builtins;
@ -37,7 +38,7 @@ in {
l.pathExists "${tree.fullPath}/dist-newstyle/cache/plan.json";
# translate from a given source and a project specification to a dream-lock.
translate = {translatorName, ...}: {
translate = {
/*
A list of projects returned by `discoverProjects`
Example:
@ -189,7 +190,7 @@ in {
in
dlib.simpleTranslate2.translate
({objectsByKey, ...}: rec {
inherit translatorName;
translatorName = name;
# relative path of the project within the source tree.
location = project.relPath;

View File

@ -1,10 +1,9 @@
{
dlib,
lib,
pkgs,
utils,
translators,
...
}: let
l = lib // builtins;
in {
}: {
type = "impure";
# A derivation which outputs a single executable at `$out`.
@ -18,24 +17,21 @@ in {
# by the input parameter `outFile`.
# The output file must contain the dream lock data encoded as json.
# See /src/specifications/dream-lock-example.json
translateBin = {
# dream2nix utils
subsystems,
utils,
# nixpkgs dependenies
bash,
coreutils,
curl,
gnutar,
gzip,
haskellPackages,
jq,
moreutils,
nix,
python3,
writeScriptBin,
...
}:
translateBin = let
inherit
(pkgs)
bash
coreutils
curl
gnutar
gzip
haskellPackages
jq
moreutils
nix
python3
;
in
utils.writePureShellScript
[
bash
@ -86,7 +82,7 @@ in {
popd
# execute cabal-plan translator
${subsystems.haskell.translators.cabal-plan.translateBin} $TMPDIR/newJsonInput
${translators.cabal-plan.translateBin} $TMPDIR/newJsonInput
# finalize dream-lock. Add source and export default package
# set correct package version under `packages`
@ -105,22 +101,5 @@ in {
# - boolean flag (type = "flag")
# String arguments contain a default value and examples. Flags do not.
extraArgs = {
# Example: boolean option
# Flags always default to 'false' if not specified by the user
noDev = {
description = "Exclude dev dependencies";
type = "flag";
};
# Example: string option
theAnswer = {
default = "42";
description = "The Answer to the Ultimate Question of Life";
examples = [
"0"
"1234"
];
type = "argument";
};
};
}

View File

@ -1,6 +1,9 @@
{
dlib,
lib,
pkgs,
utils,
name,
...
}: let
l = lib // builtins;
@ -71,12 +74,7 @@ in {
(l.attrNames tree.files);
# translate from a given source and a project specification to a dream-lock.
translate = {
translatorName,
pkgs,
utils,
...
}: let
translate = let
stackLockUtils = import ./utils.nix {inherit dlib lib pkgs;};
all-cabal-hashes = let
all-cabal-hashes' = pkgs.runCommandLocal "all-cabal-hashes" {} ''
@ -231,7 +229,7 @@ in {
in
dlib.simpleTranslate2.translate
({objectsByKey, ...}: rec {
inherit translatorName;
translatorName = name;
# relative path of the project within the source tree.
location = project.relPath;

View File

@ -1,511 +1,515 @@
{...}: {
{
pkgs,
lib,
...
}: {
type = "pure";
build = {
jq,
lib,
makeWrapper,
mkShell,
pkgs,
python3,
runCommandLocal,
stdenv,
writeText,
...
}: {
# Funcs
# AttrSet -> Bool) -> AttrSet -> [x]
getCyclicDependencies, # name: version: -> [ {name=; version=; } ]
getDependencies, # name: version: -> [ {name=; version=; } ]
getSource, # name: version: -> store-path
# Attributes
subsystemAttrs, # attrset
defaultPackageName, # string
defaultPackageVersion, # string
packages, # list
# attrset of pname -> versions,
# where versions is a list of version strings
packageVersions,
# function which applies overrides to a package
# It must be applied by the builder to each individual derivation
# Example:
# produceDerivation name (mkDerivation {...})
produceDerivation,
nodejs ? null,
...
} @ args: let
b = builtins;
l = lib // builtins;
build = let
inherit
(pkgs)
jq
makeWrapper
mkShell
python3
runCommandLocal
stdenv
;
in
{
# Funcs
# AttrSet -> Bool) -> AttrSet -> [x]
getCyclicDependencies, # name: version: -> [ {name=; version=; } ]
getDependencies, # name: version: -> [ {name=; version=; } ]
getSource, # name: version: -> store-path
# Attributes
subsystemAttrs, # attrset
defaultPackageName, # string
defaultPackageVersion, # string
packages, # list
# attrset of pname -> versions,
# where versions is a list of version strings
packageVersions,
# function which applies overrides to a package
# It must be applied by the builder to each individual derivation
# Example:
# produceDerivation name (mkDerivation {...})
produceDerivation,
nodejs ? null,
...
} @ args: let
b = builtins;
l = lib // builtins;
nodejsVersion = subsystemAttrs.nodejsVersion;
nodejsVersion = subsystemAttrs.nodejsVersion;
isMainPackage = name: version:
(args.packages."${name}" or null) == version;
isMainPackage = name: version:
(args.packages."${name}" or null) == version;
nodejs =
if args ? nodejs
then b.toString args.nodejs
else
pkgs."nodejs-${nodejsVersion}_x"
or (throw "Could not find nodejs version '${nodejsVersion}' in pkgs");
nodejs =
if args ? nodejs
then b.toString args.nodejs
else
pkgs."nodejs-${nodejsVersion}_x"
or (throw "Could not find nodejs version '${nodejsVersion}' in pkgs");
nodeSources = runCommandLocal "node-sources" {} ''
tar --no-same-owner --no-same-permissions -xf ${nodejs.src}
mv node-* $out
'';
allPackages =
lib.mapAttrs
(name: versions:
lib.genAttrs
versions
(version:
makePackage name version))
packageVersions;
outputs = rec {
# select only the packages listed in dreamLock as main packages
packages =
b.foldl'
(ps: p: ps // p)
{}
(lib.mapAttrsToList
(name: version: {
"${name}"."${version}" = allPackages."${name}"."${version}";
})
args.packages);
devShells =
{default = devShells.${defaultPackageName};}
// (
l.mapAttrs
(name: version: allPackages.${name}.${version}.devShell)
args.packages
);
};
# This is only executed for electron based packages.
# Electron ships its own version of node, requiring a rebuild of native
# extensions.
# Theoretically this requires headers for the exact electron version in use,
# but we use the headers from nixpkgs' electron instead which might have a
# different minor version.
# Alternatively the headers can be specified via `electronHeaders`.
# Also a custom electron version can be specified via `electronPackage`
electron-rebuild = ''
# prepare node headers for electron
if [ -n "$electronPackage" ]; then
export electronDist="$electronPackage/lib/electron"
else
export electronDist="$nodeModules/$packageName/node_modules/electron/dist"
fi
local ver
ver="v$(cat $electronDist/version | tr -d '\n')"
mkdir $TMP/$ver
cp $electronHeaders $TMP/$ver/node-$ver-headers.tar.gz
# calc checksums
cd $TMP/$ver
sha256sum ./* > SHASUMS256.txt
cd -
# serve headers via http
python -m http.server 45034 --directory $TMP &
# copy electron distribution
cp -r $electronDist $TMP/electron
chmod -R +w $TMP/electron
# configure electron toolchain
${pkgs.jq}/bin/jq ".build.electronDist = \"$TMP/electron\"" package.json \
| ${pkgs.moreutils}/bin/sponge package.json
${pkgs.jq}/bin/jq ".build.linux.target = \"dir\"" package.json \
| ${pkgs.moreutils}/bin/sponge package.json
${pkgs.jq}/bin/jq ".build.npmRebuild = false" package.json \
| ${pkgs.moreutils}/bin/sponge package.json
# execute electron-rebuild if available
export headers=http://localhost:45034/
if command -v electron-rebuild &> /dev/null; then
pushd $electronAppDir
electron-rebuild -d $headers
popd
fi
'';
# Only executed for electron based packages.
# Creates an executable script under /bin starting the electron app
electron-wrap =
if pkgs.stdenv.isLinux
then ''
mkdir -p $out/bin
makeWrapper \
$electronDist/electron \
$out/bin/$(basename "$packageName") \
--add-flags "$(realpath $electronAppDir)"
''
else ''
mkdir -p $out/bin
makeWrapper \
$electronDist/Electron.app/Contents/MacOS/Electron \
$out/bin/$(basename "$packageName") \
--add-flags "$(realpath $electronAppDir)"
nodeSources = runCommandLocal "node-sources" {} ''
tar --no-same-owner --no-same-permissions -xf ${nodejs.src}
mv node-* $out
'';
# Generates a derivation for a specific package name + version
makePackage = name: version: let
pname = lib.replaceStrings ["@" "/"] ["__at__" "__slash__"] name;
allPackages =
lib.mapAttrs
(name: versions:
lib.genAttrs
versions
(version:
makePackage name version))
packageVersions;
deps = getDependencies name version;
outputs = rec {
# select only the packages listed in dreamLock as main packages
packages =
b.foldl'
(ps: p: ps // p)
{}
(lib.mapAttrsToList
(name: version: {
"${name}"."${version}" = allPackages."${name}"."${version}";
})
args.packages);
nodeDeps =
lib.forEach
deps
(dep: allPackages."${dep.name}"."${dep.version}");
devShells =
{default = devShells.${defaultPackageName};}
// (
l.mapAttrs
(name: version: allPackages.${name}.${version}.devShell)
args.packages
);
};
passthruDeps =
l.listToAttrs
(l.forEach deps
(dep:
l.nameValuePair
dep.name
allPackages."${dep.name}"."${dep.version}"));
dependenciesJson =
b.toJSON
(lib.listToAttrs
(b.map
(dep: lib.nameValuePair dep.name dep.version)
deps));
electronDep =
if ! isMainPackage name version
then null
# This is only executed for electron based packages.
# Electron ships its own version of node, requiring a rebuild of native
# extensions.
# Theoretically this requires headers for the exact electron version in use,
# but we use the headers from nixpkgs' electron instead which might have a
# different minor version.
# Alternatively the headers can be specified via `electronHeaders`.
# Also a custom electron version can be specified via `electronPackage`
electron-rebuild = ''
# prepare node headers for electron
if [ -n "$electronPackage" ]; then
export electronDist="$electronPackage/lib/electron"
else
lib.findFirst
(dep: dep.name == "electron")
null
deps;
export electronDist="$nodeModules/$packageName/node_modules/electron/dist"
fi
local ver
ver="v$(cat $electronDist/version | tr -d '\n')"
mkdir $TMP/$ver
cp $electronHeaders $TMP/$ver/node-$ver-headers.tar.gz
electronVersionMajor =
lib.versions.major electronDep.version;
# calc checksums
cd $TMP/$ver
sha256sum ./* > SHASUMS256.txt
cd -
electronHeaders =
if
(electronDep == null)
# hashes seem unavailable for electron < 4
|| ((l.toInt electronVersionMajor) <= 2)
then null
else pkgs."electron_${electronVersionMajor}".headers;
# serve headers via http
python -m http.server 45034 --directory $TMP &
pkg = produceDerivation name (stdenv.mkDerivation rec {
inherit
dependenciesJson
electronHeaders
nodeDeps
nodeSources
version
;
# copy electron distribution
cp -r $electronDist $TMP/electron
chmod -R +w $TMP/electron
packageName = name;
# configure electron toolchain
${pkgs.jq}/bin/jq ".build.electronDist = \"$TMP/electron\"" package.json \
| ${pkgs.moreutils}/bin/sponge package.json
inherit pname;
${pkgs.jq}/bin/jq ".build.linux.target = \"dir\"" package.json \
| ${pkgs.moreutils}/bin/sponge package.json
meta = let
meta = subsystemAttrs.meta;
in
meta
// {
license = l.map (name: l.licenses.${name}) meta.license;
${pkgs.jq}/bin/jq ".build.npmRebuild = false" package.json \
| ${pkgs.moreutils}/bin/sponge package.json
# execute electron-rebuild if available
export headers=http://localhost:45034/
if command -v electron-rebuild &> /dev/null; then
pushd $electronAppDir
electron-rebuild -d $headers
popd
fi
'';
# Only executed for electron based packages.
# Creates an executable script under /bin starting the electron app
electron-wrap =
if pkgs.stdenv.isLinux
then ''
mkdir -p $out/bin
makeWrapper \
$electronDist/electron \
$out/bin/$(basename "$packageName") \
--add-flags "$(realpath $electronAppDir)"
''
else ''
mkdir -p $out/bin
makeWrapper \
$electronDist/Electron.app/Contents/MacOS/Electron \
$out/bin/$(basename "$packageName") \
--add-flags "$(realpath $electronAppDir)"
'';
# Generates a derivation for a specific package name + version
makePackage = name: version: let
pname = lib.replaceStrings ["@" "/"] ["__at__" "__slash__"] name;
deps = getDependencies name version;
nodeDeps =
lib.forEach
deps
(dep: allPackages."${dep.name}"."${dep.version}");
passthruDeps =
l.listToAttrs
(l.forEach deps
(dep:
l.nameValuePair
dep.name
allPackages."${dep.name}"."${dep.version}"));
dependenciesJson =
b.toJSON
(lib.listToAttrs
(b.map
(dep: lib.nameValuePair dep.name dep.version)
deps));
electronDep =
if ! isMainPackage name version
then null
else
lib.findFirst
(dep: dep.name == "electron")
null
deps;
electronVersionMajor =
lib.versions.major electronDep.version;
electronHeaders =
if
(electronDep == null)
# hashes seem unavailable for electron < 4
|| ((l.toInt electronVersionMajor) <= 2)
then null
else pkgs."electron_${electronVersionMajor}".headers;
pkg = produceDerivation name (stdenv.mkDerivation rec {
inherit
dependenciesJson
electronHeaders
nodeDeps
nodeSources
version
;
packageName = name;
inherit pname;
meta = let
meta = subsystemAttrs.meta;
in
meta
// {
license = l.map (name: l.licenses.${name}) meta.license;
};
passthru.dependencies = passthruDeps;
passthru.devShell = import ./devShell.nix {
inherit
mkShell
nodejs
packageName
pkg
;
};
passthru.dependencies = passthruDeps;
/*
For top-level packages install dependencies as full copies, as this
reduces errors with build tooling that doesn't cope well with
symlinking.
*/
installMethod =
if isMainPackage name version
then "copy"
else "symlink";
passthru.devShell = import ./devShell.nix {
inherit
mkShell
nodejs
packageName
pkg
;
};
electronAppDir = ".";
/*
For top-level packages install dependencies as full copies, as this
reduces errors with build tooling that doesn't cope well with
symlinking.
*/
installMethod =
if isMainPackage name version
then "copy"
else "symlink";
# only run build on the main package
runBuild = isMainPackage name version;
electronAppDir = ".";
src = getSource name version;
# only run build on the main package
runBuild = isMainPackage name version;
nativeBuildInputs = [makeWrapper];
src = getSource name version;
buildInputs = [jq nodejs python3];
nativeBuildInputs = [makeWrapper];
# prevents running into ulimits
passAsFile = ["dependenciesJson" "nodeDeps"];
buildInputs = [jq nodejs python3];
preConfigurePhases = ["d2nLoadFuncsPhase" "d2nPatchPhase"];
# prevents running into ulimits
passAsFile = ["dependenciesJson" "nodeDeps"];
# can be overridden to define alternative install command
# (defaults to 'npm run postinstall')
buildScript = null;
preConfigurePhases = ["d2nLoadFuncsPhase" "d2nPatchPhase"];
# python script to modify some metadata to support installation
# (see comments below on d2nPatchPhase)
fixPackage = "${./fix-package.py}";
# can be overridden to define alternative install command
# (defaults to 'npm run postinstall')
buildScript = null;
# script to install (symlink or copy) dependencies.
installDeps = "${./install-deps.py}";
# python script to modify some metadata to support installation
# (see comments below on d2nPatchPhase)
fixPackage = "${./fix-package.py}";
# python script to link bin entries from package.json
linkBins = "${./link-bins.py}";
# script to install (symlink or copy) dependencies.
installDeps = "${./install-deps.py}";
# costs performance and doesn't seem beneficial in most scenarios
dontStrip = true;
# python script to link bin entries from package.json
linkBins = "${./link-bins.py}";
# declare some useful shell functions
d2nLoadFuncsPhase = ''
# function to resolve symlinks to copies
symlinksToCopies() {
local dir="$1"
# costs performance and doesn't seem beneficial in most scenarios
dontStrip = true;
# declare some useful shell functions
d2nLoadFuncsPhase = ''
# function to resolve symlinks to copies
symlinksToCopies() {
local dir="$1"
echo "transforming symlinks to copies..."
for f in $(find -L "$dir" -xtype l); do
if [ -f $f ]; then
continue
fi
echo "copying $f"
chmod +wx $(dirname "$f")
mv "$f" "$f.bak"
mkdir "$f"
if [ -n "$(ls -A "$f.bak/")" ]; then
cp -r "$f.bak"/* "$f/"
chmod -R +w $f
fi
rm "$f.bak"
done
}
'';
# TODO: upstream fix to nixpkgs
# example which requires this:
# https://registry.npmjs.org/react-window-infinite-loader/-/react-window-infinite-loader-1.0.7.tgz
unpackCmd =
if lib.hasSuffix ".tgz" src
then "tar --delay-directory-restore -xf $src"
else null;
unpackPhase = ''
runHook preUnpack
nodeModules=$out/lib/node_modules
export sourceRoot="$nodeModules/$packageName"
# sometimes tarballs do not end with .tar.??
unpackFallback(){
local fn="$1"
tar xf "$fn"
}
unpackCmdHooks+=(unpackFallback)
unpackFile $src
# Make the base dir in which the target dependency resides in first
mkdir -p "$(dirname "$sourceRoot")"
# install source
if [ -f "$src" ]
then
# Figure out what directory has been unpacked
export packageDir="$(find . -maxdepth 1 -type d | tail -1)"
# Restore write permissions
find "$packageDir" -type d -exec chmod u+x {} \;
chmod -R u+w -- "$packageDir"
# Move the extracted tarball into the output folder
mv -- "$packageDir" "$sourceRoot"
elif [ -d "$src" ]
then
export strippedName="$(stripHash $src)"
# Restore write permissions
chmod -R u+w -- "$strippedName"
# Move the extracted directory into the output folder
mv -- "$strippedName" "$sourceRoot"
fi
runHook postUnpack
'';
# The python script wich is executed in this phase:
# - ensures that the package is compatible to the current system
# - ensures the main version in package.json matches the expected
# - pins dependency versions in package.json
# (some npm commands might otherwise trigger networking)
# - creates symlinks for executables declared in package.json
# Apart from that:
# - Any usage of 'link:' in package.json is replaced with 'file:'
# - If package-lock.json exists, it is deleted, as it might conflict
# with the parent package-lock.json.
d2nPatchPhase = ''
# delete package-lock.json as it can lead to conflicts
rm -f package-lock.json
# repair 'link:' -> 'file:'
mv $nodeModules/$packageName/package.json $nodeModules/$packageName/package.json.old
cat $nodeModules/$packageName/package.json.old | sed 's!link:!file\:!g' > $nodeModules/$packageName/package.json
rm $nodeModules/$packageName/package.json.old
# run python script (see comment above):
cp package.json package.json.bak
python $fixPackage \
|| \
# exit code 3 -> the package is incompatible to the current platform
# -> Let the build succeed, but don't create lib/node_packages
if [ "$?" == "3" ]; then
rm -r $out/*
echo "Not compatible with system $system" > $out/error
exit 0
else
exit 1
fi
# configure typescript
if [ -f ./tsconfig.json ] \
&& node -e 'require("typescript")' &>/dev/null; then
node ${./tsconfig-to-json.js}
${pkgs.jq}/bin/jq ".compilerOptions.preserveSymlinks = true" tsconfig.json \
| ${pkgs.moreutils}/bin/sponge tsconfig.json
fi
'';
# - installs dependencies into the node_modules directory
# - adds executables of direct node module dependencies to PATH
# - adds the current node module to NODE_PATH
# - sets HOME=$TMPDIR, as this is required by some npm scripts
# TODO: don't install dev dependencies. Load into NODE_PATH instead
configurePhase = ''
runHook preConfigure
# symlink sub dependencies as well as this imitates npm better
python $installDeps
echo "Symlinking transitive executables to $nodeModules/.bin"
for dep in ${l.toString nodeDeps}; do
binDir=$dep/lib/node_modules/.bin
if [ -e $binDir ]; then
for bin in $(ls $binDir/); do\
if [ ! -e $nodeModules/.bin ]; then
mkdir -p $nodeModules/.bin
echo "transforming symlinks to copies..."
for f in $(find -L "$dir" -xtype l); do
if [ -f $f ]; then
continue
fi
# symlink might have been already created by install-deps.py
# if installMethod=copy was selected
if [ ! -L $nodeModules/.bin/$bin ]; then
ln -s $binDir/$bin $nodeModules/.bin/$bin
else
echo "won't overwrite existing symlink $nodeModules/.bin/$bin. current target: $(readlink $nodeModules/.bin/$bin)"
echo "copying $f"
chmod +wx $(dirname "$f")
mv "$f" "$f.bak"
mkdir "$f"
if [ -n "$(ls -A "$f.bak/")" ]; then
cp -r "$f.bak"/* "$f/"
chmod -R +w $f
fi
rm "$f.bak"
done
}
'';
# TODO: upstream fix to nixpkgs
# example which requires this:
# https://registry.npmjs.org/react-window-infinite-loader/-/react-window-infinite-loader-1.0.7.tgz
unpackCmd =
if lib.hasSuffix ".tgz" src
then "tar --delay-directory-restore -xf $src"
else null;
unpackPhase = ''
runHook preUnpack
nodeModules=$out/lib/node_modules
export sourceRoot="$nodeModules/$packageName"
# sometimes tarballs do not end with .tar.??
unpackFallback(){
local fn="$1"
tar xf "$fn"
}
unpackCmdHooks+=(unpackFallback)
unpackFile $src
# Make the base dir in which the target dependency resides in first
mkdir -p "$(dirname "$sourceRoot")"
# install source
if [ -f "$src" ]
then
# Figure out what directory has been unpacked
export packageDir="$(find . -maxdepth 1 -type d | tail -1)"
# Restore write permissions
find "$packageDir" -type d -exec chmod u+x {} \;
chmod -R u+w -- "$packageDir"
# Move the extracted tarball into the output folder
mv -- "$packageDir" "$sourceRoot"
elif [ -d "$src" ]
then
export strippedName="$(stripHash $src)"
# Restore write permissions
chmod -R u+w -- "$strippedName"
# Move the extracted directory into the output folder
mv -- "$strippedName" "$sourceRoot"
fi
done
# add bin path entries collected by python script
export PATH="$PATH:$nodeModules/.bin"
runHook postUnpack
'';
# add dependencies to NODE_PATH
export NODE_PATH="$NODE_PATH:$nodeModules/$packageName/node_modules"
# The python script wich is executed in this phase:
# - ensures that the package is compatible to the current system
# - ensures the main version in package.json matches the expected
# - pins dependency versions in package.json
# (some npm commands might otherwise trigger networking)
# - creates symlinks for executables declared in package.json
# Apart from that:
# - Any usage of 'link:' in package.json is replaced with 'file:'
# - If package-lock.json exists, it is deleted, as it might conflict
# with the parent package-lock.json.
d2nPatchPhase = ''
# delete package-lock.json as it can lead to conflicts
rm -f package-lock.json
export HOME=$TMPDIR
# repair 'link:' -> 'file:'
mv $nodeModules/$packageName/package.json $nodeModules/$packageName/package.json.old
cat $nodeModules/$packageName/package.json.old | sed 's!link:!file\:!g' > $nodeModules/$packageName/package.json
rm $nodeModules/$packageName/package.json.old
runHook postConfigure
'';
# Runs the install command which defaults to 'npm run postinstall'.
# Allows using custom install command by overriding 'buildScript'.
buildPhase = ''
runHook preBuild
# execute electron-rebuild
if [ -n "$electronHeaders" ]; then
echo "executing electron-rebuild"
${electron-rebuild}
fi
# execute install command
if [ -n "$buildScript" ]; then
if [ -f "$buildScript" ]; then
$buildScript
# run python script (see comment above):
cp package.json package.json.bak
python $fixPackage \
|| \
# exit code 3 -> the package is incompatible to the current platform
# -> Let the build succeed, but don't create lib/node_packages
if [ "$?" == "3" ]; then
rm -r $out/*
echo "Not compatible with system $system" > $out/error
exit 0
else
eval "$buildScript"
exit 1
fi
# by default, only for top level packages, `npm run build` is executed
elif [ -n "$runBuild" ] && [ "$(jq '.scripts.build' ./package.json)" != "null" ]; then
npm run build
else
if [ "$(jq '.scripts.preinstall' ./package.json)" != "null" ]; then
npm --production --offline --nodedir=$nodeSources run preinstall
# configure typescript
if [ -f ./tsconfig.json ] \
&& node -e 'require("typescript")' &>/dev/null; then
node ${./tsconfig-to-json.js}
${pkgs.jq}/bin/jq ".compilerOptions.preserveSymlinks = true" tsconfig.json \
| ${pkgs.moreutils}/bin/sponge tsconfig.json
fi
if [ "$(jq '.scripts.install' ./package.json)" != "null" ]; then
npm --production --offline --nodedir=$nodeSources run install
fi
if [ "$(jq '.scripts.postinstall' ./package.json)" != "null" ]; then
npm --production --offline --nodedir=$nodeSources run postinstall
fi
fi
'';
runHook postBuild
'';
# - installs dependencies into the node_modules directory
# - adds executables of direct node module dependencies to PATH
# - adds the current node module to NODE_PATH
# - sets HOME=$TMPDIR, as this is required by some npm scripts
# TODO: don't install dev dependencies. Load into NODE_PATH instead
configurePhase = ''
runHook preConfigure
# Symlinks executables and manual pages to correct directories
installPhase = ''
runHook preInstall
# symlink sub dependencies as well as this imitates npm better
python $installDeps
echo "Symlinking bin entries from package.json"
python $linkBins
echo "Symlinking transitive executables to $nodeModules/.bin"
for dep in ${l.toString nodeDeps}; do
binDir=$dep/lib/node_modules/.bin
if [ -e $binDir ]; then
for bin in $(ls $binDir/); do\
if [ ! -e $nodeModules/.bin ]; then
mkdir -p $nodeModules/.bin
fi
echo "Symlinking manual pages"
if [ -d "$nodeModules/$packageName/man" ]
then
mkdir -p $out/share
for dir in "$nodeModules/$packageName/man/"*
do
mkdir -p $out/share/man/$(basename "$dir")
for page in "$dir"/*
do
ln -s $page $out/share/man/$(basename "$dir")
done
# symlink might have been already created by install-deps.py
# if installMethod=copy was selected
if [ ! -L $nodeModules/.bin/$bin ]; then
ln -s $binDir/$bin $nodeModules/.bin/$bin
else
echo "won't overwrite existing symlink $nodeModules/.bin/$bin. current target: $(readlink $nodeModules/.bin/$bin)"
fi
done
fi
done
fi
# wrap electron app
if [ -n "$electronHeaders" ]; then
echo "Wrapping electron app"
${electron-wrap}
fi
# add bin path entries collected by python script
export PATH="$PATH:$nodeModules/.bin"
runHook postInstall
'';
});
# add dependencies to NODE_PATH
export NODE_PATH="$NODE_PATH:$nodeModules/$packageName/node_modules"
export HOME=$TMPDIR
runHook postConfigure
'';
# Runs the install command which defaults to 'npm run postinstall'.
# Allows using custom install command by overriding 'buildScript'.
buildPhase = ''
runHook preBuild
# execute electron-rebuild
if [ -n "$electronHeaders" ]; then
echo "executing electron-rebuild"
${electron-rebuild}
fi
# execute install command
if [ -n "$buildScript" ]; then
if [ -f "$buildScript" ]; then
$buildScript
else
eval "$buildScript"
fi
# by default, only for top level packages, `npm run build` is executed
elif [ -n "$runBuild" ] && [ "$(jq '.scripts.build' ./package.json)" != "null" ]; then
npm run build
else
if [ "$(jq '.scripts.preinstall' ./package.json)" != "null" ]; then
npm --production --offline --nodedir=$nodeSources run preinstall
fi
if [ "$(jq '.scripts.install' ./package.json)" != "null" ]; then
npm --production --offline --nodedir=$nodeSources run install
fi
if [ "$(jq '.scripts.postinstall' ./package.json)" != "null" ]; then
npm --production --offline --nodedir=$nodeSources run postinstall
fi
fi
runHook postBuild
'';
# Symlinks executables and manual pages to correct directories
installPhase = ''
runHook preInstall
echo "Symlinking bin entries from package.json"
python $linkBins
echo "Symlinking manual pages"
if [ -d "$nodeModules/$packageName/man" ]
then
mkdir -p $out/share
for dir in "$nodeModules/$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
# wrap electron app
if [ -n "$electronHeaders" ]; then
echo "Wrapping electron app"
${electron-wrap}
fi
runHook postInstall
'';
});
in
pkg;
in
pkg;
in
outputs;
outputs;
}

View File

@ -1,29 +1,27 @@
{
dlib,
lib,
apps,
utils,
pkgs,
translators,
...
}: {
type = "impure";
# the input format is specified in /specifications/translator-call-example.json
# this script receives a json file including the input paths and specialArgs
translateBin = {
# dream2nix utils
apps,
subsystems,
utils,
# nixpkgs dependencies
bash,
coreutils,
git,
jq,
moreutils,
nodePackages,
openssh,
python3,
writeScriptBin,
...
}:
translateBin = let
inherit
(pkgs)
bash
coreutils
git
jq
moreutils
nodePackages
openssh
python3
;
in
utils.writePureShellScript
[
bash
@ -64,7 +62,7 @@
popd
# call package-lock translator
${subsystems.nodejs.translators.package-lock.translateBin} $TMPDIR/newJsonInput
${translators.package-lock.translateBin} $TMPDIR/newJsonInput
# get resolved package version
export version=$(npm view $candidate version)
@ -78,7 +76,7 @@
# inherit options from package-lock translator
extraArgs =
dlib.translators.translators.nodejs.package-lock.extraArgs
translators.package-lock.extraArgs
// {
npmArgs = {
description = "Additional arguments for npm";

View File

@ -1,26 +1,24 @@
{
dlib,
lib,
utils,
pkgs,
translators,
...
}: {
type = "impure";
# the input format is specified in /specifications/translator-call-example.json
# this script receives a json file including the input paths and specialArgs
translateBin = {
# dream2nix utils
subsystems,
utils,
# nixpkgs dependencies
bash,
coreutils,
git,
jq,
nodePackages,
openssh,
writeScriptBin,
...
}:
translateBin = let
inherit
(pkgs)
bash
coreutils
git
jq
nodePackages
openssh
;
in
utils.writePureShellScript
[
bash
@ -62,12 +60,12 @@
jq ".source = \"$newSource\"" -c -r $jsonInput > $TMPDIR/newJsonInput
popd
${subsystems.nodejs.translators.package-lock.translateBin} $TMPDIR/newJsonInput
${translators.package-lock.translateBin} $TMPDIR/newJsonInput
'';
# inherit options from package-lock translator
extraArgs =
dlib.translators.translators.nodejs.package-lock.extraArgs
translators.package-lock.extraArgs
// {
npmArgs = {
description = "Additional arguments for npm";

View File

@ -1,9 +1,10 @@
{
dlib,
lib,
utils,
name,
...
}: let
b = builtins;
l = lib // builtins;
nodejsUtils = import ../utils.nix {inherit dlib lib;};
@ -11,10 +12,6 @@
nodejsUtils.getWorkspaceLockFile tree project "package-lock.json";
translate = {
translatorName,
utils,
...
}: {
project,
source,
tree,
@ -146,7 +143,7 @@
dependenciesByOriginalID,
...
}: rec {
inherit translatorName;
translatorName = name;
location = relPath;
# values

View File

@ -1,6 +1,7 @@
{
dlib,
lib,
name,
...
}: let
l = lib // builtins;
@ -10,7 +11,7 @@
getYarnLock = tree: project:
nodejsUtils.getWorkspaceLockFile tree project "yarn.lock";
translate = {translatorName, ...}: {
translate = {
project,
source,
tree,
@ -130,7 +131,9 @@
then "path"
else "http";
in rec {
inherit defaultPackage translatorName;
inherit defaultPackage;
translatorName = name;
location = relPath;

View File

@ -1,15 +1,12 @@
{...}: {
{
lib,
pkgs,
externals,
...
}: {
type = "pure";
build = {
lib,
pkgs,
stdenvNoCC,
# dream2nix inputs
externals,
callPackageDream,
...
}: {
### FUNCTIONS
# AttrSet -> Bool) -> AttrSet -> [x]
getCyclicDependencies, # name: version: -> [ {name=; version=; } ]
@ -37,7 +34,7 @@
} @ args: let
l = lib // builtins;
inherit (callPackageDream ../../semver.nix {}) satisfies;
inherit (pkgs.callPackage ../../semver.nix {}) satisfies;
# php with required extensions
php =
@ -142,7 +139,7 @@
then "0.0.0"
else version;
pkg = stdenvNoCC.mkDerivation rec {
pkg = pkgs.stdenvNoCC.mkDerivation rec {
pname = l.strings.sanitizeDerivationName name;
inherit version;

View File

@ -1,15 +1,12 @@
{...}: {
{
lib,
pkgs,
externals,
...
}: {
type = "pure";
build = {
lib,
pkgs,
stdenvNoCC,
# dream2nix inputs
externals,
callPackageDream,
...
}: {
### FUNCTIONS
# AttrSet -> Bool) -> AttrSet -> [x]
getCyclicDependencies, # name: version: -> [ {name=; version=; } ]
@ -37,7 +34,7 @@
} @ args: let
l = lib // builtins;
inherit (callPackageDream ../../semver.nix {}) satisfies;
inherit (pkgs.callPackage ../../semver.nix {}) satisfies;
# php with required extensions
php =
@ -78,7 +75,7 @@
# Unpack dependency
cleanDependency = name: version:
stdenvNoCC.mkDerivation rec {
pkgs.stdenvNoCC.mkDerivation rec {
pname = "${l.strings.sanitizeDerivationName name}-source";
inherit version;
versionString =
@ -140,7 +137,7 @@
then "0.0.0"
else version;
pkg = stdenvNoCC.mkDerivation rec {
pkg = pkgs.stdenvNoCC.mkDerivation rec {
pname = l.strings.sanitizeDerivationName name;
inherit version;

View File

@ -1,6 +1,7 @@
{
dlib,
lib,
pkgs,
utils,
translators,
...
}: {
type = "impure";
@ -16,18 +17,16 @@
# by the input parameter `outFile`.
# The output file must contain the dream lock data encoded as json.
# See /src/specifications/dream-lock-example.json
translateBin = {
# dream2nix utils
subsystems,
utils,
# nixpkgs dependencies
bash,
coreutils,
moreutils,
jq,
phpPackages,
...
}:
translateBin = let
inherit
(pkgs)
bash
coreutils
moreutils
jq
phpPackages
;
in
utils.writePureShellScript
[
bash
@ -76,9 +75,9 @@
jq ".source = \"$newSource\"" -c -r $jsonInput > $TMPDIR/newJsonInput
popd
${subsystems.php.translators.composer-lock.translateBin} $TMPDIR/newJsonInput
${translators.composer-lock.translateBin} $TMPDIR/newJsonInput
'';
# inherit options from composer-lock translator
extraArgs = dlib.translators.translators.php.composer-lock.extraArgs;
extraArgs = translators.composer-lock.extraArgs;
}

View File

@ -1,4 +1,5 @@
{
name,
dlib,
lib,
...
@ -24,10 +25,6 @@ in {
# translate from a given source and a project specification to a dream-lock.
translate = {
translatorName,
callPackageDream,
...
}: {
/*
A list of projects returned by `discoverProjects`
Example:
@ -95,7 +92,7 @@ in {
...
} @ args: let
inherit
(callPackageDream ../../semver.nix {})
(import ../../semver.nix {inherit lib;})
satisfies
multiSatisfies
;
@ -236,7 +233,7 @@ in {
in
dlib.simpleTranslate2.translate
({objectsByKey, ...}: rec {
inherit translatorName;
translatorName = name;
# relative path of the project within the source tree.
location = project.relPath;

View File

@ -1,25 +1,24 @@
{
dlib,
lib,
apps,
utils,
translators,
pkgs,
...
}: {
type = "impure";
# the input format is specified in /specifications/translator-call-example.json
# this script receives a json file including the input paths and specialArgs
translateBin = {
# dream2nix utils
apps,
subsystems,
utils,
# nixpkgs dependencies
coreutils,
curl,
jq,
git,
moreutils,
...
}:
translateBin = let
inherit
(pkgs)
coreutils
curl
jq
git
moreutils
;
in
utils.writePureShellScript
[
coreutils
@ -71,10 +70,10 @@
if [ -f $TMPDIR/source/composer.lock ]
then
echo 'Translating with composer-lock'
${subsystems.php.translators.composer-lock.translateBin} $TMPDIR/newJsonInput
${translators.composer-lock.translateBin} $TMPDIR/newJsonInput
else
echo 'Translating with composer-json'
${subsystems.php.translators.composer-json.translateBin} $TMPDIR/newJsonInput
${translators.composer-json.translateBin} $TMPDIR/newJsonInput
fi
# add main package source info to dream-lock.json
@ -91,5 +90,5 @@
'';
# inherit options from composer-json translator
extraArgs = dlib.translators.translators.php.composer-json.extraArgs;
extraArgs = translators.composer-json.extraArgs;
}

View File

@ -1,12 +1,12 @@
# A very simple single derivation python builder
{...}: {
{
pkgs,
lib,
...
}: {
type = "pure";
build = {
lib,
pkgs,
...
}: {
defaultPackageName,
defaultPackageVersion,
getSource,

View File

@ -1,27 +1,24 @@
{
dlib,
lib,
externalSources,
utils,
pkgs,
...
}: let
b = builtins;
in {
}: {
type = "impure";
# the input format is specified in /specifications/translator-call-example.json
# this script receives a json file including the input paths and extraArgs
translateBin = {
externalSources,
utils,
bash,
coreutils,
jq,
nix,
python3,
remarshal,
toml2json,
writeScriptBin,
...
}:
translateBin = let
inherit
(pkgs)
bash
coreutils
jq
nix
remarshal
toml2json
;
in
utils.writePureShellScript
[
bash

View File

@ -1,14 +1,12 @@
{...}: {
{
pkgs,
lib,
externals,
...
}: {
type = "pure";
build = {
lib,
pkgs,
stdenv,
# dream2nix inputs
externals,
...
}: {
### FUNCTIONS
# AttrSet -> Bool) -> AttrSet -> [x]
getCyclicDependencies, # name: version: -> [ {name=; version=; } ]

View File

@ -1,10 +1,8 @@
{
dlib,
lib,
utils,
pkgs,
...
}: let
l = lib // builtins;
in {
}: {
type = "impure";
# A derivation which outputs a single executable at `$out`.
@ -18,20 +16,18 @@ in {
# by the input parameter `outFile`.
# The output file must contain the dream lock data encoded as json.
# See /src/specifications/dream-lock-example.json
translateBin = {
# dream2nix utils
utils,
# nixpkgs dependencies
bash,
coreutils,
fetchurl,
jq,
nix,
racket,
runCommandLocal,
writeScriptBin,
...
}: let
translateBin = let
inherit
(pkgs)
bash
coreutils
fetchurl
jq
nix
racket
runCommandLocal
;
pruned-racket-catalog = let
src = fetchurl {
url = "https://github.com/nix-community/pruned-racket-catalog/tarball/9f11e5ea5765c8a732c5e3129ca2b71237ae2bac";

View File

@ -1,13 +1,13 @@
{...}: {
{
lib,
dlib,
pkgs,
externals,
...
} @ topArgs: {
type = "pure";
build = {
lib,
dlib,
pkgs,
callPackageDream,
...
} @ topArgs: {
subsystemAttrs,
defaultPackageName,
defaultPackageVersion,
@ -68,7 +68,10 @@
});
mkShellForPkg = pkg:
callPackageDream ../devshell.nix {drv = pkg;};
pkgs.callPackage ../devshell.nix {
inherit externals;
drv = pkg;
};
allPackages =
l.mapAttrs

View File

@ -1,12 +1,12 @@
{...}: {
{
lib,
pkgs,
externals,
...
} @ topArgs: {
type = "ifd";
build = {
lib,
pkgs,
externals,
callPackageDream,
...
} @ topArgs: {
subsystemAttrs,
defaultPackageName,
defaultPackageVersion,
@ -121,12 +121,16 @@
pname
(buildPackageWithToolchain defaultToolchain buildArgs);
# TODO: this does not carry over environment variables from the
# dependencies derivation. this could cause confusion for users.
mkShellForPkg = pkg: let
pkgDeps = pkg.passthru.dependencies;
depsShell = callPackageDream ../devshell.nix {drv = pkgDeps;};
mainShell = callPackageDream ../devshell.nix {drv = pkg;};
depsShell = pkgs.callPackage ../devshell.nix {
inherit externals;
drv = pkgDeps;
};
mainShell = pkgs.callPackage ../devshell.nix {
inherit externals;
drv = pkg;
};
shell = depsShell.combineWith mainShell;
in
shell;

View File

@ -1,4 +1,5 @@
{
name,
dlib,
lib,
...
@ -180,6 +181,7 @@ in {
in
dlib.simpleTranslate2.translate
({...}: {
translatorName = name;
# relative path of the project within the source tree.
location = project.relPath;

View File

@ -1,17 +1,22 @@
framework: {
{
pkgs,
utils,
translators,
...
}: {
type = "impure";
# the input format is specified in /specifications/translator-call-example.json
# this script receives a json file including the input paths and specialArgs
translateBin = let
inherit
(framework.pkgs)
(pkgs)
coreutils
jq
rustPlatform
;
in
framework.utils.writePureShellScript
utils.writePureShellScript
[
coreutils
jq
@ -41,7 +46,7 @@ framework: {
popd
if [ $cargoResult -eq 0 ]; then
${framework.translators.cargo-lock.translateBin} $TMPDIR/newJsonInput
${translators.cargo-lock.translateBin} $TMPDIR/newJsonInput
else
echo "cargo failed to generate the lockfile"
exit 1
@ -50,7 +55,7 @@ framework: {
# inherit options from cargo-lock translator
extraArgs =
framework.translators.cargo-lock.extraArgs
translators.cargo-lock.extraArgs
// {
cargoArgs = {
description = "Additional arguments for Cargo";