dream2nix/src/lib.nix

135 lines
3.4 KiB
Nix
Raw Normal View History

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,
} @ args: let
2022-02-27 13:26:13 +03:00
l = lib // builtins;
initDream2nix = config: pkgs:
2022-02-27 13:26:13 +03:00
import ./default.nix
{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
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:
# 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
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
else if pkgsList != null
then
if l.isList pkgsList
then
l.listToAttrs
(pkgs: l.nameValuePair (makePkgsKey pkgs) pkgs)
pkgsList
else {"${makePkgsKey pkgsList}" = pkgsList;}
2022-02-27 13:26:13 +03:00
# only systems is specified
else
l.genAttrs systems
(system: import nixpkgsSrc {inherit system;});
flakifyBuilderOutputs = system: outputs:
l.mapAttrs
(_: outputValue: {"${system}" = outputValue;})
outputs;
init = {
pkgs ? throw "please pass 'pkgs' (a nixpkgs instance) to 'init'",
config ? {},
}:
initDream2nix (loadConfig config) pkgs;
makeFlakeOutputs = {
source,
pkgs ? null,
systems ? [],
2022-03-27 16:08:22 +03:00
config ? {},
2022-03-10 13:05:34 +03:00
inject ? {},
pname ? throw "Please pass `pname` to makeFlakeOutputs",
packageOverrides ? {},
settings ? [],
2022-03-27 17:45:31 +03:00
sourceOverrides ? oldSources: {},
translator ? null,
translatorArgs ? {},
} @ args: let
allPkgs = makeNixpkgs pkgs systems;
config = loadConfig (args.config or {});
refactor: implement a validation system for builders / translators, reorganize files (#155) * refactor: implement a validation system for builders / translators etc, organize files * refactor: use seq instead of complicated validation function for validator * feat: allow adding discoverers, translators and builders via config * refactor: rework discoverers to use makeSubsystemModules as well * fix: validate extra modules properly * feat: support inline modules * feat: use extra attribute for extending * feat: make fetchers extensible properly * fix: add name to extra fetchers * feat: support list for extra * docs: add some comment to lib/modules.nix * fix: get extra module args from extraArgs * fix: collect all modules instead of only collecting modules for built-in subsystems * refactor: minor improvements * refactor: improve how default subsystem modules are declared * fix: translators and builders are directly under subsystem now * fix: correct attribute path, remove unused argument * fix: correct translators attribute paths * fix: correct file paths and translators attribute paths * fix: use correct translator attr path in wrapPureTranslator * fix: update unit tests code * fix: remove extra paranthesis in unit tests code * tests: add an extended dream2nix example * refactor: replace recursiveUpdate usage with normal update op * tests: fix and extend d2n-extended example * fix: pass config to d2n instance in wrap pure translator script * fix: correct toFile usage * fix: pass config to dlib in more places * fix: pass config to d2n instance in aggregated hashes cli and gomod2nix translator * refactor: remove unused extra modules validation, add warning for function modules * fix: remove non-existent inherited variable * docs: update translator attr path in contributors guide * docs: add docs for extending dream2nix * refactor: comment more code, warn for function modules only if extra is an attrset decl * docs: fix some typos * docs: explain some stuff in extending d2n better * fix: print function modules warning when it is a function * tests: add a new example that tests adding new subsystem and config.extra as nix file * tests: use cargo-toml as translator on d2n-extended to potentially catch more bugs * feat: add ifd warning for builders * tests: use build-rust-package builder instead of crane builder in d2n-extended to also test it instead of only testing crane builder * fix(rust/builders): always write the generated Cargo.lock so it doesnt get out of sync with our dream-lock * fix(rust/builders): delete cargo lock before writing it? * refactor: also print ifd warnings for translators * docs: link extending d2n doc in readme, link examples in extending d2n * docs: example naming (translators.new -> translators.example-translator) * feat: allow setting nix files for modules declarations (eg. subsystems, subsystems.translators) * refactor: move IFD warnings to src/lib/builders.nix / translators.nix respectively * refactor: throw instead of warning if function declarations for modules are used * refactor: fix throw usage * refactor: improve modules code * chore(deps): update nixpkgs * fix: correct some map usages * fix: use correct attr path for extra modules * chore: update examples flake inputs * style: minor formatting changes
2022-05-29 22:42:47 +03:00
dlib = import ./lib {inherit lib config;};
initD2N = initDream2nix config;
dream2nixFor = l.mapAttrs (_: pkgs: initD2N pkgs) allPkgs;
2022-02-27 13:26:13 +03:00
discoveredProjects = dlib.discoverers.discoverProjects {
inherit settings;
tree = dlib.prepareSourceTree {inherit source;};
};
allBuilderOutputs =
l.mapAttrs
(system: pkgs: let
dream2nix = dream2nixFor."${system}";
allOutputs = dream2nix.makeOutputs {
2022-03-27 17:45:31 +03:00
inherit
source
pname
discoveredProjects
settings
sourceOverrides
packageOverrides
inject
2022-03-27 17:45:31 +03:00
;
2022-02-27 13:26:13 +03:00
};
in
allOutputs)
allPkgs;
flakifiedOutputsList =
l.mapAttrsToList
(system: outputs: flakifyBuilderOutputs system outputs)
allBuilderOutputs;
flakeOutputsBuilders =
l.foldl'
(allOutputs: output: lib.recursiveUpdate allOutputs output)
{}
flakifiedOutputsList;
flakeOutputs =
{projectsJson = l.toJSON discoveredProjects;}
// flakeOutputsBuilders;
in
flakeOutputs;
in {
inherit init makeFlakeOutputs;
refactor: implement a validation system for builders / translators, reorganize files (#155) * refactor: implement a validation system for builders / translators etc, organize files * refactor: use seq instead of complicated validation function for validator * feat: allow adding discoverers, translators and builders via config * refactor: rework discoverers to use makeSubsystemModules as well * fix: validate extra modules properly * feat: support inline modules * feat: use extra attribute for extending * feat: make fetchers extensible properly * fix: add name to extra fetchers * feat: support list for extra * docs: add some comment to lib/modules.nix * fix: get extra module args from extraArgs * fix: collect all modules instead of only collecting modules for built-in subsystems * refactor: minor improvements * refactor: improve how default subsystem modules are declared * fix: translators and builders are directly under subsystem now * fix: correct attribute path, remove unused argument * fix: correct translators attribute paths * fix: correct file paths and translators attribute paths * fix: use correct translator attr path in wrapPureTranslator * fix: update unit tests code * fix: remove extra paranthesis in unit tests code * tests: add an extended dream2nix example * refactor: replace recursiveUpdate usage with normal update op * tests: fix and extend d2n-extended example * fix: pass config to d2n instance in wrap pure translator script * fix: correct toFile usage * fix: pass config to dlib in more places * fix: pass config to d2n instance in aggregated hashes cli and gomod2nix translator * refactor: remove unused extra modules validation, add warning for function modules * fix: remove non-existent inherited variable * docs: update translator attr path in contributors guide * docs: add docs for extending dream2nix * refactor: comment more code, warn for function modules only if extra is an attrset decl * docs: fix some typos * docs: explain some stuff in extending d2n better * fix: print function modules warning when it is a function * tests: add a new example that tests adding new subsystem and config.extra as nix file * tests: use cargo-toml as translator on d2n-extended to potentially catch more bugs * feat: add ifd warning for builders * tests: use build-rust-package builder instead of crane builder in d2n-extended to also test it instead of only testing crane builder * fix(rust/builders): always write the generated Cargo.lock so it doesnt get out of sync with our dream-lock * fix(rust/builders): delete cargo lock before writing it? * refactor: also print ifd warnings for translators * docs: link extending d2n doc in readme, link examples in extending d2n * docs: example naming (translators.new -> translators.example-translator) * feat: allow setting nix files for modules declarations (eg. subsystems, subsystems.translators) * refactor: move IFD warnings to src/lib/builders.nix / translators.nix respectively * refactor: throw instead of warning if function declarations for modules are used * refactor: fix throw usage * refactor: improve modules code * chore(deps): update nixpkgs * fix: correct some map usages * fix: use correct attr path for extra modules * chore: update examples flake inputs * style: minor formatting changes
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.";
}