/
default.nix
158 lines (142 loc) · 6.03 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
let
localLib = import ./lib.nix;
in
{ system ? builtins.currentSystem
, config ? {}
, pkgs ? localLib.iohkNix.getPkgs { inherit system config; }
, cluster ? "mainnet"
, version ? "versionNotSet"
, buildNum ? null
}:
let
installPath = ".daedalus";
cardanoSL = localLib.cardanoSL { inherit system config; };
cleanSourceFilter = with pkgs.stdenv;
name: type: let baseName = baseNameOf (toString name); in ! (
# Filter out .git repo
(type == "directory" && baseName == ".git") ||
# Filter out editor backup / swap files.
lib.hasSuffix "~" baseName ||
builtins.match "^\\.sw[a-z]$" baseName != null ||
builtins.match "^\\..*\\.sw[a-z]$" baseName != null ||
# Filter out locally generated/downloaded things.
baseName == "dist" ||
baseName == "node_modules" ||
# Filter out the files which I'm editing often.
lib.hasSuffix ".nix" baseName ||
lib.hasSuffix ".dhall" baseName ||
lib.hasSuffix ".hs" baseName ||
# Filter out nix-build result symlinks
(type == "symlink" && lib.hasPrefix "result" baseName)
);
packages = self: {
inherit cluster pkgs version;
inherit (cardanoSL) daedalus-bridge;
## TODO: move to installers/nix
daedalus-installer = import ./installers/default.nix {
inherit (cardanoSL) daedalus-bridge;
inherit localLib;
};
daedalus = self.callPackage ./installers/nix/linux.nix {};
rawapp = self.callPackage ./yarn2nix.nix {
inherit buildNum;
api = "ada";
apiVersion = cardanoSL.daedalus-bridge.version;
};
source = builtins.filterSource cleanSourceFilter ./.;
yaml2json = pkgs.haskell.lib.disableCabalFlag pkgs.haskellPackages.yaml "no-exe";
tests = {
runFlow = self.callPackage ./tests/flow.nix {};
runLint = self.callPackage ./tests/lint.nix {};
runShellcheck = self.callPackage ./tests/shellcheck.nix { src = ./.;};
};
nix-bundle = import (pkgs.fetchFromGitHub {
owner = "matthewbauer";
repo = "nix-bundle";
rev = "7f12322399fd87d937355d0fc263d37d798496fc";
sha256 = "07wnmdadchf73p03wk51abzgd3zm2xz5khwadz1ypbvv3cqlzp5m";
}) { nixpkgs = pkgs; };
desktopItem = pkgs.makeDesktopItem {
name = "Daedalus${if cluster != "mainnet" then "-${cluster}" else ""}";
exec = "INSERT_PATH_HERE";
desktopName = "Daedalus${if cluster != "mainnet" then " ${cluster}" else ""}";
genericName = "Crypto-Currency Wallet";
categories = "Application;Network;";
icon = "INSERT_ICON_PATH_HERE";
};
iconPath = {
# the target of these paths must not be a symlink
demo = {
small = ./installers/icons/mainnet/64x64.png;
large = ./installers/icons/mainnet/1024x1024.png;
};
mainnet = {
small = ./installers/icons/mainnet/64x64.png;
large = ./installers/icons/mainnet/1024x1024.png;
};
staging = {
small = ./installers/icons/staging/64x64.png;
large = ./installers/icons/staging/1024x1024.png;
};
testnet = {
small = ./installers/icons/testnet/64x64.png;
large = ./installers/icons/testnet/1024x1024.png;
};
};
namespaceHelper = pkgs.writeScriptBin "namespaceHelper" ''
#!/usr/bin/env bash
set -e
cd ~/${installPath}/
mkdir -p etc
cat /etc/hosts > etc/hosts
cat /etc/nsswitch.conf > etc/nsswitch.conf
cat /etc/machine-id > etc/machine-id
cat /etc/resolv.conf > etc/resolv.conf
if [ "x$DEBUG_SHELL" == x ]; then
exec .${self.nix-bundle.nix-user-chroot}/bin/nix-user-chroot -n ./nix -c -e -m /home:/home -m /etc:/host-etc -m etc:/etc -p DISPLAY -p HOME -p XAUTHORITY -- /nix/var/nix/profiles/profile-${cluster}/bin/enter-phase2 daedalus
else
exec .${self.nix-bundle.nix-user-chroot}/bin/nix-user-chroot -n ./nix -c -e -m /home:/home -m /etc:/host-etc -m etc:/etc -p DISPLAY -p HOME -p XAUTHORITY -- /nix/var/nix/profiles/profile-${cluster}/bin/enter-phase2 bash
fi
'';
postInstall = pkgs.writeScriptBin "post-install" ''
#!${pkgs.stdenv.shell}
set -ex
test -z "$XDG_DATA_HOME" && { XDG_DATA_HOME="''${HOME}/.local/share"; }
export DAEDALUS_DIR="''${XDG_DATA_HOME}/Daedalus/${cluster}"
mkdir -pv $DAEDALUS_DIR/Logs/pub
exec 2>&1 > $DAEDALUS_DIR/Logs/pub/post-install.log
echo "in post-install hook"
cp -f ${self.iconPath.${cluster}.large} $DAEDALUS_DIR/icon_large.png
cp -f ${self.iconPath.${cluster}.small} $DAEDALUS_DIR/icon.png
cp -Lf ${self.namespaceHelper}/bin/namespaceHelper $DAEDALUS_DIR/namespaceHelper
mkdir -pv ~/.local/bin ''${XDG_DATA_HOME}/applications
${pkgs.lib.optionalString (cluster == "mainnet") "cp -Lf ${self.namespaceHelper}/bin/namespaceHelper ~/.local/bin/daedalus"}
cp -Lf ${self.namespaceHelper}/bin/namespaceHelper ~/.local/bin/daedalus-${cluster}
cat ${self.desktopItem}/share/applications/Daedalus*.desktop | sed \
-e "s+INSERT_PATH_HERE+''${DAEDALUS_DIR}/namespaceHelper+g" \
-e "s+INSERT_ICON_PATH_HERE+''${DAEDALUS_DIR}/icon_large.png+g" \
> "''${XDG_DATA_HOME}/applications/Daedalus${if cluster != "mainnet" then "-${cluster}" else ""}.desktop"
'';
xdg-open = pkgs.writeScriptBin "xdg-open" ''
#!${pkgs.stdenv.shell}
echo -n "xdg-open \"$1\"" > /escape-hatch
'';
preInstall = pkgs.writeText "pre-install" ''
if grep sse4 /proc/cpuinfo -q; then
echo 'SSE4 check pass'
else
echo "ERROR: your cpu lacks SSE4 support, cardano will not work"
exit 1
fi
'';
newBundle = let
daedalus' = self.daedalus.override { sandboxed = true; };
in (import ./installers/nix/nix-installer.nix {
inherit (self) postInstall preInstall cluster;
inherit pkgs;
installationSlug = installPath;
installedPackages = [ daedalus' self.postInstall self.namespaceHelper daedalus'.cfg self.daedalus-bridge daedalus'.daedalus-frontend self.xdg-open ];
nix-bundle = self.nix-bundle;
}).installerBundle;
};
in pkgs.lib.makeScope pkgs.newScope packages