forked from gytis-ivaskevicius/flake-utils-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.nix
41 lines (34 loc) · 1.27 KB
/
options.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
{ lib, config, inputs, ... }:
let
inherit (lib) mkIf filterAttrs mapAttrsToList mapAttrs' mkOption types;
mkFalseOption = description: mkOption {
inherit description;
default = false;
example = true;
type = types.bool;
};
flakes = filterAttrs (name: value: value ? outputs) inputs;
flakesWithPkgs = filterAttrs (name: value: value.outputs ? legacyPackages || value.outputs ? packages) flakes;
nixRegistry = builtins.mapAttrs
(name: v: { flake = v; })
flakes;
in
{
options = {
nix.generateNixPathFromInputs = mkFalseOption "Generate NIX_PATH from available inputs.";
nix.generateRegistryFromInputs = mkFalseOption "Generate Nix registry from available inputs.";
nix.linkInputs = mkFalseOption "Symlink inputs to /etc/nix/inputs.";
};
config = {
nix.registry =
if config.nix.generateRegistryFromInputs
then nixRegistry
else { self.flake = flakes.self; };
environment.etc = mkIf (config.nix.linkInputs || config.nix.generateNixPathFromInputs) (mapAttrs'
(name: value: { name = "nix/inputs/${name}"; value = { source = value.outPath; }; })
inputs);
nix.nixPath = mkIf config.nix.generateNixPathFromInputs (mapAttrsToList
(name: _: "${name}=/etc/nix/inputs/${name}")
flakesWithPkgs);
};
}