basant/flake.nix

125 lines
4.4 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";
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};
my-python = pkgs.python3;
python-with-my-packages = my-python.withPackages (p: with p; [
jinja2
click
# other python packages you want in the devShell
]);
python-deps = with pkgs.python3Packages; [
# Packages necessary at runtime to run build script
jinja2
python-ctags3
];
2022-04-16 01:13:02 -07:00
in
{
devShell = pkgs.mkShell {
buildInputs = [
python-with-my-packages
pkgs.pandoc
];
shellHook = ''
PYTHONPATH=${python-with-my-packages}/${python-with-my-packages.sitePackages}
# This only works when you have ~/vimwiki locally, since I'm not putting my unfiltered kitaab online
alias build='python3 src/kitaab-public/main.py'
# maybe set more env-vars
'';
};
packages.basant = pkgs.python3Packages.buildPythonPackage {
pname = "basant";
src = ./.;
version = "0.1";
propagatedBuildInputs = [ python-deps ];
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/ ./
'';
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;
2022-04-11 02:57:04 -07:00
2022-04-16 01:13:02 -07:00
# 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/${serverName}";
2022-04-15 19:27:47 -07:00
2022-04-16 01:13:02 -07:00
serviceConfig = config.services."${serverName}";
options = {
enable = lib.mkEnableOption "${serverName} service";
};
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";
DynamicUser = "yes";
};
startAt = "*00:00:00";
path = with pkgs; [ nix gnutar gzip curl jq ] ++ [ self.packages.${system}.site ];
script = ''
set -ex
2022-04-15 19:27:47 -07:00
2022-04-16 01:13:02 -07:00
ln -sfT ${self.packages.${system}.site} ${webRoot}
'';
};
# Allow nginx through the firewall
networking.firewall.allowedTCPPorts = [ 80 ];
services.nginx.enable = true;
services.nginx.virtualHosts.${serverName} = {
forceSSL = true;
enableACME = true;
locations."/" = { root = "${webRoot}"; };
2022-04-15 19:27:47 -07:00
};
};
};
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";
# Allow nginx through the firewall
networking.firewall.allowedTCPPorts = [ 80 ];
services.nginx.enable = true;
services."anish.lakhwara.com".enable = true;
})
];
};
};
2021-11-29 04:26:21 -08:00
}