8 cfg = config.services.lxd-image-server;
9 format = pkgs.formats.toml { };
11 location = "/var/www/simplestreams";
15 services.lxd-image-server = {
16 enable = lib.mkEnableOption "lxd-image-server";
18 group = lib.mkOption {
20 description = "Group assigned to the user and the webroot directory.";
25 settings = lib.mkOption {
28 Configuration for lxd-image-server.
30 Example see <https://github.com/Avature/lxd-image-server/blob/master/config.toml>.
36 enable = lib.mkEnableOption "nginx";
37 domain = lib.mkOption {
39 description = "Domain to use for nginx virtual host.";
40 example = "images.example.org";
46 config = lib.mkMerge [
47 (lib.mkIf (cfg.enable) {
48 users.users.lxd-image-server = {
52 users.groups.${cfg.group} = { };
54 environment.etc."lxd-image-server/config.toml".source = format.generate "config.toml" cfg.settings;
56 services.logrotate.settings.lxd-image-server = {
57 files = "/var/log/lxd-image-server/lxd-image-server.log";
60 create = "755 lxd-image-server ${cfg.group}";
66 systemd.tmpfiles.rules = [
67 "d /var/www/simplestreams 0755 lxd-image-server ${cfg.group}"
70 systemd.services.lxd-image-server = {
71 wantedBy = [ "multi-user.target" ];
72 after = [ "network.target" ];
74 description = "LXD Image Server";
77 ${pkgs.lxd-image-server}/bin/lxd-image-server init
78 ${pkgs.lxd-image-server}/bin/lxd-image-server watch
82 User = "lxd-image-server";
85 LogsDirectory = "lxd-image-server";
86 RuntimeDirectory = "lxd-image-server";
87 ExecReload = "${pkgs.lxd-image-server}/bin/lxd-image-server reload";
88 ReadWritePaths = [ location ];
92 # this is separate so it can be enabled on mirrored hosts
93 (lib.mkIf (cfg.nginx.enable) {
94 # https://github.com/Avature/lxd-image-server/blob/master/resources/nginx/includes/lxd-image-server.pkg.conf
95 services.nginx.virtualHosts = {
96 "${cfg.nginx.domain}" = {
98 enableACME = lib.mkDefault true;
104 index = "index.json";
107 # Serve json files with content type header application/json
110 add_header Content-Type application/json;
116 add_header Content-Type application/octet-stream;
122 add_header Content-Type application/octet-stream;
126 # Deny access to document root and the images folder
127 "~ ^/(images/)?$" = {