2022-02-27 13:26:13 +03:00
|
|
|
# like ./default.nix but system intependent
|
|
|
|
# (allows to generate outputs for several systems)
|
|
|
|
# follows flake output schema
|
|
|
|
{
|
|
|
|
dlib,
|
|
|
|
nixpkgsSrc,
|
|
|
|
lib,
|
|
|
|
overridesDirs,
|
|
|
|
externalSources,
|
|
|
|
externalPaths,
|
2022-03-07 13:12:07 +03:00
|
|
|
} @ args: let
|
2022-02-27 13:26:13 +03:00
|
|
|
b = builtins;
|
|
|
|
|
|
|
|
l = lib // builtins;
|
|
|
|
|
|
|
|
dream2nixForSystem = config: system: pkgs:
|
|
|
|
import ./default.nix
|
2022-03-07 13:12:07 +03:00
|
|
|
{inherit config externalPaths externalSources pkgs;};
|
2022-02-27 13:26:13 +03:00
|
|
|
|
|
|
|
# TODO: design output schema for cross compiled packages
|
2022-03-07 13:12:07 +03:00
|
|
|
makePkgsKey = pkgs: let
|
|
|
|
build = pkgs.buildPlatform.system;
|
|
|
|
host = pkgs.hostPlatform.system;
|
|
|
|
in
|
|
|
|
if build == host
|
|
|
|
then build
|
|
|
|
else throw "cross compiling currently not supported";
|
2022-02-27 13:26:13 +03:00
|
|
|
|
|
|
|
makeNixpkgs = pkgsList: systems:
|
2022-03-07 13:12:07 +03:00
|
|
|
# fail if neither pkgs nor systems are defined
|
|
|
|
if pkgsList == null && systems == []
|
|
|
|
then throw "Either `systems` or `pkgs` must be defined"
|
2022-02-27 13:26:13 +03:00
|
|
|
# fail if pkgs and systems are both defined
|
2022-03-07 13:12:07 +03:00
|
|
|
else if pkgsList != null && systems != []
|
|
|
|
then throw "Define either `systems` or `pkgs`, not both"
|
2022-02-27 13:26:13 +03:00
|
|
|
# only pkgs is specified
|
2022-03-07 13:12:07 +03:00
|
|
|
else if pkgsList != null
|
|
|
|
then
|
|
|
|
if b.isList pkgsList
|
|
|
|
then
|
2022-02-27 13:26:13 +03:00
|
|
|
lib.listToAttrs
|
2022-03-07 13:12:07 +03:00
|
|
|
(pkgs: lib.nameValuePair (makePkgsKey pkgs) pkgs)
|
|
|
|
pkgsList
|
|
|
|
else {"${makePkgsKey pkgsList}" = pkgsList;}
|
2022-02-27 13:26:13 +03:00
|
|
|
# only systems is specified
|
|
|
|
else
|
|
|
|
lib.genAttrs systems
|
2022-03-07 13:12:07 +03:00
|
|
|
(system: import nixpkgsSrc {inherit system;});
|
|
|
|
|
|
|
|
flakifyBuilderOutputs = system: outputs:
|
|
|
|
l.mapAttrs
|
|
|
|
(ouputType: outputValue: {"${system}" = outputValue;})
|
|
|
|
outputs;
|
|
|
|
|
|
|
|
init = {
|
|
|
|
pkgs ? null,
|
|
|
|
systems ? [],
|
|
|
|
config ? {},
|
|
|
|
} @ argsInit: let
|
|
|
|
config' = (import ./utils/config.nix).loadConfig argsInit.config or {};
|
|
|
|
|
|
|
|
config =
|
|
|
|
config'
|
|
|
|
// {
|
2022-02-27 13:26:13 +03:00
|
|
|
overridesDirs = args.overridesDirs ++ config'.overridesDirs;
|
|
|
|
};
|
|
|
|
|
2022-03-07 13:12:07 +03:00
|
|
|
allPkgs = makeNixpkgs pkgs systems;
|
|
|
|
|
|
|
|
forAllSystems = f: lib.mapAttrs f allPkgs;
|
|
|
|
|
|
|
|
dream2nixFor = forAllSystems (dream2nixForSystem config);
|
|
|
|
in {
|
|
|
|
riseAndShine = throw "Use makeFlakeOutputs instead of riseAndShine.";
|
|
|
|
|
|
|
|
makeFlakeOutputs = mArgs:
|
|
|
|
makeFlakeOutputsFunc
|
|
|
|
(
|
|
|
|
{inherit config pkgs systems;}
|
|
|
|
// mArgs
|
|
|
|
);
|
|
|
|
|
|
|
|
apps =
|
|
|
|
forAllSystems
|
|
|
|
(system: pkgs:
|
|
|
|
dream2nixFor."${system}".apps.flakeApps);
|
|
|
|
|
|
|
|
defaultApp =
|
|
|
|
forAllSystems
|
|
|
|
(system: pkgs:
|
|
|
|
dream2nixFor."${system}".apps.flakeApps.dream2nix);
|
|
|
|
};
|
|
|
|
|
|
|
|
makeFlakeOutputsFunc = {
|
2022-03-27 16:08:22 +03:00
|
|
|
config ? {},
|
2022-03-10 13:05:34 +03:00
|
|
|
inject ? {},
|
2022-03-07 13:12:07 +03:00
|
|
|
pname ? throw "Please pass `pname` to makeFlakeOutputs",
|
|
|
|
pkgs ? null,
|
|
|
|
packageOverrides ? {},
|
|
|
|
settings ? [],
|
|
|
|
source,
|
2022-03-27 17:45:31 +03:00
|
|
|
sourceOverrides ? oldSources: {},
|
2022-03-07 13:12:07 +03:00
|
|
|
systems ? [],
|
|
|
|
translator ? null,
|
|
|
|
translatorArgs ? {},
|
|
|
|
} @ args: let
|
|
|
|
config = args.config or ((import ./utils/config.nix).loadConfig {});
|
|
|
|
allPkgs = makeNixpkgs pkgs systems;
|
|
|
|
forAllSystems = f: b.mapAttrs f allPkgs;
|
|
|
|
dream2nixFor = forAllSystems (dream2nixForSystem config);
|
|
|
|
|
|
|
|
getInvalidationHash = project:
|
|
|
|
dlib.calcInvalidationHash {
|
2022-03-28 19:20:44 +03:00
|
|
|
inherit project source;
|
2022-03-07 13:12:07 +03:00
|
|
|
# TODO: add translatorArgs
|
|
|
|
translatorArgs = {};
|
|
|
|
translator = project.translator;
|
2022-02-27 13:26:13 +03:00
|
|
|
};
|
|
|
|
|
2022-03-07 13:12:07 +03:00
|
|
|
discoveredProjects = dlib.discoverers.discoverProjects {
|
|
|
|
inherit settings;
|
|
|
|
tree = dlib.prepareSourceTree {inherit source;};
|
|
|
|
};
|
|
|
|
|
|
|
|
allBuilderOutputs =
|
|
|
|
lib.mapAttrs
|
|
|
|
(system: pkgs: let
|
|
|
|
dream2nix = dream2nixFor."${system}";
|
|
|
|
|
|
|
|
impureDiscoveredProjects =
|
|
|
|
l.filter
|
|
|
|
(proj:
|
|
|
|
dream2nix
|
|
|
|
.translators
|
|
|
|
.translatorsV2
|
|
|
|
."${proj.subsystem}"
|
|
|
|
.all
|
|
|
|
."${proj.translator}"
|
|
|
|
.type
|
|
|
|
== "impure")
|
|
|
|
discoveredProjects;
|
|
|
|
|
|
|
|
impureResolveScriptsList =
|
|
|
|
l.listToAttrs
|
|
|
|
(l.forEach impureDiscoveredProjects
|
|
|
|
(project:
|
|
|
|
l.nameValuePair
|
|
|
|
"Name: ${project.name}; Subsystem: ${project.subsystem}; relPath: ${project.relPath}"
|
|
|
|
(dream2nix.utils.makeTranslateScript {
|
|
|
|
inherit project source;
|
|
|
|
invalidationHash = getInvalidationHash project;
|
|
|
|
})));
|
|
|
|
|
|
|
|
resolveImpureScript =
|
|
|
|
dream2nix.utils.writePureShellScript
|
|
|
|
[]
|
|
|
|
''
|
|
|
|
cd $WORKDIR
|
|
|
|
${l.concatStringsSep "\n"
|
|
|
|
(l.mapAttrsToList
|
|
|
|
(title: script: ''
|
|
|
|
echo "Resolving:: ${title}"
|
|
|
|
${script}/bin/resolve
|
|
|
|
'')
|
|
|
|
impureResolveScriptsList)}
|
|
|
|
'';
|
|
|
|
|
|
|
|
translatedProjects = dream2nix.translateProjects {
|
|
|
|
inherit pname settings source;
|
2022-03-05 20:38:06 +03:00
|
|
|
};
|
|
|
|
|
2022-03-07 13:12:07 +03:00
|
|
|
realizedProjects = dream2nix.realizeProjects {
|
2022-03-27 17:45:31 +03:00
|
|
|
inherit
|
|
|
|
inject
|
|
|
|
packageOverrides
|
|
|
|
sourceOverrides
|
|
|
|
translatedProjects
|
|
|
|
source
|
|
|
|
;
|
2022-02-27 13:26:13 +03:00
|
|
|
};
|
|
|
|
|
2022-03-07 13:12:07 +03:00
|
|
|
allOutputs =
|
|
|
|
realizedProjects
|
|
|
|
// {
|
|
|
|
apps.resolveImpure = {
|
|
|
|
type = "app";
|
|
|
|
program = l.toString resolveImpureScript;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
allOutputs)
|
|
|
|
allPkgs;
|
|
|
|
|
|
|
|
flakifiedOutputsList =
|
|
|
|
lib.mapAttrsToList
|
|
|
|
(system: outputs: flakifyBuilderOutputs system outputs)
|
|
|
|
allBuilderOutputs;
|
|
|
|
|
|
|
|
flakeOutputsBuilders =
|
|
|
|
b.foldl'
|
|
|
|
(allOutputs: output: lib.recursiveUpdate allOutputs output)
|
|
|
|
{}
|
|
|
|
flakifiedOutputsList;
|
|
|
|
|
|
|
|
flakeOutputs =
|
|
|
|
{projectsJson = l.toJSON discoveredProjects;}
|
|
|
|
// flakeOutputsBuilders;
|
|
|
|
in
|
|
|
|
lib.recursiveUpdate
|
|
|
|
flakeOutputs
|
|
|
|
{
|
|
|
|
apps = forAllSystems (system: pkgs: {
|
|
|
|
resolve.type = "app";
|
|
|
|
resolve.program = let
|
|
|
|
utils = dream2nixFor."${system}".utils;
|
|
|
|
|
|
|
|
# TODO: Too many calls to findOneTranslator.
|
|
|
|
# -> make findOneTranslator system independent
|
|
|
|
translatorFound = dream2nixFor."${system}".translators.findOneTranslator {
|
|
|
|
inherit source;
|
|
|
|
translatorName = args.translator or null;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
b.toString
|
|
|
|
(utils.makePackageLockScript {
|
|
|
|
inherit source translatorArgs;
|
|
|
|
packagesDir = config.packagesDir;
|
|
|
|
translator = translatorFound.name;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
in {
|
2022-02-27 13:26:13 +03:00
|
|
|
inherit dlib init;
|
|
|
|
riseAndShine = throw "Use makeFlakeOutputs instead of riseAndShine.";
|
2022-03-15 19:24:16 +03:00
|
|
|
makeFlakeOutputs = makeFlakeOutputsFunc;
|
2022-02-27 13:26:13 +03:00
|
|
|
}
|