forked from teslamate-org/teslamate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.nix
More file actions
142 lines (128 loc) 路 4.46 KB
/
Copy pathpackage.nix
File metadata and controls
142 lines (128 loc) 路 4.46 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
{ ... }:
{
perSystem =
{
lib,
pkgs,
system,
...
}:
let
beamPackages = pkgs.beam.packagesWith pkgs.beam.interpreters.erlang_29;
elixir = beamPackages.elixir_1_20;
rebar3 = beamPackages.rebar3;
src = ../..;
version = builtins.readFile "${src}/VERSION";
pname = "teslamate";
mixFodDeps = beamPackages.fetchMixDeps {
TOP_SRC = src;
pname = "${pname}-mix-deps";
inherit src version;
hash = "sha256-5GJb6r1kSocH9wIdgSON6EtYueFSj9OJ/bXkWwQeghg="; # if you change the mix deps, you need to update this hash
# hash = pkgs.lib.fakeHash;
};
nodejs = pkgs.nodejs;
assetsRoot = src + "/assets";
# assets/package-lock.json links phoenix, phoenix_html and
# phoenix_live_view as `file:../deps/*`. That directory only exists in a
# working tree after `mix deps.get`, so the already fetched mix deps are
# substituted for them here. Every other dependency is fetched from the
# integrity hashes in package-lock.json, which is why this needs no
# aggregate hash of its own.
npmSources = pkgs.importNpmLock {
npmRoot = assetsRoot;
packageSourceOverrides = {
"node_modules/phoenix" = "${mixFodDeps}/phoenix";
"node_modules/phoenix_html" = "${mixFodDeps}/phoenix_html";
"node_modules/phoenix_live_view" = "${mixFodDeps}/phoenix_live_view";
};
};
nodePackages = pkgs.importNpmLock.buildNodeModules {
npmRoot = assetsRoot;
inherit nodejs;
derivationArgs = {
pname = "${pname}-assets";
inherit version;
# Overrides the sources buildNodeModules would derive itself, so that
# the phoenix packages resolve to mixFodDeps (see npmSources above).
npmDeps = npmSources;
postInstall = ''
ln -s $out/node_modules/.bin $out/bin
'';
};
};
# The locale data must come from the same release as the ex_cldr version
# resolved in mix.lock. Reading the version from the lockfile keeps the
# two from drifting apart; a stale rev otherwise builds green and just
# ships the wrong locales.
cldrVersion =
let
matches = lib.filter (match: match != null) (
map (builtins.match ''^ *"ex_cldr": \{:hex, :ex_cldr, "([^"]+)".*'') (
lib.splitString "\n" (builtins.readFile "${src}/mix.lock")
)
);
in
if matches == [ ] then
throw "could not determine the ex_cldr version from mix.lock"
else
lib.head (lib.head matches);
cldr = pkgs.fetchFromGitHub {
owner = "elixir-cldr";
repo = "cldr";
rev = "v${cldrVersion}";
sha256 = "sha256-nGVuv8jyGCMZS63ga2iObjl+ldIZmM/xDfpQbB/ZRjE="; # if the ex_cldr version in mix.lock changes, you need to update this hash
# sha256 = pkgs.lib.fakeHash;
};
teslamate = beamPackages.mixRelease {
TOP_SRC = src;
inherit
pname
version
elixir
src
mixFodDeps
;
# set the environment variables for the build
SKIP_LOCALE_DOWNLOAD = "true"; # do not download locales during build as they are already included in the cldr package from github
LOCALES = "${cldr}/priv/cldr";
postBuild = ''
ln -sf ${mixFodDeps}/deps deps
ln -sf ${nodePackages}/node_modules assets/node_modules
export PATH="${pkgs.nodejs}/bin:${nodePackages}/bin:$PATH"
${nodejs}/bin/npm run deploy --prefix ./assets
# for external task you need a workaround for the no deps check flag
# https://github.com/phoenixframework/phoenix/issues/2690
mix do deps.loadpaths --no-deps-check, phx.digest
mix phx.digest --no-deps-check
'';
meta = {
mainProgram = "teslamate";
};
};
in
{
options = {
teslamate.cldr = lib.mkOption {
type = lib.types.package;
readOnly = true;
};
teslamate.elixir = lib.mkOption {
type = lib.types.package;
readOnly = true;
};
teslamate.rebar3 = lib.mkOption {
type = lib.types.package;
readOnly = true;
};
};
config = {
teslamate = {
inherit cldr elixir rebar3;
};
packages = {
default = teslamate;
};
};
};
}