{ description = "A webserver to create files for testing purposes"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; microvm = { url = "github:astro/microvm.nix"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { self, nixpkgs, ... }@inputs: let supportedSystems = [ "x86_64-linux" ]; forAllSystems = nixpkgs.lib.genAttrs supportedSystems; pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system}); in { # `nix build` packages = forAllSystems (system: rec { default = testdata; testdata = pkgs.${system}.callPackage ./nix/package.nix { src = ./.; }; vm = self.nixosConfigurations.vm.config.microvm.declaredRunner; }); # `nix develop` 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 ''; }; }); # NixOS Module nixosModules.default = import ./nix/module.nix inputs; # NixOS definition for a microvm to test nixosModules nixosConfigurations."vm" = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ inputs.microvm.nixosModules.microvm ( { config, ... }: { services.getty.autologinUser = "root"; microvm = { hypervisor = "qemu"; shares = [ { # Host's /nix/store will be picked up so that no squashfs/erofs will be built for it. tag = "ro-store"; source = "/nix/store"; mountPoint = "/nix/.ro-store"; } ]; interfaces = [ { type = "user"; id = "qemu"; # Locally administered have one of 2/6/A/E in the second nibble. mac = "02:00:00:01:01:01"; } ]; forwardPorts = [ { host.port = config.services.testdata.port; guest.port = config.services.testdata.port; } ]; }; } ) self.nixosModules.default rec { networking.firewall.allowedTCPPorts = [ services.testdata.port ]; services.testdata = { enable = true; host = "0.0.0.0"; port = 1234; settings = { 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"; }; }; } ]; }; }; }