summaryrefslogtreecommitdiff
path: root/pkgs/by-name/cr/criu/package.nix
blob: a07fb316921417b2f5b79cf3fa8d2a4fd37ddf24 (about) (plain)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
{
  stdenv,
  lib,
  fetchFromGitHub,
  protobuf,
  protobufc,
  asciidoc,
  iptables,
  xmlto,
  docbook_xsl,
  libpaper,
  libnl,
  libcap,
  libuuid,
  libnet,
  pkg-config,
  iproute2,
  gzip,
  which,
  python3,
  makeWrapper,
  docbook_xml_dtd_45,
  perl,
  nftables,
  libbsd,
  gnutar,
  buildPackages,
}:

stdenv.mkDerivation rec {
  pname = "criu";
  version = "4.1";

  src = fetchFromGitHub {
    owner = "checkpoint-restore";
    repo = "criu";
    rev = "v${version}";
    hash = "sha256-Z4prbaPYRdN/fPdBwDz7D3/gKybh2ulA3UM1LZGeAK0=";
  };

  enableParallelBuilding = true;
  depsBuildBuild = [
    protobufc
    buildPackages.stdenv.cc
  ];
  nativeBuildInputs = [
    pkg-config
    asciidoc
    xmlto
    libpaper
    docbook_xsl
    which
    makeWrapper
    docbook_xml_dtd_45
    python3
    python3.pkgs.wrapPython
    perl
  ];
  buildInputs = [
    protobuf
    libnl
    libcap
    libnet
    nftables
    libbsd
    libuuid
  ];
  propagatedBuildInputs =
    [
      protobufc
    ]
    ++ (with python3.pkgs; [
      python
      python3.pkgs.protobuf
    ]);

  postPatch = ''
    substituteInPlace ./Documentation/Makefile \
      --replace "2>/dev/null" "" \
      --replace "-m custom.xsl" "-m custom.xsl --skip-validation -x ${docbook_xsl}/xml/xsl/docbook/manpages/docbook.xsl"
    substituteInPlace ./Makefile --replace "head-name := \$(shell git tag -l v\$(CRIU_VERSION))" "head-name = ${version}.0"
    ln -sf ${protobuf}/include/google/protobuf/descriptor.proto ./images/google/protobuf/descriptor.proto
  '';

  makeFlags =
    let
      # criu's Makefile infrastructure expects to be passed a target architecture
      # which neither matches the config-tuple's first part, nor the
      # targetPlatform.linuxArch attribute. Thus we take the latter and map it
      # onto the expected string:
      linuxArchMapping = {
        "x86_64" = "x86";
        "arm" = "arm";
        "arm64" = "aarch64";
        "powerpc" = "ppc64";
        "s390" = "s390";
        "mips" = "mips";
        "loongarch" = "loongarch64";
      };
    in
    [
      "PREFIX=$(out)"
      "ASCIIDOC=${buildPackages.asciidoc}/bin/asciidoc"
      "XMLTO=${buildPackages.xmlto}/bin/xmlto"
    ]
    ++ (lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
      "ARCH=${linuxArchMapping."${stdenv.hostPlatform.linuxArch}"}"
      "CROSS_COMPILE=${stdenv.hostPlatform.config}-"
    ]);

  outputs = [
    "out"
    "dev"
    "man"
  ];

  preBuild = ''
    # No idea why but configure scripts break otherwise.
    export SHELL=""
  '';

  hardeningDisable = [
    "stackprotector"
    "fortify"
  ];
  # dropping fortify here as well as package uses it by default:
  # command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]

  postFixup = ''
    wrapProgram $out/bin/criu \
      --set-default CR_IPTABLES ${iptables}/bin/iptables \
      --set-default CR_IP_TOOL ${iproute2}/bin/ip \
      --prefix PATH : ${
        lib.makeBinPath [
          gnutar
          gzip
        ]
      }
    wrapPythonPrograms
  '';

  meta = with lib; {
    description = "Userspace checkpoint/restore for Linux";
    homepage = "https://criu.org";
    license = licenses.gpl2Plus;
    platforms = [
      "x86_64-linux"
      "aarch64-linux"
      "armv7l-linux"
      "loongarch64-linux"
    ];
    maintainers = [ maintainers.thoughtpolice ];
  };
}