Skip to content

Instantly share code, notes, and snippets.

View CRTified's full-sized avatar
🤔

Carl Richard Theodor Schneider CRTified

🤔
View GitHub Profile
@CRTified
CRTified / acpi_power_snippet.hs
Created April 19, 2017 22:43
Small snippet for a xmonad acpi logger that does not depend on /usr/bin/acpi or sed
-- dev is the device that shall be read (Like "BAT0")
-- attr are the attributes that are going to be read ("status" for charging status, "capacity" for charged capacity, and so on)
acpi_power :: String -> [String] -> Logger
acpi_power dev attr = io $ do
attrOut <- mapM (\x -> liftIO $ readFile $ sysFsPath ++ x) attr
return $ Just $ filter (/= '\n') (intercalate " " attrOut)
where
sysFsPath = "/sys/class/power_supply/" ++ dev ++ "/"
#################
# CORE SETTINGS #
#################
#
# Zim settings
#
@CRTified
CRTified / xmonad.hs
Created October 1, 2017 18:15
ACPI logger
-- Define acpi power logger
acpi_power :: String -> [String] -> Logger
acpi_power dev attr =
io $ do
attrOut <- mapM (\x -> liftIO $ readFile $ sysFsPath ++ x) attr
return $ Just $ filter (/= '\n') (intercalate " " attrOut)
where
sysFsPath = "/sys/class/power_supply/" ++ dev ++ "/"
file_reader :: String -> Logger
@CRTified
CRTified / 42_iPXE
Created November 2, 2017 21:00
iPXE netboot
#!/bin/sh
BOOTUUID=`blkid -o value $(df /boot | grep "$MOUNTPOINT\$"| cut -f1 -d" ") | head -n 2 | tail -n1`;
ROOTUUID=`blkid -o value $(df / | grep "$MOUNTPOINT\$"| cut -f1 -d" ") | head -n 2 | tail -n1`;
PREFIX=""
if [ "$BOOTUUID" = "$ROOTUUID" ]; then
PREFIX="/boot"
fi;
@CRTified
CRTified / shebang.c
Last active February 6, 2018 19:03
Shebangs
#!/usr/bin/env sh
#if 0
TMPFILE=$(mktemp);
tail -n +10 $0 | gcc -march=native -o $TMPFILE -x c -;
$TMPFILE "${@:1}";
RETVAL=$?
rm $TMPFILE;
exit $RETVAL;
#endif
@CRTified
CRTified / vpnwatch.service
Created June 25, 2018 11:29
Simple Openvpn Watchdog
[Unit]
Description=VPN watchdog
After=network.target
[Service]
Type=oneshot
ExecStart=/bin/sh -c 'ping -I tun0 -c 1 8.8.8.8 > /dev/null || systemctl restart [email protected]'
[Install]
WantedBy=multi-user.target
@CRTified
CRTified / xmonad.hook
Last active February 24, 2021 07:53
Automatic recompilation after xmonad or haskell libs update
[Trigger]
Operation=Install
Operation=Upgrade
Type=Package
Target=xmonad
Target=haskell-*
[Action]
Depends=xmonad
When=PostTransaction
@CRTified
CRTified / libvirt.nix
Created June 25, 2019 23:13
VFIO Passthrough
{ lib, pkgs, config, ... }:
with lib;
let
cfg = config.virtualisation.libvirtd;
boolToZeroOne = x: if x then "1" else "0";
aclString = with lib.strings;
concatMapStringsSep ",\n " escapeNixString cfg.deviceACL;
in {
@CRTified
CRTified / README.md
Last active August 12, 2024 21:20
VFIO Passthrough on NixOS

VFIO Setup on NixOS

Disclaimer: Nobody else tested my setup so far, so this is a "works on my machine" scenario. I am not responsible for anything you break on your machine (although I'd not expect much harm).

Hardware

My system has the following hardware:

  • Board: ASRock X570 Pro4
bracket
(do
sock <- socket AF_UNIX Stream 0
setSocketOption sock ReuseAddr 1
bind sock $ SockAddrUnix s
listen sock maxListenQueue
return sock
)
(\sock -> do