Skip to content

Commit 9bade2a

Browse files
committed
nix: Add Docker image
Docker image has been requested for ages so let’s add it.
1 parent 41654ef commit 9bade2a

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

flake.nix

+5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@
8080
};
8181

8282
packages = {
83+
selfoss-docker = pkgs.callPackage ./utils/docker.nix {
84+
inherit (nixpkgs.lib) nixosSystem;
85+
targetPlatform = system;
86+
};
87+
8388
selfoss = pkgs.callPackage ./utils/selfoss.nix {
8489
src = self.outPath;
8590
};

utils/docker.nix

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
coreutils,
3+
bash,
4+
util-linux,
5+
dockerTools,
6+
unzip,
7+
lib,
8+
nixosSystem,
9+
targetPlatform,
10+
}:
11+
12+
# We are going to abuse the NixOS module for Apache to create configuration files.
13+
# Then we will extract them from the instantiated system and add them to the image.
14+
15+
let
16+
# Configuration for NixOS system.
17+
systemConfiguration = { config, lib, pkgs, ... }: {
18+
services.httpd = {
19+
enable = true;
20+
21+
# TODO: make this overridable? Or hidden?
22+
adminAddr = "admin@selfoss";
23+
24+
# TODO: is root okay?
25+
user = "root";
26+
group = "root";
27+
28+
virtualHosts."selfoss" = {
29+
documentRoot = "/var/www";
30+
locations."/" = {
31+
index = "index.php index.html";
32+
};
33+
};
34+
35+
phpPackage = pkgs.php;
36+
enablePHP = true;
37+
};
38+
};
39+
40+
# Instantiate the NixOS configuration.
41+
system = nixosSystem {
42+
system = targetPlatform;
43+
44+
modules = [
45+
systemConfiguration
46+
];
47+
};
48+
49+
apacheHttpd = system.config.services.httpd.package;
50+
51+
in
52+
dockerTools.buildLayeredImage {
53+
name = "selfoss";
54+
tag = "latest";
55+
56+
contents = [
57+
apacheHttpd
58+
59+
# TODO: remove, only for debugging
60+
coreutils
61+
bash
62+
util-linux
63+
];
64+
65+
# Cargo-culted from https://sandervanderburg.blogspot.com/2020/07/on-using-nix-and-docker-as-deployment.html
66+
maxLayers = 100;
67+
68+
extraCommands = ''
69+
mkdir -p var/log/httpd var/cache/httpd var/www etc/httpd
70+
${selfoss} -d var/www
71+
cp ${system.config.environment.etc."httpd/httpd.conf".source} etc/httpd/httpd.conf
72+
'';
73+
74+
config = {
75+
Cmd = [ "${apacheHttpd}/bin/apachectl" "-D" "FOREGROUND" ];
76+
Expose = {
77+
"80/tcp" = {};
78+
};
79+
};
80+
}
81+
82+
# TODO: add devenv image
83+
# NOTE: Can be run:
84+
# nix build -L .#selfoss-docker
85+
# docker load < result
86+
# docker run -p 8080:80/tcp -it selfoss:latest

0 commit comments

Comments
 (0)