File: flake.nix

package info (click to toggle)
rust-rustls-platform-verifier 0.5.3%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 596 kB
  • sloc: makefile: 4; sh: 1
file content (130 lines) | stat: -rw-r--r-- 5,054 bytes parent folder | download | duplicates (3)
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
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
    flake-parts.url = "github:hercules-ci/flake-parts";
    rust-overlay.url = "github:oxalica/rust-overlay";
  };

  outputs = inputs:
    inputs.flake-parts.lib.mkFlake { inherit inputs; } {
      # TODO(XXX): in theory this flake could support aarch64-linux,
      #   x86_64-darwin and aarch64-darwin, but it is untested.
      systems = [ "x86_64-linux" ];
      perSystem = { config, self', pkgs, lib, system, ... }:
        let
          buildToolsVersion = "30.0.3";
          platformVersion = "33";
          rustTargets = [ "${system}-android" ];
          abi = (lib.systems.elaborate system).linuxArch;

          devDeps = with pkgs; [
            android-sdk
            android-studio
            maven
            jdk11 # Matched to CI setup-java task's java-version
            der-ascii
          ];

          android-comp = pkgs.androidenv.composeAndroidPackages {
            buildToolsVersions = [ buildToolsVersion ];
            platformVersions = [ platformVersion ];
            abiVersions = [ abi ];

            # Note: Pinned presently to NDK 23 specifically to workaround an issue
            # with the bundled clang missing libc++ in NDK 24. We can't use NDK
            # 22, as it's too old for cargo-ndk.
            ndkVersion = "23.1.7779620";

            systemImageTypes = [ "default" ];

            includeNDK = true;
            includeEmulator = true;
            includeSystemImages = true;
          };

          # Note: additional flags can be provided to emulator through
          #   the $NIX_ANDROID_EMULATOR_FLAGS env var.
          android-emu = pkgs.androidenv.emulateApp {
            name = "emulate-PlatformVerifier";
            platformVersion = platformVersion;
            abiVersion = abi;
            systemImageType = "default";

            # Note: Depending on your hardware you may wish to enable or disable
            # this option.
            enableGPU = false;
          };

          android-sdk = android-comp.androidsdk;
          android-sdk-root = "${android-sdk}/libexec/android-sdk";

          verifierCargoToml = builtins.fromTOML
            (builtins.readFile ./rustls-platform-verifier/Cargo.toml);
          msrv = verifierCargoToml.package.rust-version;

          verifierPackage = features:
            (pkgs.makeRustPlatform {
              cargo = pkgs.rust-bin.stable.latest.minimal;
              rustc = pkgs.rust-bin.stable.latest.minimal;
            }).buildRustPackage {
              inherit (verifierCargoToml.package) name version;
              src = ./.;
              buildAndTestSubdir = "rustls-platform-verifier";
              cargoLock.lockFile = ./Cargo.lock;
              buildFeatures = features;
              doCheck = false; # Some tests require networking
            };

          mkDevShell = rustc:
            pkgs.mkShell {
              ANDROID_HOME = "${android-sdk-root}";
              ANDROID_SDK_ROOT = "${android-sdk-root}";
              ANDROID_NDK_ROOT = "${android-sdk-root}/ndk-bundle";
              JAVA_HOME = "${pkgs.jdk11}";
              # Note: It's important to set this so that gradle uses the correct
              #   aapt2 binary.
              GRADLE_OPTS =
                "-Dorg.gradle.project.android.aapt2FromMavenOverride=${android-sdk-root}/build-tools/${buildToolsVersion}/aapt2";
              shellHook = ''
                export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc}
                echo 1>&2 "🔒🔍 rustls-platform-verifier"
              '';
              nativeBuildInputs = devDeps ++ [ rustc ];
            };

        in {
          _module.args.pkgs = import inputs.nixpkgs {
            inherit system;
            overlays = [ (import inputs.rust-overlay) ];
            config = {
              # Allow unfree packages and agree to the Android SDK terms of service.
              # Review https://developer.android.com/studio/terms before use.
              allowUnfree = true;
              android_sdk.accept_license = true;
            };
          };

          # Base library.
          packages.rustls-platform-verifier = (verifierPackage [ ]);
          # Library with debug extras.
          packages.rustls-platform-verifier-dbg =
            (verifierPackage [ "dbg" "base64" "docsrs" ]);
          # Test emulator.
          packages.android-emu = android-emu;
          packages.default = self'.packages.rustls-platform-verifier;

          devShells.nightly = (mkDevShell (pkgs.rust-bin.selectLatestNightlyWith
            (toolchain:
              toolchain.default.override { targets = rustTargets; })));
          devShells.stable = (mkDevShell
            (pkgs.rust-bin.stable.latest.default.override {
              targets = rustTargets;
            }));
          devShells.msrv = (mkDevShell
            (pkgs.rust-bin.stable.${msrv}.default.override {
              targets = rustTargets;
            }));
          devShells.default = self'.devShells.nightly;
        };
    };
}