fluffychat: 1.22.1 -> 1.23.0 (#364091)
[NixPkgs.git] / pkgs / by-name / di / distrobuilder / nixos-generator.patch
blob7379274fa072c17aa6608dae9307cff6b5718205
1 diff --git a/distrobuilder/lxc.generator b/distrobuilder/lxc.generator
2 index dc5b506..0265da8 100644
3 --- a/distrobuilder/lxc.generator
4 +++ b/distrobuilder/lxc.generator
5 @@ -21,16 +21,6 @@ is_incus_vm() {
6 [ -e /dev/virtio-ports/org.linuxcontainers.incus ]
9 -# is_in_path succeeds if the given file exists in on of the paths
10 -is_in_path() {
11 - # Don't use $PATH as that may not include all relevant paths
12 - for path in /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin; do
13 - [ -e "${path}/$1" ] && return 0
14 - done
16 - return 1
19 ## Fix functions
20 # fix_ro_paths avoids udevd issues with /sys and /proc being writable
21 fix_ro_paths() {
22 @@ -42,38 +32,6 @@ fix_ro_paths() {
23 EOF
26 -# fix_nm_link_state forces the network interface to a DOWN state ahead of NetworkManager starting up
27 -fix_nm_link_state() {
28 - [ -e "/sys/class/net/$1" ] || return 0
29 - ip_path=
30 - if [ -f /sbin/ip ]; then
31 - ip_path=/sbin/ip
32 - elif [ -f /bin/ip ]; then
33 - ip_path=/bin/ip
34 - else
35 - return 0
36 - fi
37 - cat <<-EOF > /run/systemd/system/network-device-down.service
38 - # This file was created by distrobuilder
39 - [Unit]
40 - Description=Turn off network device
41 - Before=NetworkManager.service
42 - Before=systemd-networkd.service
44 - [Service]
45 - # do not turn off if there is a default route to 169.254.0.1, i.e. the device is a routed nic
46 - ExecCondition=/bin/sh -c '! /usr/bin/grep -qs 00000000.0100FEA9 /proc/net/route'
47 - ExecStart=-${ip_path} link set $1 down
48 - Type=oneshot
49 - RemainAfterExit=true
51 - [Install]
52 - WantedBy=default.target
53 - EOF
54 - mkdir -p /run/systemd/system/default.target.wants
55 - ln -sf /run/systemd/system/network-device-down.service /run/systemd/system/default.target.wants/network-device-down.service
58 # fix_systemd_override_unit generates a unit specific override
59 fix_systemd_override_unit() {
60 dropin_dir="/run/systemd/${1}.d"
61 @@ -113,16 +71,7 @@ fix_systemd_mask() {
62 # fix_systemd_udev_trigger overrides the systemd-udev-trigger.service to match the latest version
63 # of the file which uses "ExecStart=-" instead of "ExecStart=".
64 fix_systemd_udev_trigger() {
65 - cmd=
66 - if [ -f /usr/bin/udevadm ]; then
67 - cmd=/usr/bin/udevadm
68 - elif [ -f /sbin/udevadm ]; then
69 - cmd=/sbin/udevadm
70 - elif [ -f /bin/udevadm ]; then
71 - cmd=/bin/udevadm
72 - else
73 - return 0
74 - fi
75 + cmd=udevadm
77 mkdir -p /run/systemd/system/systemd-udev-trigger.service.d
78 cat <<-EOF > /run/systemd/system/systemd-udev-trigger.service.d/zzz-lxc-override.conf
79 @@ -134,38 +83,13 @@ fix_systemd_udev_trigger() {
80 EOF
83 -# fix_systemd_sysctl overrides the systemd-sysctl.service to use "ExecStart=-" instead of "ExecStart=".
84 -fix_systemd_sysctl() {
85 - cmd=/usr/lib/systemd/systemd-sysctl
86 - ! [ -e "${cmd}" ] && cmd=/lib/systemd/systemd-sysctl
87 - mkdir -p /run/systemd/system/systemd-sysctl.service.d
88 - cat <<-EOF > /run/systemd/system/systemd-sysctl.service.d/zzz-lxc-override.conf
89 - # This file was created by distrobuilder
90 - [Service]
91 - ExecStart=
92 - ExecStart=-${cmd}
93 - EOF
96 ## Main logic
97 -# Nothing to do in Incus VM but deployed in case it is later converted to a container
98 -is_incus_vm && exit 0
100 # Exit immediately if not an Incus/LXC container
101 is_lxc_container || exit 0
103 -# Check for NetworkManager
104 -nm_exists=0
106 -is_in_path NetworkManager && nm_exists=1
108 # Determine systemd version
109 -for path in /usr/lib/systemd/systemd /lib/systemd/systemd; do
110 - [ -x "${path}" ] || continue
112 - systemd_version="$("${path}" --version | head -n1 | cut -d' ' -f2 | cut -d'~' -f1)"
113 - break
114 -done
115 +systemd_version="$(systemd --version | head -n1 | cut -d' ' -f2)"
117 # Determine distro name and release
118 ID=""
119 @@ -196,7 +120,6 @@ fi
121 # Ignore failures on some units.
122 fix_systemd_udev_trigger
123 -fix_systemd_sysctl
125 # Mask some units.
126 fix_systemd_mask dev-hugepages.mount
127 @@ -226,11 +149,6 @@ if [ -d /etc/udev ]; then
131 -# Workarounds for NetworkManager in containers
132 -if [ "${nm_exists}" -eq 1 ]; then
133 - fix_nm_link_state eth0
136 # Allow masking units created by the lxc system-generator.
137 for d in /etc/systemd/system /usr/lib/systemd/system /lib/systemd/system; do
138 if ! [ -d "${d}" ]; then