From a42a771ece52e0ef92b749688efab89fa608aa56 Mon Sep 17 00:00:00 2001 From: Julien Malka Date: Sun, 26 Dec 2021 00:21:23 +0100 Subject: [PATCH] Added status page --- base.nix | 1 + flake.nix | 2 ++ machines/lisa/default.nix | 7 +++++ modules/status/checks.csv | 4 +++ modules/status/default.nix | 48 +++++++++++++++++++++++++++++++++ packages/tinystatus/default.nix | 25 +++++++++++++++++ utils.nix | 1 + 7 files changed, 88 insertions(+) create mode 100644 modules/status/checks.csv create mode 100644 modules/status/default.nix create mode 100644 packages/tinystatus/default.nix diff --git a/base.nix b/base.nix index bb5e52e..acf0d91 100644 --- a/base.nix +++ b/base.nix @@ -30,6 +30,7 @@ rxvt_unicode xorg.xbacklight neovim + tinystatus ]; environment.variables.EDITOR = "nvim"; diff --git a/flake.nix b/flake.nix index c6c4899..7029f26 100644 --- a/flake.nix +++ b/flake.nix @@ -31,6 +31,7 @@ outputs = { self, home-manager, nixpkgs, unstable, sops-nix, neovim-nightly-overlay, nur, ... }@inputs: let utils = import ./utils.nix { inherit nixpkgs sops-nix home-manager inputs; nixpkgs-unstable = unstable; }; + pkgs = import nixpkgs { system = "x86_64-linux"; }; in with utils; { @@ -42,5 +43,6 @@ (builtins.attrNames (builtins.readDir ./modules))); nixosConfigurations = builtins.mapAttrs (name: value: (mkMachine name value self.nixosModules)) (importConfig ./machines); + packages."x86_64-linux".tinystatus = import ./packages/tinystatus { inherit pkgs; }; }; } diff --git a/machines/lisa/default.nix b/machines/lisa/default.nix index 6836153..ea20383 100644 --- a/machines/lisa/default.nix +++ b/machines/lisa/default.nix @@ -25,6 +25,13 @@ subdomain = "ci"; }; }; + status = { + enable = true; + nginx = { + enable = true; + subdomain = "status"; + }; + }; }; nix.maxJobs = lib.mkDefault 8; diff --git a/modules/status/checks.csv b/modules/status/checks.csv new file mode 100644 index 0000000..9ee2e4f --- /dev/null +++ b/modules/status/checks.csv @@ -0,0 +1,4 @@ +http, 200, Homepage, https://julienmalka.me +http, 200, CI, https://ci.julienmalka.me +ping, 0, Newton, newton.julienmalka.me + diff --git a/modules/status/default.nix b/modules/status/default.nix new file mode 100644 index 0000000..9989f2a --- /dev/null +++ b/modules/status/default.nix @@ -0,0 +1,48 @@ +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.luj.status; +in +{ + + options.luj.jackett = { + enable = mkEnableOption "activate status page"; + nginx.enable = mkEnableOption "activate nginx"; + nginx.subdomain = mkOption { + type = types.str; + }; + }; + + config = mkIf cfg.enable ( + mkMerge [{ + systemd = { + timers.simple-timer = { + wantedBy = [ "timers.target" ]; + partOf = [ "tinystatus.service" ]; + timerConfig.OnCalendar = "minutely"; + }; + services.tinystatus = { + serviceConfig.Type = "oneshot"; + script = '' + mkdir -p /var/www/status + ${pkgs.tinystatus}/bin/tinystatus ${./checks.csv} > /var/www/status/index.html + ''; + }; + }; + } + + + (mkIf cfg.nginx.enable { + luj.nginx.enable = true; + services.nginx.virtualHosts."${cfg.nginx.subdomain}.julienmalka.me" = { + enableACME = true; + forceSSL = true; + root = "/var/www/status/"; + }; + + })]); + + + + +} diff --git a/packages/tinystatus/default.nix b/packages/tinystatus/default.nix new file mode 100644 index 0000000..d395a15 --- /dev/null +++ b/packages/tinystatus/default.nix @@ -0,0 +1,25 @@ +{ pkgs, ... }: +with pkgs; +stdenv.mkDerivation rec { + pname = "tinystatus"; + version = "1.0.0"; + + src = fetchFromGitHub{ + owner = "bderenzo"; + repo = "tinystatus"; + rev="fc128adf240261ac99ea3e3be8d65a92eda52a73"; + sha256= "FvQwibm6F10l9/U3RnNTGu+C2JjHOwbv62VxXAfI7/s="; +}; + + postPatch = '' + patchShebangs . + ''; + + + installPhase = '' + mkdir -p $out/bin/ + mv tinystatus $out/bin/ + ''; + + +} diff --git a/utils.nix b/utils.nix index a1cc4a3..06a94df 100644 --- a/utils.nix +++ b/utils.nix @@ -25,6 +25,7 @@ in overlay-unstable (final: prev: { + tinystatus = prev.pkgs.callPackage ./packages/tinystatus {}; mosh = prev.mosh.overrideAttrs (old: { patches = (prev.lib.take 1 old.patches) ++ (prev.lib.sublist 4 4 old.patches); postPatch = '''';