-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
136 lines (134 loc) · 4.48 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
{
description = "Type-safe Helm";
inputs = {
hotPot.url = "github:shopstic/nix-hot-pot";
nixpkgs.follows = "hotPot/nixpkgs";
flakeUtils.follows = "hotPot/flakeUtils";
npmlock2nix = {
url = "github:nix-community/npmlock2nix/master";
flake = false;
};
};
outputs = { self, nixpkgs, flakeUtils, hotPot, npmlock2nix }:
flakeUtils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]
(system:
let
pkgs = import nixpkgs
{
inherit system;
};
hotPotPkgs = hotPot.packages.${system};
json2ts = pkgs.callPackage ./nix/json2ts {
npmlock2nix = (import npmlock2nix { inherit pkgs; }).v2;
nodejs = pkgs.nodejs_20;
};
deno = hotPotPkgs.deno;
runtimeInputs = builtins.attrValues
{
inherit json2ts;
inherit (hotPotPkgs)
kubernetes-helm;
inherit (pkgs)
kubectl
yq-go
sops
;
};
helmet =
let
name = "helmet";
src = builtins.path
{
path = ./.;
name = "${name}-src";
filter = with pkgs.lib; (path: /* type */_:
hasInfix "/src" path ||
hasSuffix "/deno.lock" path
);
};
deno-cache = pkgs.callPackage hotPot.lib.denoAppCache {
inherit name src deno;
cacheArgs = "./src/**/*.ts";
};
built = pkgs.callPackage hotPot.lib.denoAppBuild
{
inherit name deno deno-cache src;
inherit (hotPotPkgs) deno-app-build;
appSrcPath = "./src/helmet.ts";
denoRunFlags = "-A --no-lock";
};
denoJson = builtins.fromJSON (builtins.readFile ./deno.json);
in
pkgs.runCommandLocal "${name}-wrapped"
{
buildInputs = [ pkgs.makeWrapper ];
}
''
makeWrapper ${built}/bin/helmet $out/bin/helmet \
--set HELMET_VERSION "${denoJson.version}" \
--prefix PATH : "${pkgs.lib.makeBinPath runtimeInputs}"
'';
vscodeSettings = pkgs.writeTextFile {
name = "vscode-settings.json";
text = builtins.toJSON {
"deno.enable" = true;
"deno.lint" = true;
"deno.unstable" = true;
"deno.path" = deno + "/bin/deno";
"deno.suggest.imports.hosts" = {
"https://deno.land" = false;
};
"editor.tabSize" = 2;
"[typescript]" = {
"editor.defaultFormatter" = "denoland.vscode-deno";
"editor.formatOnSave" = true;
"editor.inlayHints.enabled" = "offUnlessPressed";
};
"yaml.schemaStore.enable" = true;
"yaml.schemas" = {
"https://json.schemastore.org/github-workflow.json" = ".github/workflows/*.yaml";
};
"nix.enableLanguageServer" = true;
"nix.formatterPath" = pkgs.nixpkgs-fmt + "/bin/nixpkgs-fmt";
"[nix]" = {
"editor.defaultFormatter" = "jnoortheen.nix-ide";
};
"nix.serverSettings" = {
"nil" = {
"formatting" = {
"command" = [ "nixpkgs-fmt" ];
};
};
};
"nix.serverPath" = pkgs.nil + "/bin/nil";
};
};
in
rec {
devShell = pkgs.mkShellNoCC
{
buildInputs = runtimeInputs ++ builtins.attrValues
{
inherit deno;
inherit (pkgs)
gh
nodejs_20
jq
;
inherit (hotPotPkgs)
typescript-eslint
;
};
shellHook = ''
mkdir -p ./.vscode
cat ${ vscodeSettings} > ./.vscode/settings.json
'';
};
packages = {
inherit json2ts helmet;
devEnv = devShell.inputDerivation;
};
defaultPackage = packages.helmet;
}
);
}