From 48c36bbd4ca561c450af376b8f12fb25dbdb3809 Mon Sep 17 00:00:00 2001 From: Julien Malka <julien.malka@me.com> Date: Sat, 25 Dec 2021 22:31:24 +0100 Subject: [PATCH 1/8] Updated flake inputs --- flake.lock | 48 ++++++++++-------------------------------------- flake.nix | 2 ++ 2 files changed, 12 insertions(+), 38 deletions(-) diff --git a/flake.lock b/flake.lock index d56191b..db027c1 100644 --- a/flake.lock +++ b/flake.lock @@ -92,7 +92,9 @@ "inputs": { "flake-compat": "flake-compat", "neovim-flake": "neovim-flake", - "nixpkgs": "nixpkgs_2" + "nixpkgs": [ + "unstable" + ] }, "locked": { "lastModified": 1640420040, @@ -125,22 +127,6 @@ } }, "nixpkgs_2": { - "locked": { - "lastModified": 1640319671, - "narHash": "sha256-ZkKmakwaOaLiZOpIZWbeJZwap5CzJ30s4UJTfydYIYc=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "eac07edbd20ed4908b98790ba299250b5527ecdf", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_3": { "locked": { "lastModified": 1640350772, "narHash": "sha256-8Ug1fj5CLjyECT1Jw1VjeJ7+dmgO5grsXoXre3PywO4=", @@ -156,29 +142,13 @@ "type": "github" } }, - "nixpkgs_4": { - "locked": { - "lastModified": 1638097282, - "narHash": "sha256-EXCzj9b8X/lqDPJapxZThIOKL5ASbpsJZ+8L1LnY1ig=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "78cb77b29d37a9663e05b61abb4fa09465da4b70", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, "nur": { "locked": { - "lastModified": 1640428145, - "narHash": "sha256-GTzu4NxMGiBrfPE6uWycHojqCUmhCWwOrdS0Y0/JU60=", + "lastModified": 1640463732, + "narHash": "sha256-9xakgOvzBvR/e9MX6LJJg5D35RjvWCY6E41k6yUo/Lg=", "owner": "nix-community", "repo": "NUR", - "rev": "a3425a69ea42ce9360d728246f298ddb905f342c", + "rev": "767df3ef1bb4e2820c2bf8eca1ab89b69d754549", "type": "github" }, "original": { @@ -191,7 +161,7 @@ "home-manager": "home-manager", "homepage": "homepage", "neovim-nightly-overlay": "neovim-nightly-overlay", - "nixpkgs": "nixpkgs_3", + "nixpkgs": "nixpkgs_2", "nur": "nur", "sops-nix": "sops-nix", "unstable": "unstable" @@ -199,7 +169,9 @@ }, "sops-nix": { "inputs": { - "nixpkgs": "nixpkgs_4" + "nixpkgs": [ + "nixpkgs" + ] }, "locked": { "lastModified": 1638821683, diff --git a/flake.nix b/flake.nix index ab63e41..c6c4899 100644 --- a/flake.nix +++ b/flake.nix @@ -10,6 +10,7 @@ neovim-nightly-overlay = { url = "github:nix-community/neovim-nightly-overlay"; + inputs.nixpkgs.follows = "unstable"; }; homepage = { url = "github:JulienMalka/homepage"; @@ -22,6 +23,7 @@ sops-nix = { url = "github:Mic92/sops-nix"; + inputs.nixpkgs.follows = "nixpkgs"; }; }; From a42a771ece52e0ef92b749688efab89fa608aa56 Mon Sep 17 00:00:00 2001 From: Julien Malka <julien.malka@me.com> Date: Sun, 26 Dec 2021 00:21:23 +0100 Subject: [PATCH 2/8] 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 = ''''; From d63f558eb57384fbf7ca41c5653c9c5d1ed1e430 Mon Sep 17 00:00:00 2001 From: Julien Malka <julien.malka@me.com> Date: Sun, 26 Dec 2021 02:45:49 +0100 Subject: [PATCH 3/8] Status working now --- modules/homepage/default.nix | 1 - modules/status/checks.csv | 14 ++++++++++---- modules/status/default.nix | 13 ++++++++----- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/modules/homepage/default.nix b/modules/homepage/default.nix index 208368d..8b0c1e6 100644 --- a/modules/homepage/default.nix +++ b/modules/homepage/default.nix @@ -15,7 +15,6 @@ in enableACME = true; forceSSL = true; root = inputs.homepage; - default = true; }; services.nginx.virtualHosts."www.julienmalka.me" = { diff --git a/modules/status/checks.csv b/modules/status/checks.csv index 9ee2e4f..159ea2f 100644 --- a/modules/status/checks.csv +++ b/modules/status/checks.csv @@ -1,4 +1,10 @@ -http, 200, Homepage, https://julienmalka.me -http, 200, CI, https://ci.julienmalka.me -ping, 0, Newton, newton.julienmalka.me - +http, 200, Lisa, https://google.com +http, 200, Homepage, https://julienmalka.me +http, 200, CI, https://ci.julienmalka.me +http, 200, Jellyfin, https://tv.julienmalka.me +http, 200, Transmission, https://downloads.julienmalka.me +http, 200, Sonarr, https://series.julienmalka.me +http, 200, Radarr, https://films.julienmalka.me +http, 200, Jackett, https://jackett.julienmalka.me/UI/Dashboard +ping, 0, Newton, newton.julienmalka.me +http, 200, Cloud, cloud.julienmalka.me diff --git a/modules/status/default.nix b/modules/status/default.nix index 9989f2a..10e0664 100644 --- a/modules/status/default.nix +++ b/modules/status/default.nix @@ -5,7 +5,7 @@ let in { - options.luj.jackett = { + options.luj.status = { enable = mkEnableOption "activate status page"; nginx.enable = mkEnableOption "activate nginx"; nginx.subdomain = mkOption { @@ -16,16 +16,19 @@ in config = mkIf cfg.enable ( mkMerge [{ systemd = { - timers.simple-timer = { + timers.tinystatus = { wantedBy = [ "timers.target" ]; partOf = [ "tinystatus.service" ]; - timerConfig.OnCalendar = "minutely"; + timerConfig.OnCalendar = "*-*-* *:05,15,25,35,45,55:00"; + timerConfig.Unit = "tinystatus.service"; }; services.tinystatus = { serviceConfig.Type = "oneshot"; + path = [ pkgs.gawk pkgs.gnused pkgs.curl pkgs.netcat pkgs.unixtools.ping ]; script = '' - mkdir -p /var/www/status - ${pkgs.tinystatus}/bin/tinystatus ${./checks.csv} > /var/www/status/index.html + mkdir -p /var/www/status + ${pkgs.tinystatus}/bin/tinystatus ${./checks.csv} > /var/www/status/index.html + ${pkgs.gnused}/bin/sed -i 's/tinystatus/Services status/g' /var/www/status/index.html ''; }; }; From b3450bde4f0ddeb3749c7e00717e64c184de184f Mon Sep 17 00:00:00 2001 From: Julien Malka <julien.malka@me.com> Date: Sun, 26 Dec 2021 13:16:06 +0100 Subject: [PATCH 4/8] Fixed a few things on the status page --- modules/status/checks.csv | 2 +- modules/status/default.nix | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/status/checks.csv b/modules/status/checks.csv index 159ea2f..46beb17 100644 --- a/modules/status/checks.csv +++ b/modules/status/checks.csv @@ -6,5 +6,5 @@ http, 200, Transmission, https://downloads.julienmalka.me http, 200, Sonarr, https://series.julienmalka.me http, 200, Radarr, https://films.julienmalka.me http, 200, Jackett, https://jackett.julienmalka.me/UI/Dashboard -ping, 0, Newton, newton.julienmalka.me +port, 0, Newton, newton.julienmalka.me 45 http, 200, Cloud, cloud.julienmalka.me diff --git a/modules/status/default.nix b/modules/status/default.nix index 10e0664..b6f2f4b 100644 --- a/modules/status/default.nix +++ b/modules/status/default.nix @@ -29,6 +29,7 @@ in mkdir -p /var/www/status ${pkgs.tinystatus}/bin/tinystatus ${./checks.csv} > /var/www/status/index.html ${pkgs.gnused}/bin/sed -i 's/tinystatus/Services status/g' /var/www/status/index.html + ${pkgs.gnused}/bin/sed -i 's/80%/60%/g' /var/www/status/index.html ''; }; }; From d076710b90d9e14dba24036580f498fe63f9d737 Mon Sep 17 00:00:00 2001 From: Julien Malka <julien.malka@me.com> Date: Sun, 26 Dec 2021 13:24:36 +0100 Subject: [PATCH 5/8] Actually every 5 minutes --- modules/status/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/status/default.nix b/modules/status/default.nix index b6f2f4b..0e59660 100644 --- a/modules/status/default.nix +++ b/modules/status/default.nix @@ -19,7 +19,7 @@ in timers.tinystatus = { wantedBy = [ "timers.target" ]; partOf = [ "tinystatus.service" ]; - timerConfig.OnCalendar = "*-*-* *:05,15,25,35,45,55:00"; + timerConfig.OnCalendar = "*-*-* *:05,10,15,20,25,30,35,40,45,50,55:00"; timerConfig.Unit = "tinystatus.service"; }; services.tinystatus = { From 417cebf2102c2c523f78cde3d6a4546ba6863357 Mon Sep 17 00:00:00 2001 From: Julien Malka <julien.malka@me.com> Date: Sun, 26 Dec 2021 15:52:13 +0100 Subject: [PATCH 6/8] Closed some ports --- machines/lisa/default.nix | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/machines/lisa/default.nix b/machines/lisa/default.nix index ea20383..7c9842b 100644 --- a/machines/lisa/default.nix +++ b/machines/lisa/default.nix @@ -34,16 +34,14 @@ }; }; - nix.maxJobs = lib.mkDefault 8; + nix.maxJobs = lib.mkDefault 4; - networking.hostName = "lisa"; # Define your hostname. + networking.hostName = "lisa"; networking.interfaces.ens18.useDHCP = true; networking.interfaces.ens19.useDHCP = false; networking.interfaces.ens19.ipv6.addresses = [{ address = "2a01:e0a:5f9:9681:5880:c9ff:fe9f:3dfb"; prefixLength = 120; }]; - networking.firewall.allowedTCPPorts = [ 80 443 8096 8920 ]; - networking.firewall.allowedUDPPorts = [ 80 443 1900 7359 ]; - system.stateVersion = "20.09"; # Did you read the comment? + system.stateVersion = "20.09"; } From bfe9c8d31dd867bf1ec93665cfcecb7bf151446f Mon Sep 17 00:00:00 2001 From: Julien Malka <julien.malka@me.com> Date: Sun, 26 Dec 2021 15:58:55 +0100 Subject: [PATCH 7/8] Still giving back a few ports to nginx --- modules/nginx/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/nginx/default.nix b/modules/nginx/default.nix index e331329..5ff07ac 100644 --- a/modules/nginx/default.nix +++ b/modules/nginx/default.nix @@ -13,6 +13,7 @@ in { config = mkIf cfg.enable { + networking.firewall.allowedTCPPorts = [ 80 443 ]; security.acme.email = "${cfg.email}"; security.acme.acceptTerms = true; users.groups.nginx = { name = "nginx"; }; From ac63e3a7904f590ddbe527c4a9da25da0a0e45fb Mon Sep 17 00:00:00 2001 From: Julien Malka <julien.malka@me.com> Date: Sun, 26 Dec 2021 16:01:23 +0100 Subject: [PATCH 8/8] Few improvments --- machines/macintosh/default.nix | 2 +- machines/newton/default.nix | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/machines/macintosh/default.nix b/machines/macintosh/default.nix index 50b7ac6..7134478 100644 --- a/machines/macintosh/default.nix +++ b/machines/macintosh/default.nix @@ -10,7 +10,7 @@ ]; - networking.hostName = "macintosh"; # Define your hostname. + networking.hostName = "macintosh"; networking.networkmanager.enable = true; networking.firewall.enable = true; diff --git a/machines/newton/default.nix b/machines/newton/default.nix index 82a9c36..a0d114a 100644 --- a/machines/newton/default.nix +++ b/machines/newton/default.nix @@ -18,18 +18,15 @@ in programs.gnupg.agent.enable = true; - networking.hostName = hostName; # Define your hostname. + networking.hostName = hostName; networking.hostId = "f7cdfbc9"; networking.interfaces.enp2s0f0.useDHCP = true; networking.interfaces.enp2s0f1.useDHCP = true; networking.firewall.enable = true; - networking.firewall.allowedTCPPorts = [ 80 443 ]; - networking.firewall.allowedUDPPorts = [ 80 443 ]; - services.zfs.autoSnapshot.enable = true; services.zfs.autoScrub.enable = true; - system.stateVersion = "21.05"; # Did you read the comment? + system.stateVersion = "21.05"; }