Add NixNG configuration

This commit is contained in:
Pim Kunis 2024-12-31 11:03:29 +01:00
parent 433c1ef4b5
commit 9e99ee2e47
2 changed files with 142 additions and 20 deletions

76
flake.lock generated
View file

@ -18,7 +18,61 @@
"type": "github"
}
},
"nginx": {
"flake": false,
"locked": {
"lastModified": 1735301654,
"narHash": "sha256-PHcSyHYyPUwPAls0BgtnGu2e936vhxW2nt7bQxDyGAQ=",
"owner": "nginx",
"repo": "nginx",
"rev": "e3a9b6ad08a86e799a3d77da3f2fc507d3c9699e",
"type": "github"
},
"original": {
"owner": "nginx",
"repo": "nginx",
"type": "github"
}
},
"nixng": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"treefmt-nix": "treefmt-nix"
},
"locked": {
"lastModified": 1735551011,
"narHash": "sha256-rp26PcdLjfgxsCeaSeZ0K1rGPN1Ap7YCy1UVuo9gRJA=",
"owner": "pizzapim",
"repo": "NixNG",
"rev": "aa35f7a3d426e906b15e3083c90bf2972bcfb4b4",
"type": "github"
},
"original": {
"owner": "pizzapim",
"ref": "kubernetes",
"repo": "NixNG",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1726871744,
"narHash": "sha256-V5LpfdHyQkUF7RfOaDPrZDP+oqz88lTJrMT1+stXNwo=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "a1d92660c6b3b7c26fb883500a80ea9d33321be2",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1714076141,
"narHash": "sha256-Drmja/f5MRHZCskS6mvzFqxEaZMeciScCTFxWVLqWEY=",
@ -37,7 +91,9 @@
"root": {
"inputs": {
"flutils": "flutils",
"nixpkgs": "nixpkgs"
"nginx": "nginx",
"nixng": "nixng",
"nixpkgs": "nixpkgs_2"
}
},
"systems": {
@ -54,6 +110,24 @@
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1727984844,
"narHash": "sha256-xpRqITAoD8rHlXQafYZOLvUXCF6cnZkPfoq67ThN0Hc=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "4446c7a6fc0775df028c5a3f6727945ba8400e64",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",

View file

@ -4,9 +4,19 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flutils.url = "github:numtide/flake-utils";
nixng = {
url = "github:pizzapim/NixNG/kubernetes";
inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, flutils}: flutils.lib.eachDefaultSystem (system:
nginx = {
url = "github:nginx/nginx";
flake = false;
};
};
outputs = { self, nixpkgs, flutils, nixng, nginx, ...}: flutils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
@ -21,10 +31,30 @@
dontUnpack = true;
installPhase = "install -Dm755 ${./patch-feed-date.py} $out/bin/patch-feed-date";
};
nginxPort = "80";
nginxConf = pkgs.writeText "nginx.conf" ''
user nginx nginx;
daemon off;
error_log /dev/stderr;
pid /httpd.pid;
events {}
http {
access_log /dev/stdout;
include ${nginx.outPath}/conf/mime.types;
server {
listen ${nginxPort};
index index.html;
location / {
root ${self.packages.${system}.default};
}
}
}
'';
in
{
packages = {
static-website = pkgs.stdenv.mkDerivation {
packages.default = pkgs.stdenv.mkDerivation {
name = "blog";
src = ./src;
sourceRoot = "src";
@ -45,6 +75,24 @@
patch-feed-date --file _site/feed.xml > $out/feed.xml
'';
};
nixngConfigurations.default = nixng.nglib.makeSystem {
inherit nixpkgs system;
name = "nixng-blog";
config = {config, lib, ...}: {
dinit.enable = true;
init.services.nginx = {
shutdownOnExit = true;
script = lib.mkForce (pkgs.writeShellScript "nginx-run" ''
HOME=~nginx ${config.services.nginx.package}/bin/nginx -c ${nginxConf}
'');
};
services.nginx = {
enable = true;
configuration = [];
};
};
};
});
}