Skip to content

Instantly share code, notes, and snippets.

View ryantrinkle's full-sized avatar

Ryan Trinkle ryantrinkle

View GitHub Profile
{ runCommand, patchelf, coreutils, binutils-unwrapped, find-libs }:
targetPrefix: inputPackage:
runCommand (inputPackage.pname + "-portable") {
inherit inputPackage targetPrefix;
} ''
set -euo pipefail
cp -a "$inputPackage" "$out"
let # invert is O(n^2); it's not obvious to me that we can do much better without a lot of work
# invert :: Map a [b] -> Map b [a]
invert = m:
let allBs = builtins.concatLists (builtins.attrValues m);
exploded = builtins.concatMap (a: map (b: { ${b} = a; }) m.${a}) (builtins.attrNames m);
in builtins.listToAttrs (map (b: { name = b; value = builtins.catAttrs b exploded; }) allBs);
# Given a package that installs .desktop files in the usual location,
# return a mapping from mime types to lists of desktop file names.
# This is suitable for use in home-manager's
# xdg.mimeApps.defaultApplications.
@ryantrinkle
ryantrinkle / Control.Monad.ExceptionsToErrors.hs
Created December 2, 2024 18:37
New Workflow monad for Reflex
{-# LANGUAGE UndecidableInstances #-}
module Control.Monad.ExceptionsToErrors where
import Control.Exception
import Control.Monad.Except
import Data.Proxy
import Data.Reflection
import GHC.IO (mkUserError)
-- | This is a monad that translates all IO-style synchronous exceptions into exceptions in ExceptT