From 66efaddfab70e55be329ad57903d6f46cb75b396 Mon Sep 17 00:00:00 2001 From: Alya Sirko Date: Wed, 7 Sep 2022 19:30:48 +0300 Subject: [PATCH] new flake which supports desktop --- flake.lock | 78 ++++++++++++++++++++++++++++--- flake.nix | 135 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 189 insertions(+), 24 deletions(-) diff --git a/flake.lock b/flake.lock index ca75926d..cfd8ecfe 100644 --- a/flake.lock +++ b/flake.lock @@ -1,23 +1,89 @@ { "nodes": { - "nixpkgs-unstable": { + "flake-utils": { "locked": { - "lastModified": 1662019588, - "narHash": "sha256-oPEjHKGGVbBXqwwL+UjsveJzghWiWV0n9ogo1X6l4cw=", + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixgl": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1661367362, + "narHash": "sha256-Qc8MXcV+YCPREu8kk6oggk23ZBKLqeQRAIsLbHEviPE=", + "owner": "guibou", + "repo": "nixGL", + "rev": "7165ffbccbd2cf4379b6cd6d2edd1620a427e5ae", + "type": "github" + }, + "original": { + "owner": "guibou", + "repo": "nixGL", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1660551188, + "narHash": "sha256-a1LARMMYQ8DPx1BgoI/UN4bXe12hhZkCNqdxNi6uS0g=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "441dc5d512153039f19ef198e662e4f3dbb9fd65", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1662096612, + "narHash": "sha256-R+Q8l5JuyJryRPdiIaYpO5O3A55rT+/pItBrKcy7LM4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "2da64a81275b68fdad38af669afeda43d401e94b", + "rev": "21de2b973f9fee595a7a1ac4693efff791245c34", "type": "github" }, "original": { "id": "nixpkgs", - "ref": "nixos-unstable", + "ref": "nixpkgs-unstable", "type": "indirect" } }, "root": { "inputs": { - "nixpkgs-unstable": "nixpkgs-unstable" + "flake-utils": "flake-utils", + "nixgl": "nixgl", + "nixpkgs": "nixpkgs_2" } } }, diff --git a/flake.nix b/flake.nix index ed8dad75..8a04a423 100644 --- a/flake.nix +++ b/flake.nix @@ -1,22 +1,121 @@ { - inputs.nixpkgs-unstable.url = "nixpkgs/nixos-unstable"; + nixConfig.bash-prompt = "\[selfprivacy\]$ "; - outputs = { self, nixpkgs-unstable }: - let - pkgs = import nixpkgs-unstable { config.allowUnfree = true; config.android_sdk.accept_license = true; }; - androidComposition = pkgs.androidenv.composeAndroidPackages { - toolsVersion = "26.1.1"; - platformToolsVersion = "33.0.2"; - buildToolsVersions = [ "30.0.3" ]; - platformVersions = [ "31" "30" "29" ]; - }; - in { - devShell.x86_64-linux = pkgs.mkShell { - JAVA_HOME = "${pkgs.openjdk11_headless.home}"; - ANDROID_HOME = "${androidComposition.androidsdk}/libexec/android-sdk"; - ANDROID_SDK_ROOT = "${androidComposition.androidsdk}/libexec/android-sdk"; + inputs.nixpkgs.url = "nixpkgs/nixpkgs-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.nixgl.url = "github:guibou/nixGL"; - buildInputs = with pkgs; [ bash git androidComposition.androidsdk flutter openjdk11_headless ]; - }; - }; + outputs = { self, nixpkgs, flake-utils, nixgl }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + config.allowUnfree = true; + config.android_sdk.accept_license = true; + system = "x86_64-linux"; + overlays = [ nixgl.overlay ]; + }; + + androidComposition = pkgs.androidenv.composeAndroidPackages { + toolsVersion = "26.1.1"; + platformToolsVersion = "33.0.2"; + buildToolsVersions = [ "30.0.3" ]; + platformVersions = [ "31" "30" "29" ]; + }; + + buildDeps = with pkgs; [ + gtk3 + glib + pcre + util-linux + libselinux + libsepol + libthai + libdatrie + xorg.libXdmcp + xorg.libXtst + libxkbcommon + dbus + at-spi2-core + libsecret + jsoncpp + xorg.libX11 + libepoxy + libgcrypt + libgpg-error + ]; + + nativeBuildDeps = with pkgs; [ + flutter.unwrapped + bash + curl + flutter.dart + git + unzip + which + xz + cmake + ninja + pkg-config + wrapGAppsHook + autoPatchelfHook + androidComposition.androidsdk + openjdk11_headless + ]; + + releaseDerivation = pkgs.flutter.mkFlutterApp rec { + pname = "selfprivacy"; + version = "0.6.0"; + + vendorHash = "sha256-7cbiAyIlaz3HqEsZN/nZxaLZjseJv5CmiIHqsoGa4ZI="; + + nativeBuildInputs = [ pkgs.nixgl.auto.nixGLDefault ]; + + src = ./.; + + desktopItem = pkgs.makeDesktopItem { + name = "${pname}"; + exec = "@out@/bin/${pname}"; + desktopName = "SelfPrivacy"; + }; + + postInstall = '' + rm $out/bin/$pname + + printf "#!/bin/sh\n${pkgs.nixgl.auto.nixGLDefault}/bin/nixGL $out/app/${pname}" > $out/bin/$pname + patchShebangs $out/bin/$pname + chmod +x $out/bin/$pname + wrapProgram $out/bin/$pname --set PATH ${pkgs.lib.makeBinPath [ pkgs.xdg-user-dirs ]} + + mkdir -p $out/share/applications + cp $desktopItem/share/applications/*.desktop $out/share/applications + substituteInPlace $out/share/applications/*.desktop --subst-var out + ''; + }; + in + { + packages = { + release = releaseDerivation; + }; + defaultPackage = releaseDerivation; + + devShell = pkgs.mkShell { + buildInputs = buildDeps; + nativeBuildInputs = nativeBuildDeps; + + JAVA_HOME = "${pkgs.openjdk11_headless.home}"; + ANDROID_HOME = "${androidComposition.androidsdk}/libexec/android-sdk"; + ANDROID_SDK_ROOT = "${androidComposition.androidsdk}/libexec/android-sdk"; + + NIX_LDFLAGS = "-rpath ${pkgs.lib.makeLibraryPath buildDeps}"; + NIX_CFLAGS_COMPILE = "-I${pkgs.xorg.libX11}/include"; + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildDeps; + + shellHook = '' + export TMP=$(mktemp -d) + export HOME="$TMP" + export PUB_CACHE=''${PUB_CACHE:-"$HOME/.pub-cache"} + export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1 + ''; + }; + }); }