-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathdefault.nix
More file actions
87 lines (77 loc) · 2.2 KB
/
default.nix
File metadata and controls
87 lines (77 loc) · 2.2 KB
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
{
nixpkgs ? null,
}:
let
# To not having to maintain versions of dependencies in 2 locations
# we here read the flake.lock to parse revisions and hashes
# for a select few dependencies.
flakeLock = builtins.fromJSON (builtins.readFile ./flake.lock);
# Helper function to fetch metadata about a locked input.
# Currently only fetches relevant information for github.
flakeLockMeta =
node:
let
lock = flakeLock.nodes.${node}.locked;
in
{
inherit (lock)
owner
repo
rev
type
;
hash = lock.narHash;
};
# Import nixpkgs from either parameter or the lock file.
pkgs =
let
meta = flakeLockMeta "nixpkgs";
npkgs =
if nixpkgs == null then
builtins.fetchTarball {
url = "https://github.com/${meta.owner}/${meta.repo}/archive/${meta.rev}.tar.gz";
sha256 = meta.hash;
}
else
nixpkgs;
in
import npkgs { };
# Helper function that can fetch input from flake.lock
# by its name.
fetchFromFlakeLock =
node:
let
lock = flakeLockMeta node;
in
if lock.type == "github" then
pkgs.fetchFromGitHub (removeAttrs lock [ "type" ])
else
throw "fetcher for type ${lock.type} unsupported";
# Get nix-kube-generators.
kubelib =
let
src = fetchFromFlakeLock "nix-kube-generators";
in
{
lib = import "${src}/lib";
};
# Import the lib functions present in the flake.
lib = import ./make-env.nix { inherit kubelib; };
# Import the generator functions present in the flake.
generators = import ./pkgs/generators { inherit pkgs kubelib; };
# Import the modules lib to extract mkChartAttrs.
mlib = import ./lib { inherit pkgs kubelib; };
in
{
inherit (mlib.helm) mkChartAttrs;
# Wrap the lib functions to use the pkgs imported above
# without having the user needing to pass it in.
lib = {
mkEnv = args: lib.mkEnv ({ inherit pkgs; } // args);
mkEnvs = args: lib.mkEnvs ({ inherit pkgs; } // args);
};
# Have the nixidy cli available.
nixidy = pkgs.callPackage ./nixidy/nixidy.nix { };
# Have generators available.
generators = { inherit (generators) fromCRD fromChartCRD; };
}