forked from svsticky/constipated-koala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
85 lines (77 loc) · 2.1 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{ sources ? import ./nix
}:
let
pkgs = sources.nixpkgs {};
gitignore = sources.gitignore{ lib = pkgs.lib; };
node = import ./nix/node.nix { inherit pkgs; };
gems = pkgs.bundlerEnv {
name = "koala";
ruby = pkgs.ruby_3_0;
gemdir = ./.;
gemfile = ./Gemfile;
lockfile = ./Gemfile.lock;
gemConfig = pkgs.defaultGemConfig // {
mimemagic = attrs: {
FREEDESKTOP_MIME_TYPES_PATH = "${pkgs.shared-mime-info}/share/mime/packages/freedesktop.org.xml";
};
};
};
node-path = "${(node.shell.override{src = node-jail;}).nodeDependencies}/lib/node_modules";
node-jail = import ./nix/node-jail.nix {};
in
pkgs.stdenv.mkDerivation {
name = "koala";
propagatedBuildInputs = with pkgs; [
shared-mime-info
gems
nodejs
ruby_3_0
curl
imagemagick
ghostscript
mupdf
cacert
bundler
yarn
postgresql_13
jq
bundix
nodePackages.node2nix
];
rails_wrapper = pkgs.writeScript "rails" ''
#!${pkgs.ruby}/bin/ruby
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
'';
buildPhase = ''
ln -s -f ${node-path} node_modules
rm bin/rails
cp $rails_wrapper bin/rails
bundle exec "bin/rails assets:precompile"
'';
koala_rails_wrapper = pkgs.writeScript "koala" ''
#!/bin/bash
export NODE_PATH=${node-path}
${gems.wrappedRuby}/bin/bundle exec rails $@
'';
installPhase = ''
ln -s $koala_rails_wrapper /build/constipated-koala/bin/koala
mv /build/constipated-koala $out
'';
src = builtins.path {
name = "constipated-koala";
path = ./.;
filter = gitignore.gitignoreFilter ./.;
};
NODE_PATH = node-path;
shellHook = ''
if [[ ( ! -e node_modules ) || ( -h node_modules ) ]]; then
rm node_modules
ln -sf ${node-path} node_modules
else
echo "Existing node_modules directory detected, please remove this and restart your nix-shell"
fi
'';
LC_ALL = "C.UTF-8";
}