Hi sailors,
The nix package manager can be installed on SailfishOS and serve as another vast source of applications (primarily cli programs). You can browse nixpkgs if it contains a program you need (it probably will).
Today, I successfully installed nix
on my Xperia 10iii with SailfishOS 4.4.0.72 Vanha Rauma (I know I should update, but my root partition is full and other stuff prevents me from updating right now…)
There is only one problem on SailfishOS that’s in the way: the comically small root partition. nix
needs the directory /nix
in the root of the file system. It is also notoriously space-hungry (think gigabytes, depending on what you do). While it is possible to enlarge the root partion, this might not be for everyone. Unfortunately, the /nix
dir must also not be a symlink to somewhere else. There is another way though, and that is to mount something unter /nix
that’s stored somewhere else. The least disruptive approach is to just make a filesystem on a single file and mount that under /nix
.
Note that you need to have
sudo
set up, something along this should do:devel-su;pkcon install sudo
, then add or uncomment the line%wheel ALL=(ALL) ALL
after runningvisudo
, add yourself to thewheel
group withusermod -aG wheel defaultuser
, then restart):
Here are the steps I took:
Prepare an image file for the Nix Store
# Make the 'truncate' command available
sudo pkcon remove busybox-symlinks-coreutils
sudo pkcon install gnu-coreutils
# create an empty file to hold the /nix filesystem tree
truncate -s 5G ~/.nix-store-image
Here I created it in the home directory, but you may well use your SD card (e.g. /run/media/defaultuser/*/.nix-store-image
) instead. Be aware that the SD card might not always be mounted.
The 5 gigabyte (-s 5G
) size might be too small. Adjust it to your needs and space. For me, /nix was 700M large after installation, but 1G was too small (df -h
).
# make a filesystem on our image file
sudo mkfs -t ext4 ~/.nix-store-image
We can now mount the image under /nix
:
# create the /nix folder
sudo mkdir /nix
# mount the image under /nix
sudo mount ~/.nix-store-image /nix
# make /nix belong to the defaultuser
sudo chown -R defaultuser:defaultuser /nix
Note: This mounting is not permanent and does not survive reboots. For this, it would need to be added to
/etc/fstab
or managed by systemd, but I haven’t set that up yet. For now, you will need to reexecute this after a reboot.
Installing Nix
We can now install nix
in single-user mode according to the official instructions:
sh <(curl -L https://nixos.org/nix/install) --no-daemon
This should only take a minute.
After reopening the terminal, you should now have the nix
command available in your shell:
> nix-shell -p cowsay --run 'cowsay Yay, nix on SailfishOS!'
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "de_DE.utf8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
_________________________
< Yay, nix on SailfishOS! >
-------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
There seems to be some locale issues though, setting LC_ALL=C.UTF-8
fixes it temporarily:
> LC_ALL=C.UTF-8 nix-shell -p cowsay --run 'cowsay Yay, nix on SailfishOS!'
_________________________
< Yay, nix on SailfishOS! >
-------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Using Nix
Nix may download a large amount (gigabytes) of data depending on what you install. Keep that in mind if you’re on mobile data!
To install packages, first search for the package name on https://search.nixos.org, then:
# Install tmux
nix-env -iA nixpkgs.tmux
# remove tmux again
nix-env -e tmux
# be dropped into a temporary shell with 'cowsay' available
nix-shell -p cowsay
# make some room in /nix
nix-collect-garbage # this removes nix-shell temporary stuff and keeps nix-env installed stuff
nix-channel --update # repopulate nixpkgs (necessary for some reason)
# If you run into weird errors like 'has bad meta.outputsToInstall', run the following and reinstall the last things you did
nix-env --rollback
If you messed something up, you can always just re-run the instsaller:
# reinstall nix again if something is missing
sh <(curl -L https://nixos.org/nix/install) --no-daemon
Flakes
Many online instructions for nix require you to have flakes enabled, this is how you enable them:
mkdir -p ~/.config/nix
echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf
Uninstalling nix again
# unmount /nix if necessary
sudo umount /nix
# remove the /nix directory
sudo rm -rf /nix
# remove your image file
sudo rm ~/.nix-store-image
Then have a look through your .bash_profile
or other shell startup config and remove nix-related stuff. But you can also leave that stuff in, it shouldn’t be harmful.
Cheers,
Yann (@nobodyinperson)