2020-01-13 14:28:40 +00:00
|
|
|
# This Nix expression takes care of reading/parsing the correct .env configuration file and return it as an attr set
|
|
|
|
{ config, stdenv }:
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (builtins) listToAttrs head tail readFile;
|
|
|
|
inherit (stdenv.lib) attrByPath filter hasPrefix nameValuePair splitString;
|
|
|
|
|
|
|
|
build-type = attrByPath ["status-im" "build-type"] "" config;
|
|
|
|
ci = (attrByPath ["status-im" "ci"] "" config) != "";
|
|
|
|
|
|
|
|
readLinesFromFile =
|
|
|
|
file:
|
|
|
|
let
|
|
|
|
lines = splitString "\n" (readFile file);
|
|
|
|
removeComments = filter (line: line != "" && !(hasPrefix "#" line));
|
|
|
|
meaningfulLines = removeComments lines;
|
|
|
|
in
|
|
|
|
meaningfulLines;
|
|
|
|
readFlagsFromFile =
|
|
|
|
file:
|
|
|
|
let
|
|
|
|
lines = readLinesFromFile file;
|
|
|
|
genAttrs = lines:
|
|
|
|
listToAttrs (map (line:
|
|
|
|
let flag = splitString "=" line;
|
|
|
|
in nameValuePair (head flag) (head (tail flag))) lines);
|
|
|
|
in
|
|
|
|
genAttrs lines;
|
|
|
|
envFileName =
|
|
|
|
if build-type == "release" then ../../.env.release else
|
|
|
|
if build-type == "nightly" then ../../.env.nightly else
|
2020-04-26 12:40:06 +00:00
|
|
|
if build-type == "e2e" then ../../.env.e2e else
|
|
|
|
if build-type == "pr" then ../../.env.jenkins else ../../.env;
|
2020-01-13 14:28:40 +00:00
|
|
|
flags = readFlagsFromFile envFileName; # TODO: Simplify this path search with lib.locateDominatingFile
|
|
|
|
|
|
|
|
in flags
|