From 46f394fa474b46b09385a61871fa62ddbd6bf218 Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Mon, 12 Sep 2022 18:09:21 +0200 Subject: [PATCH] Published nix article --- content/rambles/nix-on-other-distros.md | 79 +++++++++++++++++++++---- themes/vugo | 2 +- 2 files changed, 67 insertions(+), 14 deletions(-) diff --git a/content/rambles/nix-on-other-distros.md b/content/rambles/nix-on-other-distros.md index 8c290e9..3c01cc4 100644 --- a/content/rambles/nix-on-other-distros.md +++ b/content/rambles/nix-on-other-distros.md @@ -4,10 +4,9 @@ date: "2022-09-12T11:37:11+02:00" author: "$HUMANOID" tags: ["technology", "linux"] description: "A guide on installing the Nix packagemanger on Alpine and Debian" -draft: false --- -# A Few Problems +# Introduction The Nix package manager is an amazing tool that allows you to manage your packages through a purely functional environment. I'm not going to get into why it's amazing or how it really works in this article. @@ -20,17 +19,17 @@ From there it requires sudo privileges to install the package manager itself. This sets of a load of alarm bells in terms of security and what it's going to do from there. As the Nix package manager is packaged for both Debian and Alpine, my two favourite distros next to NixOS, there is no real reason _not_ to use their respective package managers. -When you try to install Nix on Alpine you also get the warning that it only supports systemd and that you're on your own when it comes to getting it to work on any other init systems. -This problem is fixed in the Alpine pacakge. +When you try to install Nix on Alpine using the aforementioned installation script you also get the warning that it only supports systemd and that you're on your own when it comes to getting it to work on any other init system (Alpine uses OpenRC). +This problem is fixed in the Alpine package. Then there is also the benefit of of being able to remove it with either `apt autoremove --purge nix-setup-systemd` or `apk del nix` instead of having to run said same script a second time. Yes, I'm aware that you don't _have_ to curl the script directly into `sh` and that you can download it to your local system to see what it's actually doing. But that doesn't take away from the fact that the official instructions tell you to perform an inherently insecure set of actions by trusting what is effectively a random script on the internet. -## Basics +# Installation Process -### Package Installation +## Package Installation The first step is to install the package itself. On Debian this is done with: @@ -40,16 +39,16 @@ sudo apt install nix ``` On Alpine, you first have to add the "testing" repo. -This is part of the `edge` branch. -As far as I know, you _could in theory_ get away with just adding the "testing" repo and not moving the rest of your system over to `edge`, but I highly doubt that will do any good for the stability of your system. +This is part of the edge branch. +As far as I know, you _could in theory_ get away with just adding the "testing" repo and not moving the rest of your system over to edge, but I highly doubt that will do any good for the stability of your system. -Moving your system over to the `edge` branch is done by opening `/etc/apk/repositories`, uncommenting the mirrors referring `edge` in the and commting out the lines referring to (at time of writing) `3.16`. +Moving your system over to the edge branch is done by opening `/etc/apk/repositories`, uncommenting the mirrors referring edge in the and commenting out the lines referring to (at time of writing) `3.16`. From there, run... ```sh doas apk -U upgrade ``` -...to move your system over to `edge`. +...to move your system over to edge. Now installing Nix can be done as usual with: ```sh @@ -58,7 +57,7 @@ doas apk add nix This will install the required binaries and the Nix daemon. -### Starting the Daemon +## Starting the Daemon On Debian the Nix daemon is enabled by default. To make sure it's running and enabled, run: @@ -81,6 +80,60 @@ Starting it is then done using: doas rc-service nix-daemon start ``` -### Groups +## Groups -Next step is to add your account to the correct group. +Next step is to add your account to the `nix` group. + + +On Debian this can be done with: +```sh +sudo usermod -aG nix $USER +``` + +And on Alpine this can be done with: +```sh +doas addgroup $USER nix +``` + +## Environment variables + +The last step is to set a few environment variables. +I have the following in my `.profile` + +```sh +# nix +export PATH=$PATH:$HOME/.nix-profile/bin +export NIX_PATH=$HOME/.nix-defexpr/channels:/nix/var/nix/profiles/per-user/root/channels${NIX_PATH:+:$NIX_PATH} +``` + +Now source your `.profile` again, either using... +```sh +source ~/.profile +``` +...or by logging out and back in again. + +## Adding a channel + +Now you have a functioning Nix package manager configuration and all that remains to be done is adding and syncing the repo. + +The Alpine package defaults to adding the `unstable` channel. +Debian doesn't add any channels at all. +This can be verified with: +```sh +nix-channel --list +``` + +To add the unstable channel to your channels, run the following command: +```sh +nix-channel --add https://nixos.org/channels/nixpkgs-unstable +``` + +You can probably also add stable channels, but I haven't tried that, as one of the reasons I want to use the Nix package manager on other distros than NixOS is for it's newer packages. +(I am aware that the stable channel of NixOS is a lot newer than the Debian stable branch, which is precisely why I don't want to to be my base system on machines where I have Debian installed.) + +## Syncing channels + +To sync your (just added) channel(s), run: +```sh +nix-channel --update +``` diff --git a/themes/vugo b/themes/vugo index 769d3a4..3e3d1a3 160000 --- a/themes/vugo +++ b/themes/vugo @@ -1 +1 @@ -Subproject commit 769d3a4e90d78fd6f141bfe7233b283851fc6740 +Subproject commit 3e3d1a397bb23f881920d3cb9cf6f784cc750831