From 9e99ee2e474992408809bdf3eecd736284d2640c Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Tue, 31 Dec 2024 11:03:29 +0100 Subject: [PATCH] Add NixNG configuration --- flake.lock | 76 ++++++++++++++++++++++++++++++++++++++++++++++- flake.nix | 86 ++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 142 insertions(+), 20 deletions(-) diff --git a/flake.lock b/flake.lock index bc67a31..5996c53 100644 --- a/flake.lock +++ b/flake.lock @@ -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", diff --git a/flake.nix b/flake.nix index fa4e156..6cbe2fa 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; + }; + + nginx = { + url = "github:nginx/nginx"; + flake = false; + }; }; - outputs = { self, nixpkgs, flutils}: flutils.lib.eachDefaultSystem (system: + outputs = { self, nixpkgs, flutils, nixng, nginx, ...}: flutils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; @@ -21,29 +31,67 @@ 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 { - name = "blog"; - src = ./src; - sourceRoot = "src"; + packages.default = pkgs.stdenv.mkDerivation { + name = "blog"; + src = ./src; + sourceRoot = "src"; - buildInputs = [ - gems - gems.wrappedRuby - patch-feed-date - ]; + buildInputs = [ + gems + gems.wrappedRuby + patch-feed-date + ]; - buildPhase = '' - bundle exec jekyll build --future - ''; + buildPhase = '' + bundle exec jekyll build --future + ''; - installPhase = '' - mkdir -p $out - cp -r _site/* $out/ - patch-feed-date --file _site/feed.xml > $out/feed.xml - ''; + installPhase = '' + mkdir -p $out + cp -r _site/* $out/ + 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 = []; + }; }; }; });