Skip to content

Instantly share code, notes, and snippets.

@tfc
Last active September 23, 2025 08:04
Show Gist options
  • Save tfc/e4bd208e0cdda86c105f6e210f1371c7 to your computer and use it in GitHub Desktop.
Save tfc/e4bd208e0cdda86c105f6e210f1371c7 to your computer and use it in GitHub Desktop.
{ pkgs, ... }:
{
imports = [
./python-web-module.nix
];
nixpkgs.overlays = [
(import ./overlay.nix)
];
services.python-web = {
enable = true;
openFirewall = true;
pages = {
index = ''
Hello this is a cool project.
Look at our [docs](/documentation)
'';
documentation = ''
lolol didn't think someone would want to read the docs.
'';
};
footer = ''
[![Made with vim](https://www.vim.org/images/vim.vialle.love.anim.gif)](https://www.vim.org/buttons.php)
[![nixcademy](https://nixcademy.com/images/logo-landscape.svg)](https://nixcademy.com)
'';
};
}
{ modulesPath, ... }:
{
imports = [
(modulesPath + "/virtualisation/qemu-vm.nix")
];
users.users.root.initialPassword = "";
services.getty.autologinUser = "root";
system.name = "christian";
virtualisation.forwardPorts = [
{ from = "host"; host.port = 9000; guest.port = 9000; }
];
}
{ pkgs, lib, config, ... }:
let
cfg = config.services.python-web;
generatedConfig = pkgs.writers.writeTOML "python-web-config.toml" ({
server = {
inherit (cfg) port;
};
inherit (cfg) pages;
} // lib.optionalAttrs (cfg.footer != null) { inherit (cfg) footer; });
in
{
options.services.python-web = {
enable = lib.mkEnableOption "the awesome python-web service";
port = lib.mkOption {
type = lib.types.port;
default = 9000;
};
package = lib.mkPackageOption pkgs "python-web" { };
openFirewall = lib.mkEnableOption "open the firewall";
footer = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = "cool footer to embed in every page";
};
pages = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
default = {};
example = {
index = "indexlol with cool [link to docs](/docs)";
docs = "docslol";
};
description = "attribute set where keys are the URLs and values are the string content served over http in markdown form";
};
configFile = lib.mkOption {
type = lib.types.path;
default = generatedConfig;
};
user = lib.mkOption {
type = lib.types.str;
default = "python-web";
};
};
config = lib.mkIf cfg.enable {
users.users."${cfg.user}" = {
name = cfg.user;
group = cfg.user;
description = "python web user";
isSystemUser = true;
};
users.groups.${cfg.user} = {};
systemd.services.python-web = {
description = "super cool python-web femto nano micro whatever blog platform";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = cfg.user;
Group = cfg.user;
ExecStart = "${lib.getExe cfg.package} --config ${cfg.configFile}";
};
};
networking.firewall.allowedTCPPorts = lib.optional cfg.openFirewall cfg.port;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment