mirror of
https://github.com/nickolaj-jepsen/nixos.git
synced 2026-01-22 00:01:58 +01:00
feat: add scripts
This commit is contained in:
parent
f1d4ea06fc
commit
4e8afa2dfc
3 changed files with 53 additions and 0 deletions
|
|
@ -36,6 +36,7 @@
|
|||
../modules/programs
|
||||
../modules/desktop
|
||||
../modules/homelab
|
||||
../modules/scripts
|
||||
host
|
||||
]
|
||||
++ modules;
|
||||
|
|
|
|||
25
modules/scripts/default.nix
Normal file
25
modules/scripts/default.nix
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
makeScript = {
|
||||
path,
|
||||
name ? lib.removeSuffix ".bash" (builtins.baseNameOf path),
|
||||
runtimeInputs ? [],
|
||||
}:
|
||||
pkgs.writeShellApplication {
|
||||
inherit name runtimeInputs;
|
||||
text = builtins.readFile path;
|
||||
};
|
||||
in {
|
||||
environment.systemPackages = [
|
||||
(makeScript {
|
||||
path = ./reboot-windows.bash;
|
||||
runtimeInputs = with pkgs; [
|
||||
jq
|
||||
systemd # for bootctl and systemctl
|
||||
];
|
||||
})
|
||||
];
|
||||
}
|
||||
27
modules/scripts/reboot-windows.bash
Normal file
27
modules/scripts/reboot-windows.bash
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Find windows entry id using bootctl
|
||||
WINDOWS_ID=$(bootctl list --json=short | jq -r '.[] | select(.title != null) | select(.title | ascii_downcase | contains("windows")) | .id' | head -n 1)
|
||||
|
||||
if [ -z "$WINDOWS_ID" ]; then
|
||||
# Fallback to checking the ID itself
|
||||
WINDOWS_ID=$(bootctl list --json=short | jq -r '.[] | select(.id | ascii_downcase | contains("windows")) | .id' | head -n 1)
|
||||
fi
|
||||
|
||||
if [ -z "$WINDOWS_ID" ]; then
|
||||
echo "Error: No Windows boot entry found in systemd-boot."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Setting next boot to: $WINDOWS_ID"
|
||||
|
||||
# Check if we have root, if not, try to use sudo
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
sudo bootctl set-oneshot "$WINDOWS_ID"
|
||||
echo "Rebooting..."
|
||||
sudo systemctl reboot
|
||||
else
|
||||
bootctl set-oneshot "$WINDOWS_ID"
|
||||
echo "Rebooting..."
|
||||
systemctl reboot
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue