4.6 KiB
How I use nix
In this article I'll explain how I use nix. I don't use NixOS nor any Linux as my main desktop environment1. Still I use nix on a few mac computers. It has multiple usages.
First, let's start by the bad news. Recent macOS security policy made nix a bit harder to install on a mac. See macOS Installation instructions.
Once you have nix installed you should update the nix-channel. Mainly a nix-channels is where are the definitions of all the packages. See nixOS documentation.
Home Manager
First, I use home-manager, it's first usage it to list a reproductible list
of application I need on all my desktop environments.
So i edit the file ~/.config/nixpkgs/home.nix
.
I provide a list of packages I want to have when I start a new shell.
home.packages = with pkgs; [
# nix
nix-prefetch-git
lorri
# emacs
emacsMacport
imagemagick
gnupg
# vim
neovim
# shell
direnv
fasd
fd
findutils
fortune
gawk
git
gitAndTools.diff-so-fancy
graphviz
htop
httpie
jq
jwt-cli
libressl
mustache-go
pandoc
ripgrep
rtv
wakatime
xpdf # pdftotext
yadm
youtube-dl
# clojure
leiningen
boot
adoptopenjdk-bin
joker
# Haskell
ghc
cabal-install
(all-hies.selection
{ selector = p:
{ inherit (p) ghc865; };})
# Common LISP
sbcl
# mails
offlineimap
notmuch
msmtp
gmailieer
# docker
docker-compose
# weechat
rel20weechat
aspell
aspellDicts.en
aspellDicts.fr
];
There are a few noticiable artifact here:
The first one is rel20weechat
is a very specify build of weechat with the
plugin I need. So here is the block I use:
rel20 = import (fetchGit {
name = "nixpkgs20";
url = "https://github.com/NixOS/nixpkgs";
# obtained via
# git ls-remote https://github.com/NixOS/nixpkgs nixpkgs-20.03-darwin
ref = "refs/heads/nixpkgs-20.03-darwin";
rev = "58f884cd3d89f47672e649c6edfb2382d4afff6a";
}) {};
rel20weechat = rel20.weechat.override {
configure = { availablePlugins, ... }: {
# plugins = with availablePlugins; [ python perl guile ];
scripts = with pkgs.weechatScripts; [ wee-slack ];
};
};
First rel20
pin a nixpkgs some specific commit of nix packages.
Second, I overriden the default packages of the weechat
package.
Another interresting one is this block:
let
...
rel19 = import (fetchGit {
name = "nixpkgs19";
url = "https://github.com/NixOS/nixpkgs";
ref = "refs/heads/nixpkgs-19.09-darwin";
rev = "2f9bafaca90acd010cccd0e79e5f27aa7537957e";
}) {};
haskellDeps = ps: with ps; [
base
protolude
tidal
shake
rel19.haskellPackages.sws
];
ghc = pkgs.haskellPackages.ghcWithPackages haskellDeps;
...
in
home.packages = with pkgs; [
...
ghc
...
]
So it means I want to install ghc
the main Haskell compiler.
But also with some specific haskell packages.
The interresting part, is that in most classical OS environment if you want
a package from a specific language platform.
You need to install the package manager for this language (npm, pip,
etc…).
And in nixpkgs
there are formulae for most of these language specific
packages.
So instead of just installing cabal-install
and then installing the
packages I need.
Which could also go bad, because they might be upgraded and not be
compatible all at the same time.
I used nix to install the packages I needed.
And one interresting detail.
One package sws
is broken in 20.03 on darwin.
So I used the older version from 19.09.
1: I'm using macOS, and I have multiple macs. A laptop and two desktop machines. Using the 27" iMac is my ultimate work station. It really enhance my productivity. Still the laptop is a superior work environment for more casual tasks. I guess I might write someday about my full work environment.