-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
144 lines (141 loc) · 4.79 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
141
142
143
144
{
description = "Type-safe Helm";
inputs = {
hotPot.url = "github:shopstic/nix-hot-pot";
nixpkgs.follows = "hotPot/nixpkgs";
flakeUtils.follows = "hotPot/flakeUtils";
};
outputs = { self, nixpkgs, flakeUtils, hotPot }:
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};
deno = hotPotPkgs.deno_2_2_x;
runtimeInputs = builtins.attrValues
{
inherit (hotPotPkgs)
kubernetes-helm;
inherit (pkgs)
kubectl
sops
gnutar
coreutils
;
};
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
);
};
unmapped-src = pkgs.runCommandLocal "unmapped-src"
{
buildInputs = [ hotPotPkgs.deno-ship ];
}
''
cp -r --reflink=auto ${src} $out
chmod -R +w $out
deno-ship unmap-specifiers --src-dir "$out" --import-map "$out/deno.json"
'';
helmet-bin = pkgs.writeShellScript "helmet" ''
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
${(if denoJson.version == "*" then ''
deno run "''${DENO_RUN_FLAGS[@]}" ${unmapped-src}/src/cli.ts "$@"
'' else ''
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.path" = deno + "/bin/deno";
"deno.suggest.imports.hosts" = {
"https://deno.land" = false;
};
"deno.codeLens.test" = true;
"deno.codeLens.testArgs" = [ "-A" "--check" ];
"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_22
jq
;
inherit (hotPotPkgs)
typescript-eslint
;
};
shellHook = ''
mkdir -p ./.vscode
cat ${ vscodeSettings} > ./.vscode/settings.json
'';
};
packages = {
inherit helmet unmapped-src helmet-bin;
devEnv = devShell.inputDerivation;
};
defaultPackage = packages.helmet;
}
);
}