Nix Notes: Overriding Haskell Packages

Setup

In one of the projects, I use a pinned version of nixpkgs based on miso. There are two advantages to that, one is that I know that miso builds with that version, and the second one is that I can take advantage of miso’s cachix cache and not compile everything from scratch.

In the most basic form, it looks like this.

File nixpkgs.nix:

let

  bootstrap = import <nixpkgs> {};

  misoTarball = bootstrap.fetchFromGitHub {
    owner = "dmjio";
    repo = "miso";
    rev = "2c193a3253216d70f0ac182fbe9c801de00363ae";
    sha256 = "1ywksdzcfd339x1hxp5pvkgbv9mdy1y0971k8v161hg33na2p8wz";
  };

  miso = import "${misoTarball}" { } ;

  inherit (miso) pkgs;

in miso.pkgs

I can then use it in another file to compile my local Haskell package named automation-server.

Read more...

Quick Haskell Trick

The Haskell REPL (Read Print Eval Loop) - GHC interpreter, ghci invoked with:

$ ghci

or:

$ stack repl

or:

$ cabal new-repl 

or:

$ cabal repl

is an environment enabling fast iteration.

You can test a particular function and that’s cool and all, but you can also run an entire program in the interpreter. You do that with:

ghci> :main

or

ghci> main

The flow is as follows:

  1. You make some changes in your editor
  • You :r or :reload
  • You make some more changes to make it compile
  • You :r again
  • You run :main to play around with your program
  • You Ctrl-C to kill the program
  • Go back to step one

What’s a little inefficient is that to run your new version of a program you have to issue two commands: :r and :main.

Read more...

Fixing Yakuake Shift+Tab

I upgraded my Ubuntu recently from 19.04 (Disco) to 19.10 (Eoan Ermine). At some point, I noticed that Shift+Tab stopped working in vim. I use nvim and have Tab configured to move to the next tab and Shift+Tab configured to move to the previous tab. Tab worked, Shift+Tab didn’t.

It’s two lines in my .vimrc:

nmap <Tab> :tabnext<enter>
nmap <S-Tab> :tabprev<enter>

Maybe it’s nvim?

At first, I suspected it’s a problem with nvim since I upgraded it as well and there is some old article mentioning how to get Shift+Tab to work. While old it provided some nice way of checking if vim has received the keys. If in insert mode you press Ctrl+V it tries to write the literal character of what you pressed into the file instead of interpreting it in some way. Again, for Tab it worked, and for Shift+Tab it didn’t.

Read more...

Repairing a Broken Multimeter

In December 2017 my multimeter broke. It no longer measured resistance correctly. For low resistances, the numbers looked alright, but with bigger resistances, the value didn’t go higher than about 40kΩ. I only had one multimeter, so I didn’t have anything to compare against, so how did I determine that it’s broken for sure?

It seemed to measure 1kΩ accurately, so I used Ohm’s Law and connected 10 of the 1kΩ resistors in series. It read about 7kΩ. Uh, oh.

I ordered a new one, same model. I complained to my friends on Facebook and got some pity likes. I didn’t know much about electronics, so I accepted that the old one is broken and only trusted the new one. Until it broke as well. In a similar way.

How did I break it? To be honest, I don’t know. I assume it was a user error. If I had to guess I either tried to measure the resistance on a powered circuit or tried to measure current with the red lead still in the Voltage/Resistance socket.

Last year I asked Santa for a different multimeter as I was tired of buying them myself. After learning some more electronics theory I decided to take a look and try to fix it.

Read more...

Why did no one tell me about gdb-add-index?

I’ve been exploring TensorFlow internals in the past couple of weeks.

Doing that required me to run some python scripts with a debug version of TensorFlow, set some breakpoints, examine some values, modify the script, repeat. You know, general sleuthing.

TensorFlow core functionality is written in C++. The python package is a wrapper around C++ code + libraries at the python layer. The way that python interacts with TensorFlow core is by loading a shared object.

Read more...

Debugging a Safe Module

TL;DR: change -XSafe to -XTrustworthy.

I’ve found myself needing to add some trace statements to System/Environment.hs. The module is marked Safe, so when you try to:

import Debug.Trace (trace)

you get the following error:

Debug.Trace: Can't be safely imported!
The module itself isn't safe.

I don’t know anything about Safe Haskell and I didn’t want to learn at the time. Removing {-# LANGUAGE Safe #-} made the Safe modules depending on System.Environment (the module I was trying to debug) fail to compile, so that wasn’t an option. Turns out you can just bypass this by marking your module as Trustworthy:

Read more...

A Hacky Way to Send Notifications From a Development Machine on iTerm2

When hacking on something in a language that’s compiled, some compiles take a long time. So long that it doesn’t make sense to wait and watch it. You can do some lightweight tasks in the meantime - respond to emails, review diffs… The problem is, unless you leave your terminal visible, you won’t know it’s done the moment it is done.

The solution is to send a notification once it’s compiled. This is not a new idea, iTerm2 has support for notifications from within a terminal via a special escape code. Problem solved? Kind of. If you only use iTerm2, then it works like a charm. But if you use a combination of iTerm2

Read more...