about summary refs log tree commit diff
path: root/pkgs/tools/virtualization/google-compute-engine-oslogin/default.nix
blob: 5096c7f94686d7acec40e2f47bcfc842066e9270 (plain) (blame)
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
{ stdenv
, fetchFromGitHub
, curl
, json_c
, pam
}:

stdenv.mkDerivation rec {
  name = "google-compute-engine-oslogin-${version}";
  version = "1.4.3";

  src = fetchFromGitHub {
    repo = "compute-image-packages";
    owner = "GoogleCloudPlatform";
    rev = "2ccfe80f162a01b5b7c3316ca37981fc8b3fc32a";
    sha256 = "036g7609ni164rmm68pzi47vrywfz2rcv0ad67gqf331pvlr92x1";
  };
  sourceRoot = "source/google_compute_engine_oslogin";

  postPatch = ''
    # change sudoers dir from /var/google-sudoers.d to /run/google-sudoers.d (managed through systemd-tmpfiles)
    substituteInPlace pam_module/pam_oslogin_admin.cc --replace /var/google-sudoers.d /run/google-sudoers.d
    # fix "User foo not allowed because shell /bin/bash does not exist"
    substituteInPlace utils/oslogin_utils.cc --replace /bin/bash /bin/sh
  '';

  buildInputs = [ curl.dev pam ];

  NIX_CFLAGS_COMPILE="-I${json_c.dev}/include/json-c";
  NIX_CFLAGS_LINK="-L${json_c}/lib";

  installPhase = ''
    mkdir -p $out/{bin,lib}

    install -Dm755 libnss_cache_google-compute-engine-oslogin-${version}.so $out/lib/libnss_cache_oslogin.so.2
    install -Dm755 libnss_google-compute-engine-oslogin-${version}.so $out/lib/libnss_oslogin.so.2

    install -Dm755 pam_oslogin_admin.so pam_oslogin_login.so $out/lib
    install -Dm755 google_{oslogin_nss_cache,authorized_keys} $out/bin
  '';

  meta = with stdenv.lib; {
    homepage = https://github.com/GoogleCloudPlatform/compute-image-packages;
    description = "OS Login Guest Environment for Google Compute Engine";
    license = licenses.asl20;
    maintainers = with maintainers; [ adisbladis flokli ];
  };
}