Background
I’ve been experimenting with NixOS and running Nix on macOS, and I’ve been documenting some of the problems and solutions I’ve encountered in the process.
NixOS
Global configuration
Global configuration paths for NixOS: /etc/nixos/configuration.nix
and /etc/nixos/hardware-configuration.nix
.
Apply the updated global configuration.
Updating major releases
If you want to update NixOS 21.11 to 22.05:
Consider changing or not changing system.stateVersion
in /etc/nixos/configuration.nix
.
Common configurations
Commonly used NixOS configurations.
|
|
Home Manager
Home Manager describes the program that users see by default, while NixOS is configured for all users.
Configuration files
Configuration file: ~/.config/nixpkgs/home.nix
Application configuration file.
|
|
Commonly used configurations
Commonly used Home Manager configurations.
Overriding Dependency Versions
Set the JDK version that the JVM program depends on.
The specific naming of parameters depends on the beginning of the corresponding package on nixpkgs.
Utilities
nixpkgs-fmt
nixpkgs-fmt is used to format Nix code.
search.nixos.org
search.nixos.org You can search for various packages on nixpkgs and also see the different platform support. The downside is that you can’t see if the packages are unfree or broken, and some darwin os-specific packages are not shown.
Packaging
It is easy to write default.nix
to package your project.
CMake
For a simple cmake program, you can write default.nix
in the following format: default.nix
.
You can use the nix-build
command to build, and the result will create a result
softlink in the current directory, which is the installation directory.
Since nix-build
also creates a build
directory, it is recommended to use a different name when developing to prevent conflicts.
Qt
For Qt projects, the implementation is a little more complicated because there are different big versions of Qt, so it has to be split into two files, first default.nix
: default.nix
.
Here it means compiling with qt5
, then when writing xxx.nix
, the libraries passed in such as qtbase
are the version of qt5
.
In actual testing, we found that the running program may report Could not initialize GLX
error, which can be solved by adding environment variables via wrapProgram
.
Development environment
In addition to packaging, the packages needed for the development environment are usually defined in shell.nix
.
Then you can use nix-shell
to enter the development environment. If you don’t want outside environment variables to be passed in, you can use nix-shell --pure
.