diff --git a/flake.nix b/flake.nix index f8caa83..2d7f0f9 100644 --- a/flake.nix +++ b/flake.nix @@ -7,6 +7,13 @@ outputs = { self, nixpkgs }: nixpkgs.lib.foldAttrs (item: acc: item // acc) { } (map (system: with nixpkgs.legacyPackages."${system}"; { + devShells."${system}".default = mkShell { + nativeBuildInputs = [ + nodejs_20 + tmux + ]; + }; + packages."${system}".default = buildNpmPackage { pname = "todo-list"; version = "1.0.0"; @@ -18,11 +25,53 @@ ''; }; - devShells."${system}".default = mkShell { - nativeBuildInputs = [ - nodejs_20 - tmux - ]; - }; + nixosModules.default = { config, lib, ... }: + let + inherit (lib) mkEnableOption mkIf mkOption mkMerge types recursiveUpdate mkForce; + cfg = config.services.todo-list; + in + { + options.services.todo-list = { + enable = mkEnableOption "Todo list"; + + hostname = mkOption { + type = types.str; + example = "todo.example.com"; + description = "The hostname to serve site on."; + }; + + nginx = mkOption { + type = types.submodule ( + recursiveUpdate + (import (nixpkgs + "/nixos/modules/services/web-servers/nginx/vhost-options.nix") { inherit config lib; }) + { } + ); + default = { }; + example = '' + { + serverAliases = [ + "list.''${config.networking.domain}" + ]; + # To enable encryption and let let's encrypt take care of certificate + forceSSL = true; + enableACME = true; + } + ''; + description = '' + With this option, you can customize the nginx virtualHost settings. + ''; + }; + }; + + config = mkIf cfg.enable { + services.nginx.virtualHosts.${cfg.hostname} = mkMerge [ + cfg.nginx + { + root = mkForce self.packages."${system}".default; + locations."/".tryFiles = "$uri $uri/ /index.html"; + } + ]; + }; + }; }) [ "x86_64-linux" "aarch64-linux" ]); }