-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathflake.nix
178 lines (165 loc) · 5.47 KB
/
flake.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
{
description = "A collection of plugins for the Yazi file manager";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
# Flake utils for stripping some boilerplate
flake-utils.url = "github:numtide/flake-utils";
flake-utils.inputs.systems.follows = "systems";
flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus/v1.4.0";
flake-utils-plus.inputs.flake-utils.follows = "flake-utils";
# The list of supported systems.
systems.url = "github:nix-systems/default-linux";
# Haumea for directory-defined attrset loading
haumea.url = "github:nix-community/haumea/v0.2.2";
haumea.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
inputs@{
self,
nixpkgs,
flake-utils-plus,
systems,
haumea,
...
}:
let
inherit (self) outputs;
instantiate_lib = lib: pkgs: rec {
inherit (pkgs) callPackage;
inherit (lib)
mapAttrs
mapAttrsToList
listToAttrs
filterAttrs
mkMerge
attrValues
filter
flatten
attrByPath
mkOption
mkEnableOption
;
# bypass.package = ...
# -> bypass = ...
CondRaiseAttrs = n: set: mapAttrs (_n: v: v."${n}") (filterAttrs (_n: v: v ? "${n}") set);
packages = (CondRaiseAttrs "package" YaziPlugins);
homeManagerModulesRaised = (CondRaiseAttrs "hm-module" YaziPlugins);
homeManagerModulesImports = (
map (
v:
{ config, lib, ... }:
let
cfg = config.programs.yazi.yaziPlugins.plugins.${v.name};
in
{
imports = (
filter (v: v != { }) [
(
inputs:
lib.mkIf (cfg.enable && inputs.config.programs.yazi.yaziPlugins.enable) (
v.config ({ inherit cfg; } // (import ./lib.nix inputs)) inputs
)
)
(_: {
config = lib.mkIf (cfg.enable && cfg.package != null) {
programs.yazi.plugins.${v.name} = cfg.package;
};
})
(_: {
config = lib.mkIf (cfg.enable && cfg ? "runtimeDeps") {
programs.yazi.yaziPlugins.runtimeDeps = cfg.runtimeDeps;
};
})
(inputs: (v.options ({ inherit cfg; } // (import ./lib.nix inputs))) inputs)
(
{ pkgs, ... }:
{
options.programs.yazi.yaziPlugins.plugins.${v.name} = {
package = mkOption {
type = lib.types.nullOr lib.types.package;
description = "The ${v.name} package to use";
default = self.packages.${pkgs.system}.${v.name};
};
enable = mkEnableOption v.name;
};
}
)
]
);
}
) (attrValues homeManagerModulesRaised)
);
YaziPlugins =
let
AttrName = path: builtins.baseNameOf (builtins.dirOf path);
in
haumea.lib.load {
src = ./plugins;
inputs =
(removeAttrs pkgs [
"self"
"super"
"root"
])
// {
flake = self;
};
# Call files like with callPackage
loader = [
{
matches = str: str == "package.nix";
loader = inputs: path: (haumea.lib.loaders.callPackage inputs path);
}
{
matches = str: str == "hm-module.nix";
loader =
_: path:
let
value = haumea.lib.loaders.verbatim { } path;
name = AttrName path;
in
{
inherit name;
options =
if value ? "options" then
(outer_inputs: inputs: {
options.programs.yazi.yaziPlugins.plugins.${name} = value.options outer_inputs inputs;
})
else
_: _: { };
config = if value ? "config" then value.config else _: _: { };
};
}
];
};
};
in
flake-utils-plus.lib.mkFlake {
inherit self inputs;
outputsBuilder =
channels:
let
pkgs = channels.nixpkgs;
lib = inputs.nixpkgs.lib;
instance = (instantiate_lib lib pkgs);
inherit (pkgs) system;
in
{
formatter = pkgs.nixfmt-rfc-style;
inherit (instance) packages;
legacyPackages = {
homeManagerModules = rec {
yaziPlugins =
{ lib, ... }:
{
imports =
((instantiate_lib lib (inputs.nixpkgs.legacyPackages.${system})).homeManagerModulesImports)
++ [ ./module.nix ];
};
default = yaziPlugins;
};
};
};
overlays.default = final: prev: { yaziPlugins = (instantiate_lib (final.lib) prev).packages; };
};
}