dotfiles.nix/flake-parts/apps.nix
2023-03-17 13:32:04 -07:00

16 lines
957 B
Nix

{ lib, self, inputs, withSystem, config, ... }: {
flake =
let
buildProgram = system: definition: (withSystem system ({ pkgs, self', ... }: definition self.lib pkgs));
defineProgram = system: name: definition: { ${system}.${name} = buildProgram system definition; };
appsDir = self.lib.importDirToAttrs ../apps;
builtPrograms = lib.mapAttrsToList (name: value: (lib.forEach (builtins.filter (system: builtins.elem system config.systems) value.systems) (system: defineProgram system name value.definition))) appsDir;
flattenedPrograms = lib.flatten builtPrograms;
assembledPrograms = builtins.foldl' (a: b: lib.recursiveUpdate a b) { } flattenedPrograms;
assembledApps = lib.mapAttrsRecursiveCond (as: !(as ? "type" && as.type == "derivation")) (path: value: { type = "app"; program = lib.getExe value; }) assembledPrograms;
in
{
apps = assembledApps;
programs = assembledPrograms;
};
}