nixpkgs/pkgs/tools/misc/etcher/default.nix

87 lines
2.4 KiB
Nix
Raw Normal View History

2020-04-27 21:22:56 +01:00
{ stdenv
, fetchurl
, gcc-unwrapped
, dpkg
, polkit
2020-11-24 15:29:28 +00:00
, util-linux
, bash
, nodePackages
2020-04-27 21:22:56 +01:00
, makeWrapper
, electron_7
}:
let
sha256 = {
2020-04-27 21:22:56 +01:00
"x86_64-linux" = "1yvqi86bw0kym401zwknhwq9041fxg047sbj3aydnfcqf11vrrmk";
"i686-linux" = "12lghzhsl16h3jvzm3vw4hrly32fz99z6rdmybl8viralrxy8mb8";
}."${stdenv.system}";
arch = {
"x86_64-linux" = "amd64";
"i686-linux" = "i386";
}."${stdenv.system}";
electron = electron_7;
2020-04-27 21:22:56 +01:00
in
stdenv.mkDerivation rec {
pname = "etcher";
2020-04-27 21:22:56 +01:00
version = "1.5.86";
src = fetchurl {
url = "https://github.com/balena-io/etcher/releases/download/v${version}/balena-etcher-electron_${version}_${arch}.deb";
inherit sha256;
};
dontBuild = true;
dontConfigure = true;
2020-04-27 21:22:56 +01:00
nativeBuildInputs = [ makeWrapper ];
unpackPhase = ''
${dpkg}/bin/dpkg-deb -x $src .
'';
# sudo-prompt has hardcoded binary paths on Linux and we patch them here
# along with some other paths
patchPhase = ''
${nodePackages.asar}/bin/asar extract opt/balenaEtcher/resources/app.asar tmp
2020-04-27 21:22:56 +01:00
# use Nix(OS) paths
sed -i "s|/usr/bin/pkexec|/usr/bin/pkexec', '/run/wrappers/bin/pkexec|" tmp/node_modules/sudo-prompt/index.js
sed -i 's|/bin/bash|${bash}/bin/bash|' tmp/node_modules/sudo-prompt/index.js
2020-11-24 15:29:28 +00:00
sed -i "s|'lsblk'|'${util-linux}/bin/lsblk'|" tmp/node_modules/drivelist/js/lsblk/index.js
2020-04-27 21:22:56 +01:00
sed -i "s|process.resourcesPath|'$out/share/${pname}/resources/'|" tmp/generated/gui.js
${nodePackages.asar}/bin/asar pack tmp opt/balenaEtcher/resources/app.asar
rm -rf tmp
'';
installPhase = ''
2020-04-27 21:22:56 +01:00
runHook preInstall
mkdir -p $out/bin $out/share/${pname}
cp -a usr/share/* $out/share
cp -a opt/balenaEtcher/{locales,resources} $out/share/${pname}
2020-04-27 21:22:56 +01:00
substituteInPlace $out/share/applications/balena-etcher-electron.desktop \
--replace 'Exec=/opt/balenaEtcher/balena-etcher-electron' 'Exec=${pname}'
2020-04-27 21:22:56 +01:00
runHook postInstall
'';
2020-04-27 21:22:56 +01:00
postFixup = ''
makeWrapper ${electron}/bin/electron $out/bin/${pname} \
2020-04-27 21:22:56 +01:00
--add-flags $out/share/${pname}/resources/app.asar \
--prefix LD_LIBRARY_PATH : "${stdenv.lib.makeLibraryPath [ gcc-unwrapped.lib ]}"
'';
meta = with stdenv.lib; {
description = "Flash OS images to SD cards and USB drives, safely and easily";
homepage = "https://etcher.io/";
license = licenses.asl20;
maintainers = [ maintainers.shou ];
platforms = [ "i686-linux" "x86_64-linux" ];
};
}