aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-03 18:43:16 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-03 18:43:16 +0200
commit20e1428fae47a5a59376b624336597eed1b605f5 (patch)
tree7a4af0faab1e9521f0155c5e7be56c5403339db0
parente820fa7dd856f1bd632cc9813077759628b11385 (diff)
downloadNix-20e1428fae47a5a59376b624336597eed1b605f5.tar.gz
Nix-20e1428fae47a5a59376b624336597eed1b605f5.tar.zst
Nix-20e1428fae47a5a59376b624336597eed1b605f5.zip
Move mastodon to pkgs
-rw-r--r--nixops/modules/websites/tools/mastodon/default.nix2
-rw-r--r--nixops/modules/websites/tools/mastodon/mastodon.nix85
-rw-r--r--pkgs/default.nix4
-rw-r--r--pkgs/webapps/mastodon/default.nix86
-rw-r--r--pkgs/webapps/mastodon/gemset.nix (renamed from nixops/modules/websites/tools/mastodon/gemset.nix)0
-rw-r--r--pkgs/webapps/mastodon/mastodon.json (renamed from nixops/modules/websites/tools/mastodon/mastodon.json)0
-rw-r--r--pkgs/webapps/mastodon/yarn-packages.nix (renamed from nixops/modules/websites/tools/mastodon/yarn-packages.nix)0
7 files changed, 95 insertions, 82 deletions
diff --git a/nixops/modules/websites/tools/mastodon/default.nix b/nixops/modules/websites/tools/mastodon/default.nix
index a3f2364..919bac2 100644
--- a/nixops/modules/websites/tools/mastodon/default.nix
+++ b/nixops/modules/websites/tools/mastodon/default.nix
@@ -1,7 +1,7 @@
1{ lib, pkgs, config, myconfig, mylibs, ... }: 1{ lib, pkgs, config, myconfig, mylibs, ... }:
2let 2let
3 mastodon = pkgs.callPackage ./mastodon.nix { 3 mastodon = pkgs.callPackage ./mastodon.nix {
4 inherit (mylibs) fetchedGithub yarn2nixPackage; 4 inherit (pkgs.webapps) mastodon;
5 env = myconfig.env.tools.mastodon; 5 env = myconfig.env.tools.mastodon;
6 }; 6 };
7 7
diff --git a/nixops/modules/websites/tools/mastodon/mastodon.nix b/nixops/modules/websites/tools/mastodon/mastodon.nix
index 67d4d48..83e3a54 100644
--- a/nixops/modules/websites/tools/mastodon/mastodon.nix
+++ b/nixops/modules/websites/tools/mastodon/mastodon.nix
@@ -1,66 +1,7 @@
1{ env, ruby_2_6, bundlerEnv, defaultGemConfig, yarn2nixPackage, fetchedGithub, stdenv, writeText, pkgs }: 1{ env, mastodon }:
2let 2let
3 varDir = "/var/lib/mastodon_immae"; 3 varDir = "/var/lib/mastodon_immae";
4 socketsDir = "/run/mastodon"; 4 socketsDir = "/run/mastodon";
5 gems = bundlerEnv {
6 name = "mastodon-env";
7 ruby = ruby_2_6;
8 gemset = ./gemset.nix;
9 gemdir = (fetchedGithub ./mastodon.json).src;
10 groups = [ "default" "production" "test" "development" ];
11 gemConfig = defaultGemConfig // {
12 redis-rack = attrs: {
13 preBuild = ''
14 sed -i 's!s\.files.*!!' redis-rack.gemspec
15 '';
16 };
17 tzinfo = attrs: {
18 preBuild = ''
19 sed -i 's!s\.files.*!!' tzinfo.gemspec
20 '';
21 };
22 cld3 = attrs: {
23 buildInputs = with pkgs; [ protobuf protobufc pkgconfig ];
24 };
25 idn-ruby = attrs: {
26 buildInputs = with pkgs; [ libidn ];
27 };
28 rpam2 = attrs: {
29 buildInputs = with pkgs; [ pam ];
30 };
31 };
32 };
33 yarnModules = let
34 info = fetchedGithub ./mastodon.json;
35 packagejson = pkgs.runCommand "package.json" { buildInputs = [ pkgs.jq ]; } ''
36 cat ${info.src}/package.json | jq -r '.version = "${info.version}"' > $out
37 '';
38 in
39 yarn2nixPackage.mkYarnModules rec {
40 name = "mastodon-yarn";
41 pname = name;
42 version = info.version;
43 packageJSON = packagejson;
44 yarnLock = "${info.src}/yarn.lock";
45 yarnNix = ./yarn-packages.nix;
46 pkgConfig = {
47 all = {
48 buildInputs = [ yarn2nixPackage.src ];
49 };
50 uws = {
51 postInstall = ''
52 npx node-gyp rebuild > build_log.txt 2>&1 || true
53 '';
54 };
55 };
56 };
57 mastodon = stdenv.mkDerivation (fetchedGithub ./mastodon.json // rec {
58 installPhase = ''
59 cp -a . $out
60 cp -a ${yarnModules}/node_modules $out
61 '';
62 buildInputs = [ yarnModules ];
63 });
64 keys.mastodon = { 5 keys.mastodon = {
65 dest = "webapps/tools-mastodon"; 6 dest = "webapps/tools-mastodon";
66 user = "mastodon"; 7 user = "mastodon";
@@ -109,29 +50,11 @@ let
109 ''; 50 '';
110 }; 51 };
111 52
112 railsRoot = stdenv.mkDerivation { 53 railsRoot = mastodon.override { inherit varDir; };
113 name = "mastodon_immae";
114 inherit mastodon;
115 builder = writeText "build_mastodon_immae" ''
116 source $stdenv/setup
117 set -a
118 SECRET_KEY_BASE=Dummy
119 OTP_SECRET=Dummy
120 set +a
121 cp -a $mastodon $out
122 cd $out
123 chmod u+rwX . public
124 chmod -R u+rwX config/
125 sed -i -e 's@^end$@ config.action_mailer.sendmail_settings = { location: ENV.fetch("SENDMAIL_LOCATION", "/usr/sbin/sendmail") }\nend@' config/environments/production.rb
126 RAILS_ENV=production ${gems}/bin/rails assets:precompile
127 rm -rf tmp/cache
128 ln -sf ${varDir}/tmp/cache tmp
129 '';
130 buildInputs = [ gems gems.ruby pkgs.nodejs pkgs.yarn ];
131 };
132in 54in
133 { 55 {
134 inherit railsRoot varDir socketsDir gems; 56 inherit varDir railsRoot socketsDir;
57 inherit (railsRoot.passthru) gems;
135 keys = builtins.attrValues keys; 58 keys = builtins.attrValues keys;
136 nodeSocket = "${socketsDir}/live_immae_node.sock"; 59 nodeSocket = "${socketsDir}/live_immae_node.sock";
137 railsSocket = "${socketsDir}/live_immae_puma.sock"; 60 railsSocket = "${socketsDir}/live_immae_puma.sock";
diff --git a/pkgs/default.nix b/pkgs/default.nix
index 409d028..d1d8fa4 100644
--- a/pkgs/default.nix
+++ b/pkgs/default.nix
@@ -33,4 +33,8 @@ in
33 pure-ftpd = callPackage ../pkgs/pure-ftpd {}; 33 pure-ftpd = callPackage ../pkgs/pure-ftpd {};
34 mpd = (callPackage ../pkgs/mpd_0_21 {}).mpd; 34 mpd = (callPackage ../pkgs/mpd_0_21 {}).mpd;
35 mpd-small = (callPackage ../pkgs/mpd_0_21 {}).mpd-small; 35 mpd-small = (callPackage ../pkgs/mpd_0_21 {}).mpd-small;
36
37 webapps = {
38 mastodon = (callPackage ./webapps/mastodon { inherit mylibs; });
39 };
36} 40}
diff --git a/pkgs/webapps/mastodon/default.nix b/pkgs/webapps/mastodon/default.nix
new file mode 100644
index 0000000..0f936b5
--- /dev/null
+++ b/pkgs/webapps/mastodon/default.nix
@@ -0,0 +1,86 @@
1{ varDir ? "/var/lib/mastodon", mylibs,
2 stdenv, writeText, runCommand,
3 ruby_2_6, bundlerEnv, defaultGemConfig,
4 jq, protobuf, protobufc, pkgconfig, libidn, pam, nodejs, yarn }:
5let
6 gems = bundlerEnv {
7 name = "mastodon-env";
8 ruby = ruby_2_6;
9 gemset = ./gemset.nix;
10 gemdir = (mylibs.fetchedGithub ./mastodon.json).src;
11 groups = [ "default" "production" "test" "development" ];
12 gemConfig = defaultGemConfig // {
13 redis-rack = attrs: {
14 preBuild = ''
15 sed -i 's!s\.files.*!!' redis-rack.gemspec
16 '';
17 };
18 tzinfo = attrs: {
19 preBuild = ''
20 sed -i 's!s\.files.*!!' tzinfo.gemspec
21 '';
22 };
23 cld3 = attrs: {
24 buildInputs = [ protobuf protobufc pkgconfig ];
25 };
26 idn-ruby = attrs: {
27 buildInputs = [ libidn ];
28 };
29 rpam2 = attrs: {
30 buildInputs = [ pam ];
31 };
32 };
33 };
34 yarnModules = let
35 info = mylibs.fetchedGithub ./mastodon.json;
36 packagejson = runCommand "package.json" { buildInputs = [ jq ]; } ''
37 cat ${info.src}/package.json | jq -r '.version = "${info.version}"' > $out
38 '';
39 in
40 mylibs.yarn2nixPackage.mkYarnModules rec {
41 name = "mastodon-yarn";
42 pname = name;
43 version = info.version;
44 packageJSON = packagejson;
45 yarnLock = "${info.src}/yarn.lock";
46 yarnNix = ./yarn-packages.nix;
47 pkgConfig = {
48 all = {
49 buildInputs = [ mylibs.yarn2nixPackage.src ];
50 };
51 uws = {
52 postInstall = ''
53 npx node-gyp rebuild > build_log.txt 2>&1 || true
54 '';
55 };
56 };
57 };
58 mastodon_with_yarn = stdenv.mkDerivation (mylibs.fetchedGithub ./mastodon.json // rec {
59 installPhase = ''
60 cp -a . $out
61 cp -a ${yarnModules}/node_modules $out
62 '';
63 buildInputs = [ yarnModules ];
64 });
65in
66stdenv.mkDerivation {
67 name = "mastodon";
68 inherit mastodon_with_yarn;
69 builder = writeText "build_mastodon" ''
70 source $stdenv/setup
71 set -a
72 SECRET_KEY_BASE=Dummy
73 OTP_SECRET=Dummy
74 set +a
75 cp -a $mastodon_with_yarn $out
76 cd $out
77 chmod u+rwX . public
78 chmod -R u+rwX config/
79 sed -i -e 's@^end$@ config.action_mailer.sendmail_settings = { location: ENV.fetch("SENDMAIL_LOCATION", "/usr/sbin/sendmail") }\nend@' config/environments/production.rb
80 RAILS_ENV=production ${gems}/bin/rails assets:precompile
81 rm -rf tmp/cache
82 ln -sf ${varDir}/tmp/cache tmp
83 '';
84 buildInputs = [ gems gems.ruby nodejs yarn ];
85 passthru = { inherit gems varDir; };
86}
diff --git a/nixops/modules/websites/tools/mastodon/gemset.nix b/pkgs/webapps/mastodon/gemset.nix
index 9bd2cd3..9bd2cd3 100644
--- a/nixops/modules/websites/tools/mastodon/gemset.nix
+++ b/pkgs/webapps/mastodon/gemset.nix
diff --git a/nixops/modules/websites/tools/mastodon/mastodon.json b/pkgs/webapps/mastodon/mastodon.json
index df73e8f..df73e8f 100644
--- a/nixops/modules/websites/tools/mastodon/mastodon.json
+++ b/pkgs/webapps/mastodon/mastodon.json
diff --git a/nixops/modules/websites/tools/mastodon/yarn-packages.nix b/pkgs/webapps/mastodon/yarn-packages.nix
index feca668..feca668 100644
--- a/nixops/modules/websites/tools/mastodon/yarn-packages.nix
+++ b/pkgs/webapps/mastodon/yarn-packages.nix