commit 740ac7c4c9bfb4bc45a7bb86d2a86bb5cb7f742a
parent df8795157de65eeccd9fa9242f3ddc06aa0dfbeb
Author: Silas Brack <silasbrack@gmail.com>
Date: Tue, 30 Sep 2025 11:54:12 +0200
feat: add simple web app
Diffstat:
5 files changed, 233 insertions(+), 14 deletions(-)
diff --git a/Makefile b/Makefile
@@ -2,7 +2,7 @@
## Deploy configuration to production server
deploy-digitalocean:
- nixos-rebuild test --show-trace --fast --flake .#nixos-s-1vcpu-512mb-10gb-ams3-01 --target-host root@188.166.127.72
+ nixos-rebuild test --show-trace --no-reexec --flake .#nixos-s-1vcpu-512mb-10gb-ams3-01 --target-host root@188.166.127.72
deploy-hetzner:
- nixos-rebuild test --show-trace --fast --flake .#debian-2gb-hel1-1 --target-host root@46.62.150.48
+ nixos-rebuild test --show-trace --no-reexec --flake .#debian-2gb-hel1-1 --target-host root@46.62.150.48
diff --git a/flake.lock b/flake.lock
@@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
- "lastModified": 1748162331,
- "narHash": "sha256-rqc2RKYTxP3tbjA+PB3VMRQNnjesrT0pEofXQTrMsS8=",
+ "lastModified": 1758791193,
+ "narHash": "sha256-F8WmEwFoHsnix7rt290R0rFXNJiMbClMZyIC/e+HYf0=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "7c43f080a7f28b2774f3b3f43234ca11661bf334",
+ "rev": "25e53aa156d47bad5082ff7618f5feb1f5e02d01",
"type": "github"
},
"original": {
@@ -18,11 +18,27 @@
},
"nixpkgs_2": {
"locked": {
- "lastModified": 1744868846,
- "narHash": "sha256-5RJTdUHDmj12Qsv7XOhuospjAjATNiTMElplWnJE9Hs=",
+ "lastModified": 1757347588,
+ "narHash": "sha256-tLdkkC6XnsY9EOZW9TlpesTclELy8W7lL2ClL+nma8o=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "ebe4301cbd8f81c4f8d3244b3632338bbeb6d49c",
+ "rev": "b599843bad24621dcaa5ab60dac98f9b0eb1cabe",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "nixpkgs_3": {
+ "locked": {
+ "lastModified": 1758262103,
+ "narHash": "sha256-aBGl3XEOsjWw6W3AHiKibN7FeoG73dutQQEqnd/etR8=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "12bd230118a1901a4a5d393f9f56b6ad7e571d01",
"type": "github"
},
"original": {
@@ -32,22 +48,94 @@
"type": "github"
}
},
+ "pyproject-build-systems": {
+ "inputs": {
+ "nixpkgs": [
+ "simple-web-app",
+ "nixpkgs"
+ ],
+ "pyproject-nix": [
+ "simple-web-app",
+ "pyproject-nix"
+ ],
+ "uv2nix": [
+ "simple-web-app",
+ "uv2nix"
+ ]
+ },
+ "locked": {
+ "lastModified": 1757296493,
+ "narHash": "sha256-6nzSZl28IwH2Vx8YSmd3t6TREHpDbKlDPK+dq1LKIZQ=",
+ "owner": "pyproject-nix",
+ "repo": "build-system-pkgs",
+ "rev": "5b8e37fe0077db5c1df3a5ee90a651345f085d38",
+ "type": "github"
+ },
+ "original": {
+ "owner": "pyproject-nix",
+ "repo": "build-system-pkgs",
+ "type": "github"
+ }
+ },
+ "pyproject-nix": {
+ "inputs": {
+ "nixpkgs": [
+ "simple-web-app",
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1757246327,
+ "narHash": "sha256-6pNlGhwOIMfhe/RLjHdpXveKS4FyLHvlGe+KtjDild4=",
+ "owner": "pyproject-nix",
+ "repo": "pyproject.nix",
+ "rev": "8d77f342d66ad1601cdb9d97e9388b69f64d4c8e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "pyproject-nix",
+ "repo": "pyproject.nix",
+ "type": "github"
+ }
+ },
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
+ "simple-web-app": "simple-web-app",
"sops-nix": "sops-nix"
}
},
+ "simple-web-app": {
+ "inputs": {
+ "nixpkgs": "nixpkgs_2",
+ "pyproject-build-systems": "pyproject-build-systems",
+ "pyproject-nix": "pyproject-nix",
+ "uv2nix": "uv2nix"
+ },
+ "locked": {
+ "lastModified": 1758989928,
+ "narHash": "sha256-3wpQQVYp4nhd2Ck5sSv0XwsKP54k08VxPkGLzIu5Xkw=",
+ "owner": "silasbrack",
+ "repo": "simple-web-app",
+ "rev": "066b714718f9b06148f47aec1d621013533ec8bd",
+ "type": "github"
+ },
+ "original": {
+ "owner": "silasbrack",
+ "repo": "simple-web-app",
+ "type": "github"
+ }
+ },
"sops-nix": {
"inputs": {
- "nixpkgs": "nixpkgs_2"
+ "nixpkgs": "nixpkgs_3"
},
"locked": {
- "lastModified": 1747603214,
- "narHash": "sha256-lAblXm0VwifYCJ/ILPXJwlz0qNY07DDYdLD+9H+Wc8o=",
+ "lastModified": 1758425756,
+ "narHash": "sha256-L3N8zV6wsViXiD8i3WFyrvjDdz76g3tXKEdZ4FkgQ+Y=",
"owner": "Mic92",
"repo": "sops-nix",
- "rev": "8d215e1c981be3aa37e47aeabd4e61bb069548fd",
+ "rev": "e0fdaea3c31646e252a60b42d0ed8eafdb289762",
"type": "github"
},
"original": {
@@ -55,6 +143,31 @@
"repo": "sops-nix",
"type": "github"
}
+ },
+ "uv2nix": {
+ "inputs": {
+ "nixpkgs": [
+ "simple-web-app",
+ "nixpkgs"
+ ],
+ "pyproject-nix": [
+ "simple-web-app",
+ "pyproject-nix"
+ ]
+ },
+ "locked": {
+ "lastModified": 1756973152,
+ "narHash": "sha256-9JcKAA7T9J98LWdcxbXvmf+amQG3ZErxqQnBjEJI04I=",
+ "owner": "pyproject-nix",
+ "repo": "uv2nix",
+ "rev": "64298e806f4a5f63a51c625edc100348138491aa",
+ "type": "github"
+ },
+ "original": {
+ "owner": "pyproject-nix",
+ "repo": "uv2nix",
+ "type": "github"
+ }
}
},
"root": "root",
diff --git a/flake.nix b/flake.nix
@@ -2,15 +2,18 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
sops-nix.url = "github:Mic92/sops-nix";
+ simple-web-app.url = "github:silasbrack/simple-web-app";
};
outputs =
{
nixpkgs,
sops-nix,
+ simple-web-app,
...
}:
let
system = "x86_64-linux";
+ pkgs = import nixpkgs { inherit system; };
in
{
# production configuration
@@ -25,7 +28,14 @@
inherit system;
modules = [
sops-nix.nixosModules.sops
- (import ./nixos/configuration-debian-2gb-hel1-1.nix)
+ (
+ inputs@{
+ pkgs,
+ system,
+ ...
+ }:
+ import ./nixos/configuration-debian-2gb-hel1-1.nix (inputs // { inherit simple-web-app; })
+ )
];
};
# development environment (nix develop)
diff --git a/nixos/configuration-debian-2gb-hel1-1.nix b/nixos/configuration-debian-2gb-hel1-1.nix
@@ -1,6 +1,6 @@
{
pkgs,
- modulesPath,
+ simple-web-app,
...
}:
{
@@ -49,6 +49,7 @@
time.timeZone = "Europe/Helsinki";
imports = [
+ ./simple-web-app.nix
# (modulesPath + "/virtualisation/digital-ocean-image.nix")
# ./vpn.nix
];
@@ -126,6 +127,18 @@
proxyPass = "http://127.0.0.1:8360";
};
};
+ virtualHosts."simple.fnarglebeast.com" = {
+ forceSSL = true;
+ enableACME = true;
+ locations."/" = {
+ proxyPass = "http://127.0.0.1:8000";
+ };
+ };
+ };
+
+ services.simple-web-app = {
+ enable = true;
+ package = simple-web-app.packages."x86_64-linux".default;
};
# sops.secrets.livebook_password_env_file = { };
diff --git a/nixos/simple-web-app.nix b/nixos/simple-web-app.nix
@@ -0,0 +1,83 @@
+{
+ config,
+ lib,
+ ...
+}:
+
+with lib;
+
+let
+ cfg = config.services.simple-web-app;
+in
+{
+ options = {
+ services.simple-web-app = {
+ enable = mkEnableOption "Simple Web App";
+
+ package = mkOption {
+ defaultText = lib.literalMD "`packages.default` from the simple-web-app flake";
+ };
+
+ # environment = mkOption {
+ # type = types.enum [
+ # "dev"
+ # "prod"
+ # ];
+ # default = "dev";
+ # example = "prod";
+ # description = "The environment (dev / prod) to deploy as.";
+ # };
+
+ user = mkOption {
+ type = types.str;
+ default = "simple_web_app_user";
+ description = "User account under which my app runs.";
+ };
+
+ port = mkOption {
+ type = types.nullOr types.int;
+ default = 8000;
+ example = 8080;
+ description = ''
+ The port to bind simple web app server to.
+ '';
+ };
+
+ database_path = mkOption {
+ type = types.str;
+ default = "/tmp/test.sqlite3";
+ };
+ };
+ };
+
+ config = mkIf cfg.enable {
+ networking.firewall.allowedTCPPorts = [ cfg.port ];
+
+ users.groups.${cfg.user} = { };
+ users.users.${cfg.user} = {
+ name = cfg.user;
+ group = cfg.user;
+ description = "";
+ isSystemUser = true;
+ createHome = false;
+ };
+
+ systemd.services = {
+ simple-web-app = {
+ wantedBy = [ "multi-user.target" ];
+ description = "Run simple web app.";
+ after = [ "network.target" ];
+ serviceConfig = {
+ Type = "simple";
+ User = cfg.user;
+ ExecStart = "${cfg.package}/bin/simple-web-app";
+ };
+ environment = {
+ # PORT = builtins.toString cfg.port;
+ DATABASE_PATH = cfg.database_path;
+ };
+ };
+
+ };
+ };
+}