2024-04-10 16:26:38 +00:00
|
|
|
{
|
2025-01-02 17:18:57 +00:00
|
|
|
description = "A webserver to create files for testing purposes";
|
2024-04-10 16:26:38 +00:00
|
|
|
|
|
|
|
inputs = {
|
2025-01-04 00:05:40 +00:00
|
|
|
nixpkgs.url = "github:nixos/nixpkgs?rev=a73246e2eef4c6ed172979932bc80e1404ba2d56";
|
2025-01-02 17:18:57 +00:00
|
|
|
|
2024-04-11 19:11:05 +00:00
|
|
|
microvm = {
|
|
|
|
url = "github:astro/microvm.nix";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2024-04-10 16:26:38 +00:00
|
|
|
};
|
|
|
|
|
2025-01-02 17:18:57 +00:00
|
|
|
outputs = {
|
|
|
|
self,
|
|
|
|
nixpkgs,
|
|
|
|
...
|
|
|
|
} @ inputs: let
|
2024-04-10 16:26:38 +00:00
|
|
|
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
|
2025-01-02 17:18:57 +00:00
|
|
|
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
|
|
|
pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system}.extend overlay);
|
|
|
|
|
|
|
|
overlay = final: prev: rec {
|
|
|
|
python3Packages = prev.python3Packages.overrideScope (pfinal: pprev: {
|
|
|
|
packageNameToDrv = x: builtins.getAttr (cleanPythonPackageName x) final.python3Packages;
|
|
|
|
});
|
|
|
|
|
|
|
|
cleanPythonPackageName = x: let
|
|
|
|
cleanName = builtins.match "([a-z,A-Z,0-9,_,-]+).*" x;
|
|
|
|
in
|
|
|
|
if cleanName != null
|
|
|
|
then builtins.elemAt cleanName 0
|
|
|
|
else builtins.warn "Could not determine package name from '${x}'" null;
|
|
|
|
};
|
|
|
|
|
|
|
|
pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml);
|
|
|
|
|
|
|
|
buildDependencies = forAllSystems (system: builtins.map pkgs.${system}.python3Packages.packageNameToDrv pyproject.build-system.requires);
|
|
|
|
runtimeDependencies = forAllSystems (system: builtins.map pkgs.${system}.python3Packages.packageNameToDrv pyproject.project.dependencies);
|
|
|
|
optionalDependencies = forAllSystems (system: builtins.mapAttrs (name: value: builtins.map pkgs.${system}.python3Packages.packageNameToDrv value) pyproject.project.optional-dependencies);
|
2024-04-10 16:26:38 +00:00
|
|
|
in {
|
|
|
|
# `nix build`
|
2025-01-02 17:18:57 +00:00
|
|
|
packages = forAllSystems (system: let
|
|
|
|
buildTestdata = {skipCheck ? false}:
|
|
|
|
pkgs.${system}.python3Packages.buildPythonPackage {
|
|
|
|
pname = pyproject.project.name;
|
|
|
|
version = pyproject.project.version;
|
|
|
|
src = ./.;
|
2024-04-11 19:11:05 +00:00
|
|
|
|
2025-01-02 17:18:57 +00:00
|
|
|
pyproject = true;
|
|
|
|
|
|
|
|
build-system = buildDependencies.${system};
|
|
|
|
|
|
|
|
dependencies = runtimeDependencies.${system};
|
|
|
|
|
|
|
|
optional-dependencies = optionalDependencies.${system};
|
|
|
|
|
|
|
|
nativeCheckInputs = optionalDependencies.${system}.dev;
|
|
|
|
|
|
|
|
checkPhase = let
|
|
|
|
dev = builtins.map (x: x.pname) optionalDependencies.${system}.dev;
|
|
|
|
in ''
|
|
|
|
${
|
|
|
|
if builtins.elem "pytest" dev && !skipCheck
|
|
|
|
then "pytest src tests"
|
|
|
|
else ""
|
|
|
|
}
|
|
|
|
${
|
|
|
|
if builtins.elem "mypy" dev && !skipCheck
|
|
|
|
then "mypy src tests"
|
|
|
|
else ""
|
|
|
|
}
|
|
|
|
${
|
|
|
|
if builtins.elem "pylint" dev && !skipCheck
|
|
|
|
then "pylint src tests"
|
|
|
|
else ""
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in rec {
|
|
|
|
default = testdata;
|
|
|
|
testdata = buildTestdata {skipCheck = false;};
|
|
|
|
quick = buildTestdata {skipCheck = true;};
|
|
|
|
vm = self.nixosConfigurations.vm.config.microvm.declaredRunner;
|
2024-04-10 16:26:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
# `nix fmt`
|
|
|
|
formatter = forAllSystems (system: pkgs.${system}.alejandra);
|
|
|
|
|
|
|
|
# `nix develop`
|
2025-01-02 17:18:57 +00:00
|
|
|
devShells = forAllSystems (system: rec {
|
|
|
|
default = venv;
|
|
|
|
|
|
|
|
venv = pkgs.${system}.mkShell {
|
|
|
|
shellHook = ''
|
|
|
|
if [ ! -d .venv/ ]; then
|
|
|
|
echo "Creating Virtual Environment..."
|
|
|
|
${pkgs.${system}.python3}/bin/python3 -m venv .venv
|
|
|
|
fi
|
|
|
|
|
|
|
|
alias activate='source .venv/bin/activate'
|
|
|
|
|
|
|
|
echo "Entering Virtual Environment..."
|
|
|
|
source .venv/bin/activate
|
|
|
|
'';
|
|
|
|
};
|
2024-04-10 16:26:38 +00:00
|
|
|
});
|
2024-04-11 19:11:05 +00:00
|
|
|
|
|
|
|
# NixOS Module
|
|
|
|
nixosModules.default = import ./nix/module.nix inputs;
|
2025-01-02 17:18:57 +00:00
|
|
|
|
|
|
|
# nixos definition for a microvm to test nixosModules
|
|
|
|
nixosConfigurations = let
|
|
|
|
system = "x86_64-linux";
|
|
|
|
in {
|
|
|
|
vm = nixpkgs.lib.nixosSystem {
|
|
|
|
inherit system;
|
|
|
|
|
|
|
|
modules = [
|
|
|
|
inputs.microvm.nixosModules.microvm
|
|
|
|
({config, ...}: {
|
|
|
|
system.stateVersion = config.system.nixos.version;
|
|
|
|
|
|
|
|
networking.hostName = "vm";
|
|
|
|
users.users.root.password = "";
|
|
|
|
|
|
|
|
microvm = {
|
|
|
|
# volumes = [
|
|
|
|
# {
|
|
|
|
# mountPoint = "/var";
|
|
|
|
# image = "var.img";
|
|
|
|
# size = 256;
|
|
|
|
# }
|
|
|
|
# ];
|
|
|
|
shares = [
|
|
|
|
{
|
|
|
|
# use proto = "virtiofs" for MicroVMs that are started by systemd
|
|
|
|
proto = "9p";
|
|
|
|
tag = "ro-store";
|
|
|
|
# a host's /nix/store will be picked up so that no
|
|
|
|
# squashfs/erofs will be built for it.
|
|
|
|
source = "/nix/store";
|
|
|
|
mountPoint = "/nix/.ro-store";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
interfaces = [
|
|
|
|
{
|
|
|
|
type = "user";
|
|
|
|
id = "qemu";
|
|
|
|
mac = "02:00:00:01:01:01";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
forwardPorts = [
|
|
|
|
{
|
|
|
|
host.port = config.services.testdata.port;
|
|
|
|
guest.port = config.services.testdata.port;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
# "qemu" has 9p built-in!
|
|
|
|
hypervisor = "qemu";
|
|
|
|
socket = "control.socket";
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
self.nixosModules.default
|
|
|
|
rec {
|
|
|
|
networking.firewall.allowedTCPPorts = [services.testdata.port];
|
|
|
|
services.testdata = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
host = "0.0.0.0";
|
|
|
|
port = 1234;
|
|
|
|
|
|
|
|
settings = {
|
2025-01-03 23:47:21 +00:00
|
|
|
keys = ["one" "two" "three"];
|
|
|
|
max-size = "1GB";
|
|
|
|
max-data = "100GB";
|
|
|
|
buffer-size = "12MiB";
|
|
|
|
database = "/root/testdata_state.json";
|
|
|
|
database-update-interval = 5.0;
|
|
|
|
log = "/root/log.jsonl";
|
2025-01-02 17:18:57 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2024-04-10 16:26:38 +00:00
|
|
|
};
|
|
|
|
}
|