aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2024-08-30 07:11:39 +0100
committerAkshay <[email protected]>2024-08-30 07:11:39 +0100
commitc2326bc381923d91d8becc58fc52cd984c5014d1 (patch)
tree3968484ca7cf0fb09a000c1ca3db592c0208b1b2
parent5e765cc96b89862dd8091112b79c246ef6c0264e (diff)
add nix module
-rw-r--r--flake.nix42
-rw-r--r--src/index.js3
2 files changed, 44 insertions, 1 deletions
diff --git a/flake.nix b/flake.nix
index 60a501d..2bee636 100644
--- a/flake.nix
+++ b/flake.nix
@@ -103,5 +103,47 @@
103 }); 103 });
104 104
105 formatter = forAllSystems (system: nixpkgsFor."${system}".alejandra); 105 formatter = forAllSystems (system: nixpkgsFor."${system}".alejandra);
106
107 nixosModules.default = {
108 config,
109 pkgs,
110 lib,
111 ...
112 }:
113 with lib; {
114 options = {
115 services.readit = {
116 enable = mkOption {
117 type = types.bool;
118 default = false;
119 description = "Enable readit";
120 };
121 port = mkOption {
122 type = types.int;
123 default = 3000;
124 description = "Port to run readit on";
125 };
126 };
127 };
128
129 config = mkIf config.services.readit.enable {
130 systemd.services.readit = {
131 description = "readit service";
132 wantedBy = ["multi-user.target"];
133
134 serviceConfig = {
135 ExecStart = "${pkgs.readit}/bin/readit";
136 Restart = "always";
137 };
138
139 listenStream = ["0.0.0.0:${toString config.services.readit.port}"];
140
141 # If the binary needs specific environment variables, set them here
142 environment = {
143 READIT_PORT = "${toString config.services.readit.port}";
144 };
145 };
146 };
147 };
106 }; 148 };
107} 149}
diff --git a/src/index.js b/src/index.js
index a1b9967..099ee4d 100644
--- a/src/index.js
+++ b/src/index.js
@@ -11,7 +11,8 @@ app.set('view engine', 'pug');
11app.use(express.static(path.join(__dirname, 'public'))); 11app.use(express.static(path.join(__dirname, 'public')));
12app.use('/', routes); 12app.use('/', routes);
13 13
14const server = app.listen(3000, () => { 14const port = process.env.READIT_PORT;
15const server = app.listen(port?port:3000, () => {
15 console.log(`started on ${server.address().port}`); 16 console.log(`started on ${server.address().port}`);
16}); 17});
17 18