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.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..7029f26 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"; }; }; @@ -29,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; { @@ -40,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..7c9842b 100644 --- a/machines/lisa/default.nix +++ b/machines/lisa/default.nix @@ -25,18 +25,23 @@ subdomain = "ci"; }; }; + status = { + enable = true; + nginx = { + enable = true; + subdomain = "status"; + }; + }; }; - 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"; } 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"; } 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/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"; }; diff --git a/modules/status/checks.csv b/modules/status/checks.csv new file mode 100644 index 0000000..46beb17 --- /dev/null +++ b/modules/status/checks.csv @@ -0,0 +1,10 @@ +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 +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 new file mode 100644 index 0000000..0e59660 --- /dev/null +++ b/modules/status/default.nix @@ -0,0 +1,52 @@ +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.luj.status; +in +{ + + options.luj.status = { + enable = mkEnableOption "activate status page"; + nginx.enable = mkEnableOption "activate nginx"; + nginx.subdomain = mkOption { + type = types.str; + }; + }; + + config = mkIf cfg.enable ( + mkMerge [{ + systemd = { + timers.tinystatus = { + wantedBy = [ "timers.target" ]; + partOf = [ "tinystatus.service" ]; + timerConfig.OnCalendar = "*-*-* *:05,10,15,20,25,30,35,40,45,50,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 + ${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 + ''; + }; + }; + } + + + (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 = '''';