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