1 { config, pkgs, lib, ... }:
3 cfg = config.services.lxd-image-server;
4 format = pkgs.formats.toml {};
6 location = "/var/www/simplestreams";
10 services.lxd-image-server = {
11 enable = lib.mkEnableOption "lxd-image-server";
13 group = lib.mkOption {
15 description = "Group assigned to the user and the webroot directory.";
20 settings = lib.mkOption {
23 Configuration for lxd-image-server.
25 Example see <https://github.com/Avature/lxd-image-server/blob/master/config.toml>.
31 enable = lib.mkEnableOption "nginx";
32 domain = lib.mkOption {
34 description = "Domain to use for nginx virtual host.";
35 example = "images.example.org";
41 config = lib.mkMerge [
42 (lib.mkIf (cfg.enable) {
43 users.users.lxd-image-server = {
47 users.groups.${cfg.group} = {};
49 environment.etc."lxd-image-server/config.toml".source = format.generate "config.toml" cfg.settings;
51 services.logrotate.settings.lxd-image-server = {
52 files = "/var/log/lxd-image-server/lxd-image-server.log";
55 create = "755 lxd-image-server ${cfg.group}";
61 systemd.tmpfiles.rules = [
62 "d /var/www/simplestreams 0755 lxd-image-server ${cfg.group}"
65 systemd.services.lxd-image-server = {
66 wantedBy = [ "multi-user.target" ];
67 after = [ "network.target" ];
69 description = "LXD Image Server";
72 ${pkgs.lxd-image-server}/bin/lxd-image-server init
73 ${pkgs.lxd-image-server}/bin/lxd-image-server watch
77 User = "lxd-image-server";
80 LogsDirectory = "lxd-image-server";
81 RuntimeDirectory = "lxd-image-server";
82 ExecReload = "${pkgs.lxd-image-server}/bin/lxd-image-server reload";
83 ReadWritePaths = [ location ];
87 # this is separate so it can be enabled on mirrored hosts
88 (lib.mkIf (cfg.nginx.enable) {
89 # https://github.com/Avature/lxd-image-server/blob/master/resources/nginx/includes/lxd-image-server.pkg.conf
90 services.nginx.virtualHosts = {
91 "${cfg.nginx.domain}" = {
93 enableACME = lib.mkDefault true;
102 # Serve json files with content type header application/json
105 add_header Content-Type application/json;
111 add_header Content-Type application/octet-stream;
117 add_header Content-Type application/octet-stream;
121 # Deny access to document root and the images folder
122 "~ ^/(images/)?$" = {