{ description = "Reproducible Environment for anish.lakhwara.com"; inputs = { nixpkgs.url = "github:nixos/nixpkgs"; flake-utils.url = "github:numtide/flake-utils"; poonam.url = "git+ssh://gitea@git.sealight.xyz/aynish/kitaab?ref=main"; poonam.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, nixpkgs, flake-utils, poonam }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; finalPython = pkgs.python3.override { packageOverrides = poonam.overlays.default; self = finalPython; }; python-with-my-packages = finalPython.withPackages (p: with p; [ jinja2 click pytest poonam python-ctags3 # other python packages you want in the devShell ]); in { devShell = pkgs.mkShell { buildInputs = [ python-with-my-packages pkgs.pandoc self.packages.x86_64-linux.basant poonam.packages.${system}.poonam ]; shellHook = '' # PYTHONPATH=${python-with-my-packages}/${python-with-my-packages.sitePackages} # maybe set more env-vars ''; }; packages.basant = with finalPython.pkgs; buildPythonApplication { pname = "basant"; src = ./.; version = "0.3"; propagatedBuildInputs = [ poonam.packages.${system}.poonam jinja2 python-ctags3 ]; passthru = { python = finalPython; # for running? }; doCheck = false; }; packages.site = pkgs.stdenv.mkDerivation { name = "anish-lakhwara-site"; src = ./.; buildInputs = [ poonam.defaultPackage.${system} self.packages.${system}.basant ]; configurePhase = '' cp -r ${poonam.defaultPackage.${system}}/public/ ./ cp -r ${poonam.defaultPackage.${system}}/media/ ./ ''; buildPhase = '' ${self.packages.${system}.basant}/bin/main.py ''; installPhase = '' mkdir -p $out cp -R output/* $out/ ''; }; defaultPackage = self.packages.${system}.site; }) // { # also need a module that refreshes this flake.lock, but maybe that shouldn't live here? nixosModule = { options, lib, config, pkgs, ... }: let serverName = "anish.lakhwara.com"; webRoot = "/var/www/"; serviceConfig = config.services."${serverName}"; options = { enable = lib.mkEnableOption "${serverName} service"; enableSSL = lib.mkEnableOption "${serverName} SSL for Nginx"; }; in { options.services.${serverName} = options; config = lib.mkIf serviceConfig.enable { systemd.services."source-${serverName}" = { description = '' https://${serverName} source ''; wantedBy = [ "multi-user.target" ]; serviceConfig = { Type = "oneshot"; }; startAt = "*00:00:00"; path = with pkgs; [ nix ] ++ [ self.packages.${system}.site ]; script = '' set -ex mkdir -p ${webRoot} ln -sfT ${self.packages.${pkgs.system}.site} ${webRoot}${serverName} ''; }; # Allow nginx through the firewall networking.firewall.allowedTCPPorts = [ 80 ]; services.nginx.enable = true; services.nginx.virtualHosts.${serverName} = { forceSSL = serviceConfig.enableSSL; enableACME = serviceConfig.enableSSL; locations."/" = { root = "${webRoot}${serverName}"; index = "/home.html"; }; }; }; }; # Test container nixosConfigurations."test" = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ self.nixosModule ({ pkgs, ... }: { # Only allow this to boot as a container boot.isContainer = true; networking.hostName = "basant"; services."anish.lakhwara.com".enable = true; }) ]; }; }; }