From ca1c54245ff4eaf3222404ec57137eebe89c5167 Mon Sep 17 00:00:00 2001 From: Gerg-L Date: Mon, 3 Jul 2023 18:50:21 -0400 Subject: [PATCH] removed readFile of self which rebuilt every change --- .../gerg-desktop/1_mon.conf | 7 +- .../gerg-desktop/2_mon.conf | 11 +- hosts/gerg-desktop/vfio.nix | 32 ++-- modules/boot/stage-2-init.sh | 145 ++++++++++++++++++ modules/boot/stage2patch.nix | 6 +- modules/shell.nix | 8 - 6 files changed, 179 insertions(+), 30 deletions(-) rename misc/1-monitor.conf => hosts/gerg-desktop/1_mon.conf (97%) rename misc/2-monitor.conf => hosts/gerg-desktop/2_mon.conf (98%) create mode 100755 modules/boot/stage-2-init.sh diff --git a/misc/1-monitor.conf b/hosts/gerg-desktop/1_mon.conf similarity index 97% rename from misc/1-monitor.conf rename to hosts/gerg-desktop/1_mon.conf index c2f6004..ffb1779 100644 --- a/misc/1-monitor.conf +++ b/hosts/gerg-desktop/1_mon.conf @@ -14,7 +14,7 @@ Section "InputClass" Option "Tapping" "on" Option "TappingDragLock" "on" Option "DisableWhileTyping" "off" - Option "Resolution" "3000" + Option "Resolution" "3000" EndSection Section "ServerFlags" @@ -32,6 +32,7 @@ EndSection Section "Module" Load "glx" EndSection + Section "Monitor" Identifier "Monitor0" VendorName "Monitor Vendor" @@ -41,16 +42,16 @@ Section "Monitor" Option "PreferredMode" "1920x1080_144" Option "DPMS" "false" EndSection -Section "Device" +Section "Device" Identifier "Card0" Driver "amdgpu" BusID "PCI:15:0:0" EndSection + Section "Screen" Identifier "Screen0" Device "Card0" Monitor "Monitor0" Option "TearFree" "true" EndSection - diff --git a/misc/2-monitor.conf b/hosts/gerg-desktop/2_mon.conf similarity index 98% rename from misc/2-monitor.conf rename to hosts/gerg-desktop/2_mon.conf index 4ca6f3c..2a64895 100644 --- a/misc/2-monitor.conf +++ b/hosts/gerg-desktop/2_mon.conf @@ -7,7 +7,6 @@ Section "ServerFlags" Option "BlankTime" "0" EndSection - Section "Monitor" Identifier "Monitor" Option "DPMS" "false" @@ -32,32 +31,32 @@ Section "InputClass" Option "Resolution" "3000" EndSection - Section "ServerLayout" Identifier "layout" Screen 0 "nvidia" Inactive "amdgpu" EndSection - Section "Device" Identifier "nvidia" Driver "nvidia" BusID "PCI:1:0:0" EndSection + Section "Screen" Identifier "nvidia" Device "nvidia" Option "AllowEmptyInitialConfiguration" - EndSection +EndSection + Section "Device" Identifier "amdgpu" Driver "amdgpu" BusID "PCI:15:0:0" EndSection + Section "Screen" Identifier "amdgpu" Device "amdgpu" - EndSection - +EndSection diff --git a/hosts/gerg-desktop/vfio.nix b/hosts/gerg-desktop/vfio.nix index 16f5d8e..9c43208 100644 --- a/hosts/gerg-desktop/vfio.nix +++ b/hosts/gerg-desktop/vfio.nix @@ -43,8 +43,22 @@ let ###END OF TAKEN PART in { environment.etc = { - "Xorg/1_mon".source = pkgs.runCommand "1_mon" {} (xserverbase + "cat '${self}/misc/1-monitor.conf' >> $out"); - "Xorg/2_mon".source = pkgs.runCommand "2_mon" {} (xserverbase + "cat '${self}/misc/2-monitor.conf' >> $out"); + "Xorg/1_mon.conf".source = pkgs.runCommand "1_mon.conf" {} ( + xserverbase + + '' + cat << EOF >> $out + ${builtins.readFile ./1_mon.conf} + EOF + '' + ); + "Xorg/2_mon.conf".source = pkgs.runCommand "2_mon.conf" {} ( + xserverbase + + '' + cat << EOF >> $out + ${builtins.readFile ./2_mon.conf} + EOF + '' + ); }; ####VM SOUND BORKED services.pipewire.package = pipewire_fix.legacyPackages.${pkgs.system}.pipewire; @@ -103,9 +117,9 @@ in { users.users.gerg.extraGroups = ["kvm" "libvirtd"]; - services.xserver.displayManager.xserverArgs = lib.mkAfter ["-config /etc/Xorg/current"]; + services.xserver.displayManager.xserverArgs = lib.mkAfter ["-config /etc/Xorg/active.conf"]; services.xserver.displayManager.sessionCommands = lib.mkBefore '' - if ! [ -e "/tmp/ONE_MONITOR" ] ; then + if ! [ -e "/etc/Xorg/ONE_MONITOR" ] ; then xrandr --output DP-0 --auto --mode 3440x1440 --rate 120 --primary --pos 0x0 xrandr --output HDMI-A-1-0 --auto --mode 1920x1080 --rate 144 --set TearFree on --pos 3440x360 xset -dpms @@ -127,8 +141,8 @@ in { systemctl set-property --runtime -- user.slice AllowedCPUs=8-15,24-31 systemctl set-property --runtime -- system.slice AllowedCPUs=8-15,24-31 systemctl set-property --runtime -- init.scope AllowedCPUs=8-15,24-31 - ln -fs /etc/Xorg/1_mon /etc/Xorg/current - touch /tmp/ONE_MONITOR + ln -fs /etc/Xorg/1_mon.conf /etc/Xorg/active.conf + touch /etc/Xorg/ONE_MONITOR systemctl start display-manager.service fi if [ "$OPERATION" == "release" ]; then @@ -139,14 +153,14 @@ in { ${pkgs.libvirt}/bin/virsh nodedev-reattach pci_0000_01_00_0 ${pkgs.libvirt}/bin/virsh nodedev-reattach pci_0000_01_00_1 modprobe -a nvidia_uvm nvidia_drm nvidia nvidia_modeset - ln -fs /etc/Xorg/2_mon /etc/Xorg/current - rm /tmp/ONE_MONITOR + ln -fs /etc/Xorg/2_mon.conf /etc/Xorg/active.conf + rm /etc/Xorg/ONE_MONITOR systemctl start display-manager.service fi fi ''; in [ - "L /etc/Xorg/current - - - - /etc/Xorg/2_mon" + "L /etc/Xorg/active.conf - - - - /etc/Xorg/2_mon.conf" "L+ /var/lib/libvirt/hooks/qemu - - - - ${qemuHook}" "L+ /var/lib/libvirt/qemu/Windows.xml - - - - ${self}/misc/Windows.xml" ]; diff --git a/modules/boot/stage-2-init.sh b/modules/boot/stage-2-init.sh new file mode 100755 index 0000000..656afef --- /dev/null +++ b/modules/boot/stage-2-init.sh @@ -0,0 +1,145 @@ +#! @shell@ +exec 1<>/dev/null + +systemConfig=@systemConfig@ + +export HOME=/root PATH="@path@" + + +if [ "${IN_NIXOS_SYSTEMD_STAGE1:-}" != true ]; then + # Process the kernel command line. + for o in $(>>\e[0m" + echo + + + # Normally, stage 1 mounts the root filesystem read/writable. + # However, in some environments, stage 2 is executed directly, and the + # root is read-only. So make it writable here. + if [ -z "$container" ]; then + mount -n -o remount,rw none / + fi +fi + + +# Likewise, stage 1 mounts /proc, /dev and /sys, so if we don't have a +# stage 1, we need to do that here. +if [ ! -e /proc/1 ]; then + specialMount() { + local device="$1" + local mountPoint="$2" + local options="$3" + local fsType="$4" + + # We must not overwrite this mount because it's bind-mounted + # from stage 1's /run + if [ "${IN_NIXOS_SYSTEMD_STAGE1:-}" = true ] && [ "${mountPoint}" = /run ]; then + return + fi + + install -m 0755 -d "$mountPoint" + mount -n -t "$fsType" -o "$options" "$device" "$mountPoint" + } + source @earlyMountScript@ +fi + + +if [ "${IN_NIXOS_SYSTEMD_STAGE1:-}" = true ]; then + echo "booting system configuration ${systemConfig}" +else + echo "booting system configuration $systemConfig" > /dev/kmsg +fi + + +# Make /nix/store a read-only bind mount to enforce immutability of +# the Nix store. Note that we can't use "chown root:nixbld" here +# because users/groups might not exist yet. +# Silence chown/chmod to fail gracefully on a readonly filesystem +# like squashfs. +chown -f 0:30000 /nix/store +chmod -f 1775 /nix/store +if [ -n "@readOnlyNixStore@" ]; then + if ! [[ "$(findmnt --noheadings --output OPTIONS /nix/store)" =~ ro(,|$) ]]; then + if [ -z "$container" ]; then + mount --bind /nix/store /nix/store + else + mount --rbind /nix/store /nix/store + fi + mount -o remount,ro,bind /nix/store + fi +fi + + +if [ "${IN_NIXOS_SYSTEMD_STAGE1:-}" != true ]; then + # Use /etc/resolv.conf supplied by systemd-nspawn, if applicable. + if [ -n "@useHostResolvConf@" ] && [ -e /etc/resolv.conf ]; then + resolvconf -m 1000 -a host &1 {logErrFd}>&2 + if test -w /dev/kmsg; then + exec > >(tee -i /proc/self/fd/"$logOutFd" | while read -r line; do + if test -n "$line"; then + echo "<7>stage-2-init: $line" > /dev/kmsg + fi + done) 2>&1 + else + mkdir -p /run/log + exec > >(tee -i /run/log/stage-2-init.log) 2>&1 + fi +fi + + +# Required by the activation script +install -m 0755 -d /etc /etc/nixos +install -m 01777 -d /tmp + + +# Run the script that performs all configuration activation that does +# not have to be done at boot time. +echo "running activation script..." +$systemConfig/activate + + +# Record the boot configuration. +ln -sfn "$systemConfig" /run/booted-system + + +# Run any user-specified commands. +@shell@ @postBootCommands@ + + +# Ensure systemd doesn't try to populate /etc, by forcing its first-boot +# heuristic off. It doesn't matter what's in /etc/machine-id for this purpose, +# and systemd will immediately fill in the file when it starts, so just +# creating it is enough. This `: >>` pattern avoids forking and avoids changing +# the mtime if the file already exists. +: >> /etc/machine-id + + +# No need to restore the stdout/stderr streams we never redirected and +# especially no need to start systemd +if [ "${IN_NIXOS_SYSTEMD_STAGE1:-}" != true ]; then + # Reset the logging file descriptors. + exec 1>&$logOutFd 2>&$logErrFd + exec {logOutFd}>&- {logErrFd}>&- + + + # Start systemd in a clean environment. + echo "starting systemd..." + exec @systemdExecutable@ "$@" +fi diff --git a/modules/boot/stage2patch.nix b/modules/boot/stage2patch.nix index 7e5c96d..99dd3ae 100644 --- a/modules/boot/stage2patch.nix +++ b/modules/boot/stage2patch.nix @@ -1,4 +1,4 @@ -{unstable, ...}: { +_: { lib, config, pkgs, @@ -9,9 +9,7 @@ let useHostResolvConf = config.networking.resolvconf.enable && config.networking.useHostResolvConf; bootStage2 = pkgs.substituteAll { - src = pkgs.runCommand "stage-2-init.sh" {} '' - sed '2i exec 1<>/dev/null' ${unstable}/nixos/modules/system/boot/stage-2-init.sh > $out - ''; + src = ./stage-2-init.sh; shellDebug = "${pkgs.bashInteractive}/bin/bash"; shell = "${pkgs.bash}/bin/bash"; inherit (config.boot) readOnlyNixStore systemdExecutable extraSystemdUnitPaths; diff --git a/modules/shell.nix b/modules/shell.nix index c858cae..4940023 100644 --- a/modules/shell.nix +++ b/modules/shell.nix @@ -146,14 +146,6 @@ time_format = "%I:%M %p"; disabled = false; }; - # username = { - # format = "[$user]($style)"; - # show_always = true; - # }; - # hostname = { - # ssh_only = false; - # format = "[$hostname]($style)"; - # }; }; }; };