-
Notifications
You must be signed in to change notification settings - Fork 77
/
simpleFlake.nix
82 lines (77 loc) · 1.8 KB
/
simpleFlake.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
{ lib
, defaultSystems ? [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]
}:
# This function returns a flake outputs-compatible schema.
{
# pass an instance of self
self
, # pass an instance of the nixpkgs flake
nixpkgs
, # we assume that the name maps to the project name, and also that the
# overlay has an attribute with the `name` prefix that contains all of the
# project's packages.
name
, # nixpkgs config
config ? { }
, # pass either a function or a file
overlay ? null
, # use this to load other flakes overlays to supplement nixpkgs
preOverlays ? [ ]
, # maps to the devShell output. Pass in a shell.nix file or function.
shell ? null
, # pass the list of supported systems
systems ? defaultSystems
}:
let
loadOverlay = obj:
if obj == null then
[ ]
else
[ (maybeImport obj) ]
;
maybeImport = obj:
if (builtins.typeOf obj == "path") || (builtins.typeOf obj == "string") then
import obj
else
obj
;
overlays = preOverlays ++ (loadOverlay overlay);
shell_ = maybeImport shell;
outputs = lib.eachSystem systems (system:
let
pkgs = import nixpkgs {
inherit
config
overlays
system
;
};
packages = pkgs.${name} or { };
in
{
# Use the legacy packages since it's more forgiving.
legacyPackages = packages;
}
//
(
if packages ? defaultPackage then {
defaultPackage = packages.defaultPackage;
} else { }
)
//
(
if packages ? checks then {
checks = packages.checks;
} else { }
)
//
(
if shell != null then {
devShell = shell_ { inherit pkgs; };
} else if packages ? devShell then {
devShell = packages.devShell;
} else { }
)
);
in
outputs