-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
140 lines (138 loc) · 4.62 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
137
138
139
140
{
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;
overlays = [
(self: super: {
nodejs-16_x = super.nodejs-18_x;
})
];
};
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
;
};
denoJson = builtins.fromJSON (builtins.readFile ./deno.json);
src = builtins.path
{
path = ./.;
name = "helmet-src";
filter = with pkgs.lib; (path: /* type */_:
hasInfix "/src" path ||
hasSuffix "/deno.lock" path ||
hasSuffix "/deno.json" path
);
};
helmet-bin = pkgs.writeShellScript "helmet"
(if denoJson.version == "0.0.0" then ''
deno run -A --check ${src}/src/cli.ts "$@"
'' else ''
DENO_RUN_FLAGS=("-A")
if [ ! -f deno.lock ]; then
DENO_RUN_FLAGS+=("--no-lock")
fi
if [ -f deno.json ]; then
DENO_RUN_FLAGS+=("--config=deno.json")
elif [ -f deno.jsonc ]; then
DENO_RUN_FLAGS+=("--config=deno.jsonc")
fi
deno run "''${DENO_RUN_FLAGS[@]}" jsr:${denoJson.name}@${denoJson.version}/cli "$@"
'');
helmet = pkgs.runCommandLocal "helmet"
{
buildInputs = [ pkgs.makeWrapper ];
}
''
makeWrapper ${helmet-bin} $out/bin/helmet \
--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;
}
);
}