Skip to content

Commit 23e5eeb

Browse files
committed
Initial commit
0 parents  commit 23e5eeb

File tree

6 files changed

+301
-0
lines changed

6 files changed

+301
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nixos.qcow2
2+
result
3+
result-*

flake.lock

Lines changed: 175 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
inputs = {
3+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
4+
disko.url = "github:nix-community/disko";
5+
disko.inputs.nixpkgs.follows = "nixpkgs";
6+
flake-parts.url = "github:hercules-ci/flake-parts";
7+
nspawn-nixos.url = "/home/tfc/src/nspawn-example";
8+
};
9+
10+
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } {
11+
systems = [ "x86_64-linux" "aarch64-linux" ];
12+
perSystem = { config, pkgs, system, ... }: {
13+
packages =
14+
let
15+
vmFromModules = modules: (inputs.nixpkgs.lib.nixosSystem {
16+
inherit modules system;
17+
}).config.system.build.vm;
18+
in {
19+
vm = vmFromModules [
20+
./qemu-vm.nix
21+
./nginx-php.nix
22+
];
23+
vm-containered = vmFromModules [
24+
./qemu-vm.nix
25+
({ ... }: { # NixOS config of within the VM
26+
containers.webserver = {
27+
autoStart = true;
28+
privateNetwork = false;
29+
config = { ... }: { # NixOS config of within the container
30+
imports = [ ./nginx-php.nix ];
31+
};
32+
};
33+
})
34+
];
35+
};
36+
};
37+
};
38+
}

nginx-php.nix

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{ config, lib, pkgs, ... }:
2+
3+
let
4+
wwwRoot = ./wwwroot;
5+
phpPkgNames = [ "php80" "php81" "php82" ];
6+
7+
phpPools =
8+
let
9+
f = phpPkgName: {
10+
name = phpPkgName;
11+
value = {
12+
user = "php";
13+
phpPackage = pkgs.${phpPkgName};
14+
settings = {
15+
"listen.owner" = config.services.nginx.user;
16+
"pm" = "dynamic";
17+
"pm.max_children" = 32;
18+
"pm.max_requests" = 500;
19+
"pm.start_servers" = 2;
20+
"pm.min_spare_servers" = 1;
21+
"pm.max_spare_servers" = 5;
22+
};
23+
};
24+
};
25+
in
26+
builtins.listToAttrs (map f phpPkgNames);
27+
28+
nginxLocations =
29+
let
30+
f = phpPkgName: {
31+
name = "/${phpPkgName}";
32+
value = {
33+
root = wwwRoot;
34+
extraConfig = ''
35+
rewrite ^/${phpPkgName}(.*)$ /$1 break;
36+
37+
include ${pkgs.nginx}/conf/fastcgi_params;
38+
include ${pkgs.nginx}/conf/fastcgi.conf;
39+
fastcgi_pass unix:${config.services.phpfpm.pools.${phpPkgName}.socket};
40+
fastcgi_index index.php;
41+
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
42+
fastcgi_param SCRIPT_FILENAME ${wwwRoot}$fastcgi_script_name;
43+
'';
44+
};
45+
};
46+
in
47+
builtins.listToAttrs (map f phpPkgNames);
48+
in
49+
{
50+
nixpkgs.config.permittedInsecurePackages = [
51+
"openssl-1.1.1v"
52+
];
53+
54+
services = {
55+
phpfpm.pools = phpPools;
56+
nginx = {
57+
enable = true;
58+
virtualHosts.localhost.locations = nginxLocations;
59+
};
60+
};
61+
users.users.php = {
62+
isSystemUser = true;
63+
group = "php";
64+
};
65+
users.groups.php = {};
66+
}

qemu-vm.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{ config, modulesPath, ... }:
2+
3+
{
4+
imports = [ (modulesPath + "/virtualisation/qemu-vm.nix") ];
5+
6+
virtualisation.forwardPorts = [
7+
{ from = "host"; host.port = 8080; guest.port = 80; }
8+
];
9+
10+
networking.firewall.enable = false;
11+
12+
users.users.root.initialPassword = "";
13+
}

wwwroot/index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
phpinfo();
4+
phpinfo(INFO_MODULES);
5+
6+
?>

0 commit comments

Comments
 (0)