Skip to content

Instantly share code, notes, and snippets.

View shiryel's full-sized avatar
🙀
> Insert another bug joke here <

Shiryel shiryel

🙀
> Insert another bug joke here <
  • SP, Brazil
View GitHub Profile
@shiryel
shiryel / nixos_fix.md
Last active May 3, 2022 23:59
How to solve all NixOS library problems

How to solve all nixos problems in 2 steps

(my new war crime)

STEP 1

Note: make sure to create the /lib dir before

# legacy way:
#gcc_path=$(nix eval nixpkgs.gcc-unwrapped.lib.outPath | tr -d '"')
@shiryel
shiryel / kubenv.sh
Last active March 15, 2022 21:39
Get all envs from kubernetes container (curated environment vars as export)
if [[ $# -lt 1 ]]; then
echo "Error: Needs at least the name of the pod"
echo "Example: ./kubenv.sh pod-name output-file.env"
exit 1
fi
pod_name=$1
output=${2:-"$1.env"}
# create the envrc from the pod envs
@shiryel
shiryel / git_email_change.md
Last active February 23, 2022 23:04
Git change email to allow signing correctly on old commits

Create an alias to simplify our lifes

git config --global alias.change-commits '!'"f() { VAR=\$1; OLD=\$2; NEW=\$3; shift 3; git filter-branch --env-filter \"if [[ \\\"\$\`echo \$VAR\`\\\" = '\$OLD' ]]; then export \$VAR='\$NEW'; fi\" \$@; }

Change the author and the committer emails on all commits

git change-commits GIT_AUTHOR_EMAIL "old@example.com" "new@example.com" -f -- --all
git change-commits GIT_COMMITTER_EMAIL "old@example.com" "new@example.com" -f -- --all
@shiryel
shiryel / keybase.md
Created February 23, 2022 02:10
Keybase proof

Keybase proof

I hereby claim:

  • I am shiryel on github.
  • I am shiryel (https://keybase.io/shiryel) on keybase.
  • I have a public key whose fingerprint is AB63 4CD9 3322 BD42 6231 F764 C404 1EA6 B326 33DE

To claim this, I am signing this object:

@shiryel
shiryel / bash_strict_mode.md
Created April 17, 2022 00:26 — forked from vncsna/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation

set -e, -u, -o, -x pipefail

The set lines

  • These lines deliberately cause your script to fail. Wait, what? Believe me, this is a good thing.
  • With these settings, certain common errors will cause the script to immediately fail, explicitly and loudly. Otherwise, you can get hidden bugs that are discovered only when they blow up in production.
  • set -euxo pipefail is short for:
set -e
set -u
@shiryel
shiryel / nix-ui.md
Created April 22, 2022 19:04 — forked from edolstra/nix-ui.md
Nix UI

General notes

  • nix-channel and ~/.nix-defexpr are gone. We'll use $NIX_PATH (or user environment specific overrides configured via nix set-path) to look up packages. Since $NIX_PATH supports URLs nowadays, this removes the need for channels: you can just set $NIX_PATH to e.g. https://nixos.org/channels/nixos-15.09/nixexprs.tar.xz and stay up to date automatically.

  • By default, packages are selected by attribute name, rather than the name attribute. Thus nix install hello is basically equivalent to nix-env -iA hello. The attribute name is recorded in the user environment manifest and used in upgrades. Thus (at least by default) hello won't be upgraded to helloVariant.

    @vcunat suggested making this an arbitrary Nix expression rather than an attrpath, e.g. firefox.override { enableFoo = true; }. However, such an expression would not have a key in the user environment, unlike an attrpath. Better to require an explicit flag for this.

TBD: How to deal with search path clashes.

@shiryel
shiryel / .ghci
Created June 6, 2022 16:22 — forked from rpearce/.ghci
Flake for using Haskell in nix develop
:def hoogle \x -> return $ ":!hoogle --count=15 \"" ++ x ++ "\""
:def doc \x -> return $ ":!hoogle --info \"" ++ x ++ "\""
:set -Wall
:set -fno-warn-type-defaults -ferror-spans -freverse-errors -fprint-expanded-synonyms
:set prompt "\ESC[0;32m%s\n\ESC[m[ghci]\ESC[38;5;172mλ \ESC[m"
:set prompt-cont " \ESC[38;5;172m> \ESC[m"
@shiryel
shiryel / flake.nix
Created June 16, 2022 07:00
Nix flake for Clang
{
description = "Clang Template";
inputs = {
nixpkgs_stable.url = "github:NixOS/nixpkgs/nixos-22.05";
flake-utils.url = "github:numtide/flake-utils/v1.0.0";
};
outputs = { self, nixpkgs_stable, flake-utils }:
flake-utils.lib.eachDefaultSystem
@shiryel
shiryel / setup.sh
Created July 6, 2022 23:02
simple encrypted disk with btrfs
# BASED_ON:
# https://wiki.archlinux.org/title/User:Altercation/Bullet_Proof_Arch_Install#Create_and_mount_BTRFS_subvolumes
# https://wiki.archlinux.org/title/Btrfs#Compression
# https://btrfs.readthedocs.io/en/latest/Administration.html?highlight=mount#mount-options
# https://grahamc.com/blog/erase-your-darlings
# download with:
# curl -L setup-disk.shiryel.com > setup.sh
# run with:
@shiryel
shiryel / nix_try_eval.patch
Last active May 29, 2024 22:51
Nixpkgs to JSON
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index bc253d0a3..e6c348d99 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -867,7 +867,7 @@ static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Va
state.forceValue(*args[0], pos);
attrs.insert(state.sValue, args[0]);
attrs.alloc("success").mkBool(true);
- } catch (AssertionError & e) {
+ } catch (EvalError & e) {