-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
153 lines (126 loc) · 3.55 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
{
description = "winvoice-server dev env / packaging";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = inputs @ { self, nixpkgs, ... }:
let
inherit (nixpkgs) lib;
inherit (self) outputs;
name = "winvoice-gui";
version = "0.2.0";
genSystems = lib.genAttrs ["aarch64-darwin" "aarch64-linux" "i686-linux" "x86_64-darwin" "x86_64-linux"];
mkPkgs = system: import nixpkgs {
inherit system;
config.allowUnfree = true;
overlays = [ ];
};
nodeJs = builtins.getAttr "nodejs_21";
in {
devShells = genSystems (system:
let pkgs = mkPkgs system;
in {
default = pkgs.mkShell {
inherit name;
packages = [(nodeJs pkgs)] ++ (with pkgs; [
# test
mkcert
# deploy
kind kubectl kubectl-cnpg kubectx
terraform
]);
};
});
packages = genSystems (system:
let
inherit (lib) fileset;
pkgs = mkPkgs system;
inherit (pkgs) importNpmLock;
mkFileset = fileset: lib.fileset.toSource {
inherit fileset;
root = ./.;
};
nodejs = nodeJs pkgs;
packageJson = fileset.unions [ ./package-lock.json ./package.json ];
meta = {
description = "A web UI for Winvoice";
homepage = "https://github.com/Iron-E/winvoice-gui";
license = with lib.licenses; [gpl3Plus];
mainProgram = "winvoice-gui";
};
# see nixos.org/manual/nixpkgs/unstable#javascript-buildNpmPackage
winvoice-gui-unwrapped = pkgs.buildNpmPackage {
inherit version;
pname = "${name}-unwrapped";
# env vars
NEXT_TELEMETRY_DISABLED = 1;
NODE_ENV = "production";
# source
inherit nodejs;
npmConfigHook = importNpmLock.npmConfigHook;
npmDeps = importNpmLock {
npmRoot = mkFileset packageJson;
};
src = mkFileset (fileset.unions [
./jest.config.json
./next-env.d.ts
./next.config.js
./postcss.config.js
./src
./tailwind.config.js
./tests
./tsconfig-base.json
./tsconfig.json
packageJson
]);
postInstall = /* bash */ ''
# install locations
targetBin="$out/bin/${name}"
targetLib="$out/lib/node_modules/${name}"
tmpLib="$${targetLib}-2"
# grab next standalone files
cp -r "$targetLib/.next/standalone" "$tmpLib"
mkdir -p "$tmpLib/.next"
cp -r "$targetLib/.next/static" "$tmpLib/.next/static"
# move next standalone files into target location
rm -r "$targetLib"
mv "$tmpLib" "$targetLib"
'';
meta = {
inherit (meta) homepage license;
description = "${meta.description} (unwrapped)";
};
};
winvoice-gui = pkgs.writeShellApplication {
inherit meta name;
derivationArgs = { inherit version; };
runtimeEnv.NODE_ENV = "production";
runtimeInputs = [ nodejs ];
text = /* sh */ ''node "${lib.getLib winvoice-gui-unwrapped}/lib/node_modules/${name}/server.js"'';
};
oci-image = let
inherit (pkgs) dockerTools;
group = "nodejs";
user = "nextjs";
in dockerTools.streamLayeredImage { # https://nixos.org/manual/nixpkgs/unstable#ssec-pkgs-dockerTools-streamLayeredImage
inherit name;
tag = version;
created = "2024-05-06T21:29:17+00:00"; # date --iso-8601='seconds' --utc
enableFakechroot = true;
fakeRootCommands = /* sh */ ''
${dockerTools.shadowSetup}
groupadd --system --gid 1001 ${group}
useradd --system --uid 1001 ${user}
'';
config = {
Entrypoint = [ "${lib.getExe winvoice-gui}" ];
User = "${user}:${group}";
};
};
in {
inherit oci-image winvoice-gui winvoice-gui-unwrapped;
default = winvoice-gui;
});
overlays = { };
};
}