{ description = "A very basic flake"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs"; flake-utils = { url = "github:numtide/flake-utils"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; pythonPackages = pkgs.python310Packages; pythonDeps = with pythonPackages; [ gunicorn mypy flask pytest pylint black types-setuptools requests types-requests ]; in { packages.pronoun-o-matic = pythonPackages.buildPythonPackage { pname = "pronoun-o-matic"; version = "1.0"; propagatedBuildInputs = pythonDeps; src = ./.; }; devShell = pkgs.mkShell { buildInputs = [ pythonPackages.python ] ++ pythonDeps; }; defaultPackage = self.packages.${system}.pronoun-o-matic; }) // { nixosModule = { config, lib, pkgs, options, ... }: with lib; let system = pkgs.system; in let pkgs = nixpkgs.${system}; cfg = config.services.pronoun-o-matic; pronoun-o-matic = self.packages.${system}.pronoun-o-matic; python-pkgs = pronoun-o-matic.pythonModule.pkgs; python-path = python-pkgs.makePythonPath [ pronoun-o-matic ]; gunicorn = python-pkgs.gunicorn; in { options.services.pronoun-o-matic = { enable = mkEnableOption "Enables the pronoun-o-matic HTTP service"; workers = mkOption { type = types.int; default = 1; example = 4; description = '' The number of gunicorn worker processes for handling requests. ''; }; package = mkOption { type = types.package; description = "Package to use for the server."; default = pronoun-o-matic; }; bind = mkOption { type = types.str; description = "The address and port gunicorn should bind to"; default = "127.0.0.1:8080"; }; plugins = mkOption { type = types.listOf types.attrs; default = [{ name = "log"; }]; }; }; config = mkIf cfg.enable { systemd.services.pronoun-o-matic = { wantedBy = [ "multi-user.target" ]; environment = { PYTHONPATH = python-path; PRONOUNOMATIC_PLUGINS = builtins.toJSON cfg.plugins; }; serviceConfig = { ExecStart = '' ${gunicorn}/bin/gunicorn pronounomatic.core.app:app \ --name pronoun-o-matic \ --workers ${toString cfg.workers} \ --bind ${cfg.bind} ''; Restart = "on-failure"; }; }; }; }; }; }