-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathflake.nix
More file actions
90 lines (84 loc) · 3.37 KB
/
flake.nix
File metadata and controls
90 lines (84 loc) · 3.37 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
88
89
90
{
description = "DevGuard Web";
nixConfig = {
extra-substituters = [ "https://nix.garage.l3montree.cloud" ];
extra-trusted-public-keys = [ "nix.garage.l3montree.cloud:MGlzfPQKA91/zxw91CN+GP7NpjAAwmKvWXlDYgeeI8k=" ];
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
flake-utils.url = "github:numtide/flake-utils";
sbomnix.url = "github:tiiuae/sbomnix";
sbomnix.inputs.nixpkgs.follows = "nixpkgs"; # share the same nixpkgs pin
};
outputs = { self, nixpkgs, flake-utils, sbomnix }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
sbomnixPkgs = sbomnix.packages.${system};
npmPackages = (import ./nix/npm-packages.nix { inherit pkgs; });
pkgsLinuxAmd64 = nixpkgs.legacyPackages.x86_64-linux;
pkgsLinuxArm64 = nixpkgs.legacyPackages.aarch64-linux;
nodejs = import ./nix/nodejs.nix { inherit pkgs pkgsLinuxAmd64 pkgsLinuxArm64; };
nodejsLinuxLibs = nodejs.linuxLibs;
devguardWeb = pkgs.stdenv.mkDerivation {
name = "devguard-web";
src = pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [
./src
./public
./next.config.js
./postcss.config.js
./tailwind.config.js
./tsconfig.json
./package.json
./components.json
./sentry.server.config.ts
];
};
nativeBuildInputs = [ nodejs.${system} pkgs.cacert ];
buildPhase = ''
export NODE_OPTIONS="--max-old-space-size=4096"
export GIT_COMMIT_SHA="${self.rev or "dev"}"
cp -r ${npmPackages.patchedNodeModules}/node_modules ./node_modules
chmod -R u+w ./node_modules
node ./node_modules/next/dist/bin/next build --turbopack
cp -r public .next/standalone/ && cp -r .next/static .next/standalone/.next/
'';
installPhase = ''
mkdir -p $out
cp -r .next $out/
'';
};
nodejsLinuxAmd64 = nodejs.x86_64-linux;
nodejsLinuxArm64 = nodejs.aarch64-linux;
mkDevguardWebOCI = linuxPkgs: node: pkgs.dockerTools.buildLayeredImage {
name = "devguard-web-oci";
tag = "latest";
contents = [ node pkgs.cacert ] ++ (nodejsLinuxLibs linuxPkgs);
fakeRootCommands = ''
# Copy standalone output to /app (outside Nix store) so Next.js
# can write its cache at runtime. The Nix store is read-only.
mkdir -p app
cp -r ${devguardWeb}/.next/standalone/. app/
mkdir -p app/.next/cache
chown -R 53111:53111 app
'';
config = {
Cmd = [ "${node}/bin/node" "/app/server.js" ];
User = "53111:53111";
Expose = [ "3000" ];
};
};
in
{
packages = {
default = devguardWeb;
node_modulesArm64 = (import ./nix/npm-packages.nix { pkgs = pkgsLinuxArm64; }).patchedNodeModules;
node_modulesAmd64 = (import ./nix/npm-packages.nix { pkgs = pkgsLinuxAmd64; }).patchedNodeModules;
"devguard-web-amd64" = mkDevguardWebOCI pkgsLinuxAmd64 nodejsLinuxAmd64;
"devguard-web-arm64" = mkDevguardWebOCI pkgsLinuxArm64 nodejsLinuxArm64;
};
}
);
}