-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.nix
47 lines (43 loc) · 1.41 KB
/
lib.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
{ nixpkgs-lib }:
let
inherit (nixpkgs-lib) attrValues escapeShellArg makeLibraryPath;
inherit (nixpkgs-lib.modules) evalModules;
inherit (nixpkgs-lib.attrsets) foldlAttrs;
inherit (nixpkgs-lib.strings) concatStringsSep;
mkFlake = inputs@{ ... }:
let
inherit (inputs) system pkgs;
module = mkModule inputs;
inherit (module) config;
in
{
formatter.${system} = config.formatter;
devShells.${system}.default = mkShell config pkgs system;
} // config.flake;
mkShell = config: pkgs: system:
config.mkShell {
packages = config.packages ++ [ config.formatter ];
LD_LIBRARY_PATH = makeLibraryPath config.libraries;
inputsFrom = attrValues (config.flake.packages.${system} or { });
shellHook =
let
aliasCmd = foldlAttrs (acc: name: value: acc + ''alias ${escapeShellArg name}=${escapeShellArg value};'') "" config.aliases;
envCmd = foldlAttrs (acc: name: value: acc + ''export ${escapeShellArg name}=${escapeShellArg value};'') "" config.environment;
in
concatStringsSep "\n" ([
aliasCmd
envCmd
] ++ config.shellHooks ++ [ config.shellHook ]);
};
mkModule = { extraArgs, userModule, ... }:
let
toplevel = import ./modules/top-level.nix { inherit extraArgs; };
in
evalModules {
modules = [ toplevel userModule ];
};
lib = {
inherit mkFlake;
};
in
lib