From a3f147541fd01e506a3856b02b34c509703111da Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 28 Mar 2022 14:51:01 +0200 Subject: [PATCH] flake.*: add Nix development environment This change adds a Nix flake capable of setting up an environment for building Gio programs for Linux and Android, on top of the platforms that only needs Go (Windows, WASM). To use the flake, install Nix 2.4 or later and enable experimental support for flakes. Then, you can launch a development shell with $ alias nix='nix --extra-experimental-features "nix-command flakes"' $ nix develop sourcehut:~eliasnaur/gio The environment can also be applied to the current shell, which is useful in combination with direnv: $ . <(nix print-dev-env sourcehut:~eliasnaur/gio) Signed-off-by: Elias Naur --- flake.lock | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 55 ++++++++++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..4f379398 --- /dev/null +++ b/flake.lock @@ -0,0 +1,114 @@ +{ + "nodes": { + "android": { + "inputs": { + "devshell": "devshell", + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1648412532, + "narHash": "sha256-zh0rLcppJ5i2Bh8oBWjBhDvgOrMhDGdXINbp3bhrs0U=", + "owner": "tadfisher", + "repo": "android-nixpkgs", + "rev": "b1318b23926260685dbb09dd127f38c917fc7441", + "type": "github" + }, + "original": { + "owner": "tadfisher", + "repo": "android-nixpkgs", + "type": "github" + } + }, + "devshell": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1647857022, + "narHash": "sha256-Aw70NWLOIwKhT60MHDGjgWis3DP3faCzr6ap9CSayek=", + "owner": "numtide", + "repo": "devshell", + "rev": "0a5ff74dacb9ea22614f64e61aeb3ca0bf0e7311", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1642700792, + "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1648297722, + "narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1643381941, + "narHash": "sha256-pHTwvnN4tTsEKkWlXQ8JMY423epos8wUOhthpwJjtpc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5efc8ca954272c4376ac929f4c5ffefcc20551d5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1648469949, + "narHash": "sha256-ExCG9k36QNs0bNsi2NwnfL4w/kjb661rW43pf03ok/Y=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a63a39e23873d5d72753ff12bb418cb7e470790c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "android": "android", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..d1a6bfc1 --- /dev/null +++ b/flake.nix @@ -0,0 +1,55 @@ +# SPDX-License-Identifier: Unlicense OR MIT +{ + description = "Gio build environment"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + android.url = "github:tadfisher/android-nixpkgs"; + android.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { self, nixpkgs, android }: + let + supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ]; + forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); + in + { + devShells = forAllSystems + (system: + let + pkgs = import nixpkgs { + inherit system; + }; + android-sdk = android.sdk.${system} (sdkPkgs: with sdkPkgs; + [ + build-tools-31-0-0 + cmdline-tools-latest + emulator + platform-tools + platforms-android-31 + ndk-bundle + ]); + in + { + default = with pkgs; mkShell { + ANDROID_SDK_ROOT = "${android-sdk}/share/android-sdk"; + JAVA_HOME = jdk8.home; + packages = [ + android-sdk + jdk8 + clang + ] ++ (if stdenv.isLinux then [ + vulkan-headers + libxkbcommon + wayland + xorg.libX11 + xorg.libXcursor + xorg.libXfixes + libGL + pkgconfig + ] else [ ]); + }; + } + ); + }; +}