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
|
|
|
|
{
|
|
|
|
nixpkgsSrc,
|
|
|
|
lib,
|
|
|
|
overridesDirs,
|
|
|
|
externalSources,
|
|
|
|
externalPaths,
|
2022-03-07 13:12:07 +03:00
|
|
|
} @ args: let
|
2022-02-27 13:26:13 +03:00
|
|
|
l = lib // builtins;
|
|
|
|
|
2022-06-01 23:53:46 +03:00
|
|
|
initDream2nix = config: pkgs:
|
2022-02-27 13:26:13 +03:00
|
|
|
import ./default.nix
|
2022-06-01 23:53:46 +03:00
|
|
|
{inherit config pkgs externalPaths externalSources;};
|
|
|
|
|
|
|
|
loadConfig = config'': let
|
|
|
|
config' = (import ./utils/config.nix).loadConfig config'';
|
|
|
|
|
|
|
|
config =
|
|
|
|
config'
|
|
|
|
// {
|
|
|
|
overridesDirs = args.overridesDirs ++ config'.overridesDirs;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
config;
|
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
|
2022-06-01 23:53:46 +03:00
|
|
|
if l.isList pkgsList
|
2022-03-07 13:12:07 +03:00
|
|
|
then
|
2022-06-01 23:53:46 +03:00
|
|
|
l.listToAttrs
|
|
|
|
(pkgs: l.nameValuePair (makePkgsKey pkgs) pkgs)
|
2022-03-07 13:12:07 +03:00
|
|
|
pkgsList
|
|
|
|
else {"${makePkgsKey pkgsList}" = pkgsList;}
|
2022-02-27 13:26:13 +03:00
|
|
|
# only systems is specified
|
|
|
|
else
|
2022-06-01 23:53:46 +03:00
|
|
|
l.genAttrs systems
|
2022-03-07 13:12:07 +03:00
|
|
|
(system: import nixpkgsSrc {inherit system;});
|
|
|
|
|
|
|
|
flakifyBuilderOutputs = system: outputs:
|
|
|
|
l.mapAttrs
|
2022-06-01 23:53:46 +03:00
|
|
|
(_: outputValue: {"${system}" = outputValue;})
|
2022-03-07 13:12:07 +03:00
|
|
|
outputs;
|
|
|
|
|
|
|
|
init = {
|
2022-06-01 23:53:46 +03:00
|
|
|
pkgs ? throw "please pass 'pkgs' (a nixpkgs instance) to 'init'",
|
2022-03-07 13:12:07 +03:00
|
|
|
config ? {},
|
2022-06-01 23:53:46 +03:00
|
|
|
}:
|
|
|
|
initDream2nix (loadConfig config) pkgs;
|
2022-03-07 13:12:07 +03:00
|
|
|
|
2022-06-01 23:53:46 +03:00
|
|
|
makeFlakeOutputs = {
|
|
|
|
source,
|
|
|
|
pkgs ? null,
|
|
|
|
systems ? [],
|
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",
|
|
|
|
packageOverrides ? {},
|
|
|
|
settings ? [],
|
2022-03-27 17:45:31 +03:00
|
|
|
sourceOverrides ? oldSources: {},
|
2022-03-07 13:12:07 +03:00
|
|
|
translator ? null,
|
|
|
|
translatorArgs ? {},
|
|
|
|
} @ args: let
|
|
|
|
allPkgs = makeNixpkgs pkgs systems;
|
2022-06-01 23:53:46 +03:00
|
|
|
|
|
|
|
config = loadConfig (args.config or {});
|
2022-05-29 22:42:47 +03:00
|
|
|
dlib = import ./lib {inherit lib config;};
|
2022-03-07 13:12:07 +03:00
|
|
|
|
2022-06-01 23:53:46 +03:00
|
|
|
initD2N = initDream2nix config;
|
|
|
|
dream2nixFor = l.mapAttrs (_: pkgs: initD2N pkgs) allPkgs;
|
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 =
|
2022-06-01 23:53:46 +03:00
|
|
|
l.mapAttrs
|
2022-03-07 13:12:07 +03:00
|
|
|
(system: pkgs: let
|
|
|
|
dream2nix = dream2nixFor."${system}";
|
2022-06-01 23:53:46 +03:00
|
|
|
allOutputs = dream2nix.makeOutputs {
|
2022-03-27 17:45:31 +03:00
|
|
|
inherit
|
|
|
|
source
|
2022-06-01 23:53:46 +03:00
|
|
|
pname
|
|
|
|
discoveredProjects
|
|
|
|
settings
|
|
|
|
sourceOverrides
|
|
|
|
packageOverrides
|
|
|
|
inject
|
2022-03-27 17:45:31 +03:00
|
|
|
;
|
2022-02-27 13:26:13 +03:00
|
|
|
};
|
2022-03-07 13:12:07 +03:00
|
|
|
in
|
|
|
|
allOutputs)
|
|
|
|
allPkgs;
|
|
|
|
|
|
|
|
flakifiedOutputsList =
|
2022-06-01 23:53:46 +03:00
|
|
|
l.mapAttrsToList
|
2022-03-07 13:12:07 +03:00
|
|
|
(system: outputs: flakifyBuilderOutputs system outputs)
|
|
|
|
allBuilderOutputs;
|
|
|
|
|
|
|
|
flakeOutputsBuilders =
|
2022-06-01 23:53:46 +03:00
|
|
|
l.foldl'
|
2022-03-07 13:12:07 +03:00
|
|
|
(allOutputs: output: lib.recursiveUpdate allOutputs output)
|
|
|
|
{}
|
|
|
|
flakifiedOutputsList;
|
|
|
|
|
|
|
|
flakeOutputs =
|
|
|
|
{projectsJson = l.toJSON discoveredProjects;}
|
|
|
|
// flakeOutputsBuilders;
|
|
|
|
in
|
2022-04-04 14:36:45 +03:00
|
|
|
flakeOutputs;
|
2022-03-07 13:12:07 +03:00
|
|
|
in {
|
2022-06-01 23:53:46 +03:00
|
|
|
inherit init makeFlakeOutputs;
|
2022-05-29 22:42:47 +03:00
|
|
|
dlib = import ./lib {inherit lib;};
|
2022-02-27 13:26:13 +03:00
|
|
|
riseAndShine = throw "Use makeFlakeOutputs instead of riseAndShine.";
|
|
|
|
}
|