basant/flake.nix

124 lines
4.3 KiB
Nix
Raw Normal View History

2021-11-29 04:26:21 -08:00
{
description = "Reproducible Environment for anish.lakhwara.com";
2021-11-29 04:26:21 -08:00
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";
2021-11-29 04:26:21 -08:00
};
outputs = { self, nixpkgs, flake-utils, poonam }:
2022-04-16 01:13:02 -07:00
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
2023-04-22 22:10:36 -07:00
finalPython = pkgs.python3.override { packageOverrides = poonam.overlays.default; self = finalPython; };
python-with-my-packages = finalPython.withPackages (p: with p; [
2022-04-16 01:13:02 -07:00
jinja2
click
2023-04-02 06:55:39 -07:00
pytest
poonam
python-ctags3
2022-04-16 01:13:02 -07:00
# other python packages you want in the devShell
]);
in
{
devShell = pkgs.mkShell {
buildInputs = [
python-with-my-packages
pkgs.pandoc
2022-07-10 21:13:59 -07:00
self.packages.x86_64-linux.basant
poonam.packages.${system}.poonam
2022-04-16 01:13:02 -07:00
];
shellHook = ''
2022-07-10 21:13:59 -07:00
# PYTHONPATH=${python-with-my-packages}/${python-with-my-packages.sitePackages}
2022-04-16 01:13:02 -07:00
# maybe set more env-vars
'';
};
2023-04-22 22:10:36 -07:00
packages.basant = with finalPython.pkgs; buildPythonApplication {
2022-04-16 01:13:02 -07:00
pname = "basant";
src = ./.;
2023-04-22 21:40:17 -07:00
version = "0.3";
2023-04-22 22:10:36 -07:00
propagatedBuildInputs = [ poonam.packages.${system}.poonam jinja2 python-ctags3 ];
passthru = {
python = finalPython; # for running?
};
2022-04-16 01:13:02 -07:00
doCheck = false;
};
packages.site = pkgs.stdenv.mkDerivation {
name = "anish-lakhwara-site";
src = ./.;
buildInputs = [ poonam.defaultPackage.${system} self.packages.${system}.basant ];
configurePhase = ''
2022-07-10 21:13:59 -07:00
cp -r ${poonam.defaultPackage.${system}}/public/ ./
cp -r ${poonam.defaultPackage.${system}}/media/ ./
2022-07-10 21:13:59 -07:00
'';
2022-04-16 01:13:02 -07:00
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/";
2022-04-11 02:57:04 -07:00
serviceConfig = config.services."${serverName}";
options = {
enable = lib.mkEnableOption "${serverName} service";
2022-09-20 02:21:22 -07:00
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";
2022-04-16 01:13:02 -07:00
};
startAt = "*00:00:00";
path = with pkgs; [ nix ] ++ [ self.packages.${system}.site ];
script = ''
set -ex
2022-04-15 19:27:47 -07:00
mkdir -p ${webRoot}
ln -sfT ${self.packages.${pkgs.system}.site} ${webRoot}${serverName}
'';
2022-04-15 19:27:47 -07:00
};
# Allow nginx through the firewall
networking.firewall.allowedTCPPorts = [ 80 ];
services.nginx.enable = true;
services.nginx.virtualHosts.${serverName} = {
2022-09-20 02:21:22 -07:00
forceSSL = serviceConfig.enableSSL;
enableACME = serviceConfig.enableSSL;
locations."/" = { root = "${webRoot}${serverName}"; index = "/home.html"; };
};
};
};
2022-04-16 01:13:02 -07:00
# 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;
})
];
};
};
2021-11-29 04:26:21 -08:00
}