2 description = "a free software media publishing platform that anyone can run.";
4 url = "path:../myuids";
6 inputs.flake-utils.url = "github:numtide/flake-utils";
8 url = "github:NixOS/nixpkgs/840c782d507d60aaa49aa9e3f6d0b0e780912742";
11 inputs.mediagoblin = {
12 url = "git+https://git.savannah.gnu.org/git/mediagoblin.git?submodules=1&ref=stable&rev=cd465ebfec837a75a44c4ebd727dffe2fff6d850";
16 outputs = { self, myuids, nixpkgs, mediagoblin, flake-utils }: flake-utils.lib.eachSystem ["x86_64-linux"] (system:
18 pkgs = import nixpkgs { inherit system; overlays = []; };
19 version = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.mediagoblin.original.ref;
20 inherit (pkgs) callPackage;
22 packages.mediagoblin = callPackage ./. { src = mediagoblin // { inherit version; }; };
23 defaultPackage = packages.mediagoblin;
24 legacyPackages.mediagoblin = packages.mediagoblin;
26 build = defaultPackage;
31 mediagoblin = final: prev: {
32 mediagoblin = self.defaultPackage."${final.system}";
35 overlay = overlays.mediagoblin;
36 nixosModule = { lib, pkgs, config, ... }:
39 cfg = config.services.mediagoblin;
41 uid = config.ids.uids.mediagoblin;
42 gid = config.ids.gids.mediagoblin;
44 paste_local = pkgs.writeText "paste_local.ini" ''
49 pipeline = mediagoblin
52 use = egg:mediagoblin#app
53 config = ${cfg.configFile} ${cfg.package}/mediagoblin.ini
54 /mgoblin_static = ${cfg.package}/mediagoblin/static
76 format = %(levelname)-7.7s [%(name)s] %(message)s
79 use = egg:mediagoblin#errors
83 use = egg:waitress#main
84 unix_socket = ${cfg.sockets.paster}
85 unix_socket_perms = 777
90 options.services.mediagoblin = {
91 enable = lib.mkEnableOption "Enable Mediagoblin’s service";
95 description = "User account under which Mediagoblin runs";
97 group = lib.mkOption {
100 description = "Group under which Mediagoblin runs";
102 dataDir = lib.mkOption {
103 type = lib.types.path;
104 default = "/var/lib/${name}";
106 The directory where Mediagoblin stores its data.
109 socketsDir = lib.mkOption {
110 type = lib.types.path;
111 default = "/run/${name}";
113 The directory where Mediagoblin puts runtime files and sockets.
116 configFile = lib.mkOption {
117 type = lib.types.path;
119 The configuration file path for Mediagoblin.
122 package = lib.mkOption {
123 type = lib.types.package;
124 default = pkgs.mediagoblin;
125 example = lib.literalExample ''
126 pkgs.webapps.mediagoblin.withPlugins (p: [p.basicsearch])
129 Mediagoblin package to use.
132 systemdStateDirectory = lib.mkOption {
133 type = lib.types.str;
134 # Use ReadWritePaths= instead if varDir is outside of /var/lib
135 default = assert lib.strings.hasPrefix "/var/lib/" cfg.dataDir;
136 lib.strings.removePrefix "/var/lib/" cfg.dataDir;
138 Adjusted Mediagoblin data directory for systemd
142 systemdRuntimeDirectory = lib.mkOption {
143 type = lib.types.str;
144 # Use ReadWritePaths= instead if socketsDir is outside of /run
145 default = assert lib.strings.hasPrefix "/run/" cfg.socketsDir;
146 lib.strings.removePrefix "/run/" cfg.socketsDir;
148 Adjusted Mediagoblin sockets directory for systemd
152 sockets = lib.mkOption {
153 type = lib.types.attrsOf lib.types.path;
155 paster = "${cfg.socketsDir}/mediagoblin.sock";
162 pids = lib.mkOption {
163 type = lib.types.attrsOf lib.types.path;
165 paster = "${cfg.socketsDir}/mediagoblin.pid";
166 celery = "${cfg.socketsDir}/mediagoblin-celeryd.pid";
170 Mediagoblin pid files
175 config = lib.mkIf cfg.enable {
176 nixpkgs.overlays = [ self.overlay ];
177 users.users = lib.optionalAttrs (cfg.user == name) {
181 description = "Mediagoblin user";
183 useDefaultShell = true;
186 users.groups = lib.optionalAttrs (cfg.group == name) {
192 systemd.slices.mediagoblin = {
193 description = "Mediagoblin slice";
195 systemd.services.mediagoblin-web = {
196 description = "Mediagoblin service";
197 wantedBy = [ "multi-user.target" ];
198 after = [ "network.target" ];
199 wants = [ "postgresql.service" "redis.service" ];
201 environment.SCRIPT_NAME = "/mediagoblin/";
204 exec ./bin/paster serve \
206 --pid-file=${cfg.pids.paster}
209 exec ./bin/paster serve \
210 --pid-file=${cfg.pids.paster} \
214 if [ -d ${cfg.dataDir}/plugin_static/ ]; then
215 rm ${cfg.dataDir}/plugin_static/coreplugin_basic_auth
216 ln -sf ${cfg.package}/mediagoblin/plugins/basic_auth/static ${cfg.dataDir}/plugin_static/coreplugin_basic_auth
218 ./bin/gmg -cf ${cfg.configFile} dbupdate
222 Slice = "mediagoblin.slice";
228 WorkingDirectory = cfg.package;
229 RuntimeDirectory = cfg.systemdRuntimeDirectory;
230 StateDirectory= cfg.systemdStateDirectory;
231 PIDFile = cfg.pids.paster;
234 unitConfig.RequiresMountsFor = cfg.dataDir;
237 systemd.services.mediagoblin-celeryd = {
238 description = "Mediagoblin service";
239 wantedBy = [ "multi-user.target" ];
240 after = [ "network.target" "mediagoblin-web.service" ];
242 environment.MEDIAGOBLIN_CONFIG = cfg.configFile;
243 environment.CELERY_CONFIG_MODULE = "mediagoblin.init.celery.from_celery";
246 exec ./bin/celery worker \
247 --logfile=${cfg.dataDir}/celery.log \
252 Slice = "mediagoblin.slice";
258 WorkingDirectory = cfg.package;
259 RuntimeDirectory = cfg.systemdRuntimeDirectory;
260 StateDirectory= cfg.systemdStateDirectory;
261 PIDFile = cfg.pids.celery;
264 unitConfig.RequiresMountsFor = cfg.dataDir;