Skip to content

Instantly share code, notes, and snippets.

@aabccd021
aabccd021 / debug-vm.nix
Created June 18, 2025 04:46
NixOS debug vm
{ lib, modulesPath, ... }:
{
imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ];
disko.devices.disk.disk1.device = lib.mkForce "/dev/vda";
services.openssh.settings.PermitRootLogin = "yes";
services.openssh.settings.PermitEmptyPasswords = "yes";
services.openssh.settings.PasswordAuthentication = lib.mkForce true;
@aabccd021
aabccd021 / gist:94504ae7a7d4f395b6ca8f80a097d5a6
Created June 16, 2025 00:17
Show largest nix derivation
nix run nixpkgs#dua -- --count-hard-links --apparent-size /nix/store
@aabccd021
aabccd021 / ssh_sops.sh
Created June 12, 2025 11:38
inser ssh key to sops file
ssh-keygen -f __foo && sops set ./host-secrets.yaml '["node2_ssh_key"]' "$(cat __foo | tr -d '\n' | jq -R '@json')" &&
cat __foo.pub && rm __foo*
@aabccd021
aabccd021 / create_dataset.sh
Last active June 3, 2025 23:35
ZFS create encrypted dataset
zfs create -o encryption=on -o keyformat=passphrase -o keylocation=file:///path/to/secret pool/dataset
@aabccd021
aabccd021 / detect_fs_anomaly.sh
Created May 19, 2025 02:34
fs anomaly detection
find "$dir" 2>/dev/null | while read -r item; do
# Get all stats at once for each item
stats=$(stat --format "%F|%a|%u|%g" "$item" 2>/dev/null)
# Parse the stats
IFS='|' read -r type perms owner group <<< "$stats"
# Set expected values based on whether it's a directory or file
if [ "$type" = "directory" ]; then
expected_perms="700"
item_type="Directory"
@aabccd021
aabccd021 / systemd-monitor.sh
Created May 15, 2025 05:42
systemd-monitor.sh
#!/bin/sh
webhook_url="https://discord.com/api/webhooks/your-webhook-url-here"
cursor_file="/var/lib/systemd-monitor/journal_cursor"
# Use journalctl cursor for more atomic and reliable tracking
if [ -f "$cursor_file" ]; then
journal_args="--cursor-file=$cursor_file"
else
# First run - check last 5 min then save cursor
@aabccd021
aabccd021 / check-duplicate.nix
Created May 12, 2025 01:21
check duplicate scenario
{
checkDuplicateScenario = pkgs.runCommand "checkDuplicateScenario"
{ env.HISTORIES = "${snapshot-scenarioHistories}/test/scenario-histories"; } ''
scenarioDirFiles=$(ls "$HISTORIES")
checked=""
for scenario1 in $scenarioDirFiles; do
for scenario2 in $scenarioDirFiles; do
if [ "$scenario1" = "$scenario2" ]; then
continue
fi
@aabccd021
aabccd021 / mpv-youtube.nix
Created April 4, 2025 04:54
mpv youtube keymap
{
programs.mpv.enable = true;
programs.mpv.bindings.j = "seek -5";
programs.mpv.bindings.l = "seek 5";
programs.mpv.bindings.k = "cycle pause";
programs.mpv.bindings.UP = "add volume 5";
programs.mpv.bindings.DOWN = "add volume -5";
programs.mpv.bindings.">" = "multiply speed 1.1";
programs.mpv.bindings."<" = "multiply speed 1/1.1";
programs.mpv.bindings.c = "cycle sub";
@aabccd021
aabccd021 / lsp-after-direnv.lua
Created April 4, 2025 02:56
neovim start lsp after direnv load
local lsp_langs = { "ts_ls", "biome", "nixd" }
local direnv_lspstart_group = vim.api.nvim_create_augroup("StartLspAfterDirenv", { clear = true })
vim.api.nvim_create_autocmd("BufEnter", {
group = vim.api.nvim_create_augroup("StartLsp", { clear = true }),
pattern = "*",
callback = function()
local result = vim.system(
{ "git", "-C", vim.fn.expand("%:p:h"), "rev-parse", "--show-toplevel" },
{ text = true }
)
@aabccd021
aabccd021 / colors.nix
Created April 3, 2025 12:04
qutebrowser gruvbox material dark hard
{
programs.qutebrowser.settings.colors.completion.fg = "#ddc7a1";
programs.qutebrowser.settings.colors.completion.odd.bg = "#282828";
programs.qutebrowser.settings.colors.completion.even.bg = "#1d2021";
programs.qutebrowser.settings.colors.completion.category.fg = "#e78a4e";
programs.qutebrowser.settings.colors.completion.category.bg = "#1d2021";
programs.qutebrowser.settings.colors.completion.category.border.top = "#1d2021";
programs.qutebrowser.settings.colors.completion.category.border.bottom = "#1d2021";
programs.qutebrowser.settings.colors.completion.item.selected.fg = "#ddc7a1";
programs.qutebrowser.settings.colors.completion.item.selected.bg = "#32361a";