mews.page/flake.nix

129 lines
4 KiB
Nix

{
description = "Mews Profile: page validator, site directory and the mews.page site";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
pyproject-nix = {
url = "github:pyproject-nix/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
uv2nix = {
url = "github:pyproject-nix/uv2nix";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
pyproject-build-systems = {
url = "github:pyproject-nix/build-system-pkgs";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.uv2nix.follows = "uv2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
nixpkgs,
pyproject-nix,
uv2nix,
pyproject-build-systems,
...
}:
let
inherit (nixpkgs) lib;
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
# Wheels, not sources: the service is built on the machine it runs on,
# which has one CPU, and lxml from source there takes minutes.
overlay = workspace.mkPyprojectOverlay {
sourcePreference = "wheel";
};
editableOverlay = workspace.mkEditablePyprojectOverlay {
root = "$REPO_ROOT";
};
pythonSets = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
(pkgs.callPackage pyproject-nix.build.packages {
python = pkgs.python312;
}).overrideScope
(
lib.composeManyExtensions [
pyproject-build-systems.overlays.wheel
overlay
]
)
);
specDescription = "The Mews Profile specification, version 0.1.";
in
{
devShells = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
pythonSet = pythonSets.${system}.overrideScope editableOverlay;
virtualenv = pythonSet.mkVirtualEnv "mews-dev-env" workspace.deps.all;
in
{
default = pkgs.mkShell {
packages = [
virtualenv
pkgs.uv
# md2mews.py is a standalone script with its own dependency
# header, so it is not part of the workspace environment.
(pkgs.python3.withPackages (ps: [ ps.mistune ]))
];
env = {
UV_NO_SYNC = "1";
UV_PYTHON = pythonSet.python.interpreter;
UV_PYTHON_DOWNLOADS = "never";
};
shellHook = ''
unset PYTHONPATH
export REPO_ROOT=$(git rev-parse --show-toplevel)
'';
};
}
);
packages = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
app = pythonSets.${system}.mkVirtualEnv "mews-env" workspace.deps.default;
converter = pkgs.python3.withPackages (ps: [ ps.mistune ]);
in
{
default = app;
# The published site. Every page it assembles is validated here, so a
# page that does not follow the spec cannot reach the server.
site = pkgs.runCommand "mews-site" { } ''
mkdir -p $out/spec $out/dtd
cp ${./site}/index.html ${./site}/about.html ${./site}/check.html $out/
cp ${./mews-0.1.css} $out/mews-0.1.css
cp ${./mews-0.1.css} $out/spec/mews-0.1.css
cp ${./dtd/mews-0.1.dtd} $out/dtd/mews-0.1.dtd
cp ${./dtd/xhtml-mobile12.dtd} $out/dtd/xhtml-mobile12.dtd
chmod -R u+w $out
${converter}/bin/python ${./md2mews.py} ${./doc/SPEC.md} \
-o $out/spec/0.1.html --lang en --variant mews-cool \
--description ${lib.escapeShellArg specDescription}
${app}/bin/mewslint --quiet \
$out/index.html $out/about.html $out/check.html $out/spec/0.1.html
'';
}
);
};
}