-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake-module.nix
92 lines (87 loc) · 2.16 KB
/
flake-module.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
toplevel@{
lib,
flake-parts-lib,
inputs,
...
}:
let
inherit (flake-parts-lib)
mkPerSystemOption
;
inherit (lib)
mkOption
types
;
in
{
options = {
perSystem = mkPerSystemOption (
{ ... }:
{
options = {
pkgsDirectory = mkOption {
type = types.nullOr types.path;
default = null;
description = ''
If set, the flake will import packages from the specified directory.
'';
};
pkgsNameSeparator = mkOption {
type = types.str;
default = "/";
description = ''
The separator to use when flattening package names.
'';
};
};
}
);
};
config = {
perSystem =
{ config, pkgs, ... }:
let
scope = lib.makeScope pkgs.newScope (self: {
inherit inputs;
});
flattenAttrs =
{
attrs ? { },
separator ? "/",
callback,
}:
let
flatten =
attrSet: prefixes:
builtins.foldl' (
acc: name:
let
newValue = attrSet.${name};
newKey = prefixes ++ [ name ];
in
if lib.isFunction newValue then
acc // { ${lib.concatStringsSep separator newKey} = newValue callback; }
else
acc // (flatten newValue newKey)
) { } (builtins.attrNames attrSet);
in
flatten attrs [ ];
in
lib.mkIf (config.pkgsDirectory != null) {
legacyPackages = lib.filesystem.packagesFromDirectoryRecursive {
directory = config.pkgsDirectory;
inherit (scope) callPackage;
};
packages = flattenAttrs {
attrs = lib.filesystem.packagesFromDirectoryRecursive {
directory = config.pkgsDirectory;
callPackage =
file: args: callback:
callback file args;
};
separator = config.pkgsNameSeparator;
callback = scope.callPackage;
};
};
};
}