-
Notifications
You must be signed in to change notification settings - Fork 3
/
flake.nix
159 lines (144 loc) · 4.63 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
{
inputs = {
nixpkgs-matrix = {
type = "indirect";
id = "nixpkgs-matrix";
};
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs-matrix, flake-utils, ... }:
let
# The target systems and their vercel/pkg mapping
systems = { "x86_64-linux" = [ "linux" "x64" ]; };
in flake-utils.lib.eachSystem (builtins.attrNames systems) (system:
let
pkgs = nixpkgs-matrix.legacyPackages.${system};
platform = builtins.elemAt systems.${system} 0;
arch = builtins.elemAt systems.${system} 1;
utils = pkgs.callPackage ./utils.nix { };
commitHash = builtins.replaceStrings [ "-dirty" ] [ "" ]
(toString (self.rev or self.dirtyRev));
npmDepsHash = builtins.readFile ./npmDepsHash;
polykey-cli = pkgs.buildNpmPackage {
inherit npmDepsHash;
pname = utils.packageName;
version = utils.packageVersion;
src = utils.src;
COMMIT_HASH = commitHash;
GIT_DIR = if commitHash != null then null else utils.dotGit;
postInstall = ''
mv "$packageOut"/build/build.json "$out"/build.json;
rm -rf \
"$packageOut"/build \
"$packageOut"/src \
"$packageOut"/.env.example \
"$packageOut"/images \
"$packageOut"/scripts \
"$packageOut"/tsconfig.build.json \
"$packageOut"/tsconfig.json \
"$packageOut"/LICENSE \
"$packageOut"/ADDITIONAL_TERMS \
"$packageOut"/README.md;
'';
};
polykey-cli-executable = pkgs.buildNpmPackage {
inherit npmDepsHash;
name =
"${utils.packageName}-${utils.packageVersion}-${platform}-${arch}";
src = utils.src;
PKG_CACHE_PATH = utils.pkgCachePath;
PKG_IGNORE_TAG = 1;
COMMIT_HASH = commitHash;
GIT_DIR = if commitHash != null then null else utils.dotGit;
postBuild = ''
npm run pkg -- \
--output=out \
--bin=dist/polykey.js \
--node-version=${utils.nodeVersion} \
--platform=${platform} \
--arch=${arch}
'';
installPhase = ''
cp ${if platform == "win32" then "out.exe" else "out"} $out
'';
dontFixup = true;
};
buildJSON =
builtins.fromJSON (builtins.readFile "${polykey-cli}/build.json");
docker = pkgs.dockerTools.buildImage {
name = polykey-cli.name;
copyToRoot = [ polykey-cli ];
keepContentsDirlinks = true;
created = "now";
extraCommands = ''
mkdir -m 1777 tmp
'';
config = {
Entrypoint = [ "polykey" ];
Labels = buildJSON.versionMetadata;
};
};
shell = { ci ? false }:
with pkgs;
pkgs.mkShell {
nativeBuildInputs = [
nodejs_20
prefetch-npm-deps
shellcheck
gitAndTools.gh
gitAndTools.git
awscli2
skopeo
jq
];
PKG_CACHE_PATH = utils.pkgCachePath;
PKG_IGNORE_TAG = 1;
shellHook = ''
echo "Entering $(npm pkg get name)"
set -o allexport
. ./.env
set +o allexport
set -v
${lib.optionalString ci ''
set -o errexit
set -o nounset
set -o pipefail
shopt -s inherit_errexit
''}
mkdir --parents "$(pwd)/tmp"
export PATH="$(pwd)/dist/bin:$(npm root)/.bin:$PATH"
npm install --ignore-scripts
set +v
'';
};
in {
apps = {
default = {
type = "app";
program = "${polykey-cli}/bin/polykey";
};
executable = {
type = "app";
program = polykey-cli-executable;
};
};
packages = {
default = polykey-cli;
executable = polykey-cli-executable;
docker = docker;
};
devShells = {
default = shell { ci = false; };
ci = shell { ci = true; };
};
}) // (let
modules = import ./modules.nix {
inherit nixpkgs-matrix;
outputs = self.outputs;
system = "x86_64-linux";
};
in {
nixosModules.default = modules.polykey;
homeModules.default = modules.polykey-home;
});
}