-
Notifications
You must be signed in to change notification settings - Fork 1
/
default.nix
119 lines (115 loc) · 3.55 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
{ lib, config, self, inputs, ... }:
{
imports = [
../lib
];
options = let
inherit (lib)
types
;
inherit (config.lib)
createThings
;
createPackages = baseDir:
createThings {
inherit baseDir;
thingType = "package";
raw = false;
extras.systems = {
default = lib.const true;
};
};
in {
auto.packages = lib.mkOption {
description = ''
Automagically generate packages from walking directories with Nix files
'';
type = types.submodule (submodule: {
options = {
enable = lib.mkEnableOption "Automatic packages extraction";
dir = lib.mkOption {
description = ''
Base directory of the contained packages
'';
type = types.path;
default = "${self}/pkgs";
defaultText = ''''${self}/pkgs'';
};
result = lib.mkOption {
description = ''
The resulting automatic packages
'';
type = types.attrsOf (types.submodule { options = {
package = lib.mkOption { type = types.unspecified; };
systems = lib.mkOption { type = types.functionTo types.bool; };
};});
readOnly = true;
internal = true;
default =
lib.optionalAttrs
config.auto.packages.enable
(createPackages config.auto.packages.dir);
};
};
});
default = {};
};
};
config = {
perSystem = { lib, pkgs, system, ... }: let
# NOTE: evaluate packages in isolation, which allows
# merging them back into the global `pkgs` later
# NOTE: also faster than `import nixpkgs { inherit system; }`
pkgsPure = inputs.nixpkgs.legacyPackages.${system};
packages =
lib.pipe
config.auto.packages.result
[
(lib.filterAttrs
(name: { package, systems }:
systems {
inherit (pkgsPure)
lib
hostPlatform
buildPlatform
targetPlatform
;
}))
(lib.mapAttrs
(name: { package, systems }:
let
# TODO: put in `autoThings` `handle`?
# TODO: keep source `dream2nix` module for overriding?
isDream2Nix = lib.pipe package
[
builtins.functionArgs
builtins.attrNames
(builtins.elem "dream2nix")
];
in
if isDream2Nix then
inputs.dream2nix.lib.evalModules {
packageSets.nixpkgs = pkgsPure;
modules = [
package
{
paths.projectRoot = "${self.outPath}";
paths.projectRootFile = "flake.nix";
paths.package = "${self.outPath}";
}
];
specialArgs = {
# NOTE: for overlayed `maintainers` and `net`
inherit (pkgs) lib;
inherit inputs;
};
}
else
# TODO: only inherit `input` if requested
pkgsPure.callPackage package { /* inherit inputs; */ }))
];
in {
inherit packages;
};
};
}