blob: cd8f7894fa8003ed47d7a7c7fda72238e9e9596d (
plain)
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
|
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
};
outputs = {
self,
nixpkgs,
}: let
supportedSystems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin"];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = forAllSystems (system:
import nixpkgs {
inherit system;
overlays = [
self.overlays.default
];
});
in {
overlays.default = final: prev: {
node_modules = with final;
stdenv.mkDerivation {
pname = "readit-node-modules";
version = "0.0.1";
impureEnvVars =
lib.fetchers.proxyImpureEnvVars
++ ["GIT_PROXY_COMMAND" "SOCKS_SERVER"];
src = ./.;
nativeBuildInputs = [bun];
buildInputs = [nodejs-slim_latest];
dontConfigure = true;
dontFixup = true;
buildPhase = ''
bun install --no-progress --frozen-lockfile
'';
installPhase = ''
mkdir -p $out/node_modules
cp -R ./node_modules/* $out/node_modules
ls -la $out/node_modules
'';
outputHash = "sha256-3hjIDUMEi259ylUL+W0FGqiuIl2uRecb9yWq05XbT+o=";
outputHashAlgo = "sha256";
outputHashMode = "recursive";
};
readit = with final;
stdenv.mkDerivation {
pname = "readit";
version = "0.0.1";
src = ./.;
nativeBuildInputs = [makeBinaryWrapper];
buildInputs = [bun];
buildPhase = ''
runHook preBuild
runHook postBuild
'';
dontFixup = true;
installPhase = ''
runHook preInstall
mkdir -p $out/bin
ln -s ${node_modules}/node_modules $out
cp -R ./* $out
# bun is referenced naked in the package.json generated script
# makeBinaryWrapper ${bun}/bin/bun $out/bin/$pname \
# --add-flags "run --prefer-offline --no-install $out/app.js"
makeBinaryWrapper ${bun}/bin/bun $out/bin/$pname \
--prefix PATH : ${lib.makeBinPath [bun]} \
--add-flags "run --prefer-offline --no-install $out/src/index.js"
'';
};
};
devShell = forAllSystems (system: let
pkgs = nixpkgsFor."${system}";
in
pkgs.mkShell {
nativeBuildInputs = [
pkgs.bun
pkgs.biome
];
});
packages = forAllSystems (system: {
inherit (nixpkgsFor."${system}") readit node_modules;
});
defaultPackage = forAllSystems (system: nixpkgsFor."${system}".readit);
apps = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
in {
default = {
type = "app";
program = "${pkgs.readit}/bin/readit";
};
});
formatter = forAllSystems (system: nixpkgsFor."${system}".alejandra);
nixosModules.default = {
config,
pkgs,
lib,
...
}:
with lib; {
options = {
services.readit = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable readit";
};
port = mkOption {
type = types.int;
default = 3000;
description = "Port to run readit on";
};
};
};
config = mkIf config.services.readit.enable {
nixpkgs.overlays = [self.overlays.default];
systemd.services.readit = {
description = "readit service";
wantedBy = ["multi-user.target"];
serviceConfig = {
ListenStream = "0.0.0.0:${toString config.services.readit.port}";
ExecStart = "${pkgs.readit}/bin/readit";
Restart = "always";
};
# If the binary needs specific environment variables, set them here
environment = {
READIT_PORT = "${toString config.services.readit.port}";
};
};
};
};
};
}
|