1{ lib
2, coreutils
3, fakechroot
4, fakeroot
5, evalMinimalConfig
6, pkgsModule
7, runCommand
8, util-linux
9, vmTools
10, writeText
11}:
12let
13 node = evalMinimalConfig ({ config, ... }: {
14 imports = [ pkgsModule ../etc/etc.nix ];
15 environment.etc."passwd" = {
16 text = passwdText;
17 };
18 environment.etc."hosts" = {
19 text = hostsText;
20 mode = "0751";
21 };
22 });
23 passwdText = ''
24 root:x:0:0:System administrator:/root:/run/current-system/sw/bin/bash
25 '';
26 hostsText = ''
27 127.0.0.1 localhost
28 ::1 localhost
29 # testing...
30 '';
31in
32lib.recurseIntoAttrs {
33 test-etc-vm =
34 vmTools.runInLinuxVM (runCommand "test-etc-vm" { } ''
35 mkdir -p /etc
36 ${node.config.system.build.etcActivationCommands}
37 set -x
38 [[ -L /etc/passwd ]]
39 diff /etc/passwd ${writeText "expected-passwd" passwdText}
40 [[ 751 = $(stat --format %a /etc/hosts) ]]
41 diff /etc/hosts ${writeText "expected-hosts" hostsText}
42 set +x
43 touch $out
44 '');
45
46 # fakeroot is behaving weird
47 test-etc-fakeroot =
48 runCommand "test-etc"
49 {
50 nativeBuildInputs = [
51 fakeroot
52 fakechroot
53 # for chroot
54 coreutils
55 # fakechroot needs getopt, which is provided by util-linux
56 util-linux
57 ];
58 fakeRootCommands = ''
59 mkdir -p /etc
60 ${node.config.system.build.etcActivationCommands}
61 diff /etc/hosts ${writeText "expected-hosts" hostsText}
62 touch $out
63 '';
64 } ''
65 mkdir fake-root
66 export FAKECHROOT_EXCLUDE_PATH=/dev:/proc:/sys:${builtins.storeDir}:$out
67 fakechroot fakeroot chroot $PWD/fake-root bash -c 'source $stdenv/setup; eval "$fakeRootCommands"'
68 '';
69
70}