Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@
"ekala-corepkgs.cachix.org-1:DcZV+vegWoEzacbSdXFXU4S7728C0eS9RfGpKeyHd6w="
];
};
mkFlake = import ./lib/mk-flake.nix;
};
}
48 changes: 48 additions & 0 deletions lib/mk-flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
overlays ? [ ],
config ? { },
packages ? null,
devShells ? null,
checks ? null,
formatter ? null,
apps ? null,
checks ? null,
hydraJobs ? null,
systems ? [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ],
# TODO: support pkgsModules
}:

let
# TODO: don't depend on lib
forAllSystems = lib.genAttrs systems;
optionalAttrs = pred: attrs: if pred then attrs else { };
optionalOutput = outputFunc: outputName: optionalAttrs (output != null) {
${outputName} = forallSystem (system: outputFunc legacyPackages.${sytem});
};
packages = forallSystems (system: packages legacyPackages.${system});

legacyPackages = forAllSystems (system: import ../. {
inherit system config;
});
assertMsg = pred: msg: pred || throw msg;
assertFuncDefined = func: name: assertMsg (func != null -> builtins.isFunction func) "${name} must be a function";
# Avoid having people do this boilerplate
mkApps = builtins.mapAttrs (_: v: { type = "app"; program = v; })
apps' = if apps == null then null else x: mkApps (apps x);
in

assert assertFuncDefined packages "packages";
assert assertFuncDefined devShells "devShells";
assert assertFuncDefined checks "checks";
assert assertFuncDefined formatter "formatter";
assert assertFuncDefined apps "apps";
assert assertFuncDefined hydraJobs "hydraJobs";

{
inherit legacyPackages;
} // optionalOutput packages "packages"
// optionalOutput devShells "devShells"
// optionalOutput checks "checks"
// optionalOutput formatter "formatter"
// optionalOutput apps' "apps"
// optionalOutput hydraJobs "hydraJobs"
Loading