Created
August 4, 2024 23:36
-
-
Save mattpolzin/7c4f71df30ef695391aa4697be90e19d to your computer and use it in GitHub Desktop.
Working nginx Docker Image from Nix derivation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { nixpkgs ? import <nixpkgs> {} }: | |
| let inherit (nixpkgs) busybox lib writeText runCommand nginx; | |
| adduser = "${busybox}/bin/adduser"; | |
| files = runCommand "mk-files" {} '' | |
| mkdir -p $out/share | |
| echo '<html>hi</html>' > $out/share/index.html | |
| ''; | |
| nginxConf = writeText "nginx-conf" '' | |
| events {} | |
| http { | |
| server { | |
| listen 8080; | |
| location / { | |
| autoindex on; | |
| root ${files}/share; | |
| } | |
| } | |
| } | |
| ''; | |
| in | |
| nixpkgs.dockerTools.buildLayeredImage { | |
| name = "nginx2"; | |
| enableFakechroot = true; | |
| fakeRootCommands = '' | |
| mkdir -p /etc | |
| touch /etc/passwd | |
| ${adduser} nginx -H | |
| mkdir -p /var/log/nginx | |
| chown nginx /var/log/nginx | |
| ln -sf /dev/stdout /var/log/nginx/access.log | |
| ln -sf /dev/stderr /var/log/nginx/error.log | |
| mkdir -p /tmp | |
| chown nginx /tmp | |
| ''; | |
| config = { | |
| User = "nginx"; | |
| Cmd = [ | |
| "${lib.getExe nginx}" | |
| "-g" | |
| "daemon off;" | |
| "-c" | |
| "${nginxConf}" | |
| ]; | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment