- Just like NixOS, it supports declarative reproductible system configurations using home-manager.
- Install packages at user level without having to change system state.
- SELinux is currently unsupported. You need to disable it.
- Primary used on systemd but can be used on other init systems. You will have to enable the nix daemon manually.
Nix
Home-Manager
This command will install the Nix Package Manager on your system. More information can be found here. When prompted, allow the installer to use root priviliges and to set up Nix as a Multi User.
$ sh <(curl -L https://nixos.org/nix/install)
If you just want to use the Nix Package Manager, great, you are done. You can install new packages using the command below. Available packages can be found here:
$ nix-env -iA nixpkgs.<package name>
$ nix-shell -p <package name>
A couple more useful commands:
$ nix-env --uninstall <package name>
$ nix-env -q
$ nix-env --upgrade
If you would also like to configure these packages using their options, it’s recommended that you keep reading.
- Remove undeclared packages, dependencies and symlinks:
$ sudo nix-collect-garbage -d
- Home-manager can be installed by using the commands below:
As a user
- Add the channel:
$ nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
$ nix-channel --add https://github.com/nix-community/home-manager/archive/release-21.11.tar.gz home-manager
$ nix-channel --update
- Just to be sure, relog.
- If installation give NIX-PATH errors
$ sudo nix-collect-garbage -d
$ export NIX_PATH=$HOME/.nix-defexpr/channels:/nix/var/nix/profiles/per-user/root/channels${NIX_PATH:+:$NIX_PATH}
- Installation:
$ nix-shell '<home-manager>' -A install
- Configuration file:
$ cd ~/.config/nixpkgs/home.nix
- Home-Manager Options
$ man home-configuration.nix
home.packages = with pkgs; [
firefox
];
services.dunst = {
enable = true;
};
$ home-manager switch
- Flakes are an “upcoming feature” of the Nix package manager.
- Specify code dependencies declaratively (will be stored in flake.lock)
- For example: home-manager
- Rebuilding and updating whole system made easy
- Very useful tool to build your own config
- Multiple configs in one
- People with github dotfiles will feel right at home
Allowing experimental features such as flake to be installed
$ mkdir -p ~/.config/nix $ echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
This command will generate a flake.nix and flake.lock file
cd
into a location to store in your system$ nix flake init
{
description = "A very basic flake";
outputs = { self, nixpkgs}: {
packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
};
}
attribute set of all the dependencies used in the flake
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nixgl = {
url = "gihub:guibou/nixGL";
inputs.nixpkgs.follows = "nixpkgs";
};
};
function of an argument that uses the inputs for reference
- Configure what you imported
- Can be pretty much anything: Packages / configurations / modules / etc…
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, home-manager, ...}: {
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in
homeConfigurations = {
"<host>" = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
extraSpecialArgs = { inherit inputs; };
modules = [
./<path.nix>
{
home = {
username = "<user>";
homeDirectory = "/home/${user}";
packages = [ pkgs.home-manager ];
stateVersion = "22.05";
};
}
];
};
#"<second host>" = home-manager.lib.homeManagerConfiguration {
# pkgs = nixpkgs.legacyPackages."x86_64-linux";
# extraSpecialArgs = { inherit inputs; };
# modules = [
# ./<path.nix>
# {
# home = {
# ...
};
};
This is only for those who don’t have nix-darwin installed and have an existing flake they want to install on a fresh system If this is not your situation, move on to rebuild
- For the first initial installation it recommended that your use
$ nix build
- The location of
/result
depends on what location you are building from. It’s maybe recommended that your build inside the flake.
$ cd <flake> $ nix build .#homeConfigurations.<host>.activationPackage $ ./result/activate
- After the first installation, you don’t need to target
/activate
inside/result
$ home-manager
is now installed and can be used from anywhere. Example:/HOME/<USER>/ $ home-manager switch --flake <flake path>#<host>
- Full guide
- Commands are based on a systemd distribution, but I guess can be modified for your distro of choice.
$ sudo systemctl stop nix-daemon.socket $ sudo systemctl stop nix-daemon.service $ sudo systemctl disable nix-daemon.socket $ sudo systemctl disable nix-daemon.service $ sudo systemctl daemon-reload
- reboot