feat: makeFLakeOutputs: add flag autoProjects

- defaults to false
- helpful error is raised if set to false and `projects` is not defined
This commit is contained in:
DavHau 2022-12-07 15:52:19 +07:00
parent 08f1b71c44
commit e48421c830

View File

@ -71,6 +71,24 @@
}:
initDream2nix (loadConfig config) pkgs;
missingProjectsError = ''
Please pass `projects` to makeFlakeOutputs.
`projects` can be:
- an attrset
- a path to a .toml file
- a path to a .json file
To generate a projects.toml file automatically:
1. execute:
nix run github:nix-community/dream2nix#discover-projects > projects.toml
2. review the ./projects.toml and edit it if necessary.
3. pass `projects = ./projects.toml` to makeFlakeOutputs.
Alternatively pass `autoProjects = true` to makeFlakeOutputs.
This is not recommended as it doesn't allow you to review or filter the list
of detected projects.
'';
makeFlakeOutputs = {
source,
pkgs ? null,
@ -81,6 +99,7 @@
pname ? throw "Please pass `pname` to makeFlakeOutputs",
packageOverrides ? {},
projects ? {},
autoProjects ? false,
settings ? [],
sourceOverrides ? oldSources: {},
} @ args: let
@ -101,6 +120,21 @@
file = systemsFromFile;
};
# if projects provided via `.json` or `.toml` file, parse to attrset
projects = let
givenProjects = args.projects or {};
in
if autoProjects && args ? projects
then throw "Don't pass `projects` to makeFlakeOutputs when `autoProjects = true`"
else if l.isPath givenProjects
then
if ! l.pathExists givenProjects
then throw missingProjectsError
else if l.hasSuffix ".toml" (l.toString givenProjects)
then l.fromTOML (l.readFile givenProjects)
else l.fromJSON (l.readFile givenProjects)
else givenProjects;
allPkgs = makeNixpkgs pkgs systems;
initD2N = initDream2nix config;
@ -128,7 +162,9 @@
proj
(l.head projectsList);
})
else discoveredProjects;
else if autoProjects == true
then discoveredProjects
else throw missingProjectsError;
allBuilderOutputs =
l.mapAttrs