10.4 C
London
Sunday, February 11, 2024

use Nix on macOS


Nix OS



The Mac has a number of third-party package deal managers for putting in further software program. This is find out how to use the Nix package deal supervisor with macOS.

What’s Nix?

Nix is a package deal supervisor that gives container-based growth environments throughout platforms. Just like container methods equivalent to Docker and Kubernetes, Nix lets you set up configured growth environments throughout machines and networks with much less configuration and bother.

Historically on the Mac, customers used both MacPorts or Homebrew to put in third-party packages. Each methods have advantages and disadvantages.

Homebrew has been standard within the Mac group due to its ease of use and set up: packages will be put in from the Terminal app in macOS with just some instructions, and updates are automated and simply as straightforward.

Nevertheless, each Homebrew and MacPorts lack portability throughout machines. You’ll be able to write Terminal (shell) scripts to put in Homebrew or MacPorts packages throughout methods, however script upkeep can grow to be advanced and sometimes it is troublesome to put in writing scripts which might be conscious of all attainable machine configurations.

Nix solves this by containerizing growth environments and making them extra moveable throughout methods.

The tradeoff value you pay with Nix is a barely extra advanced configuration – and a steeper studying curve.

Nix ecosystem

NixOS from the NixOS Basis is definitely a number of issues: it is a Linux distribution that makes use of the Nix package deal supervisor. Nixpkgs is a set of over 80,000 packages that may be put in utilizing the Nix package deal supervisor.

There are three separate manuals for Nix: the Nix Handbook, the Nixpkgs Handbook, and the NixOS Handbook.

There’s additionally a Nix Reference Handbook.

A community-maintained unofficial NixOS Wiki is on the market and a Nix growth website is situated at nix.dev. The NixOS Wiki has data on the package deal supervisor, the Nix language, Nixpkgs, and NixOS itself.

There’s additionally a Nix Language you should utilize to create and duplicate components of packages for brand new installations.

You will in all probability wish to learn the whole Nix Handbook no less than earlier than you start putting in and utilizing Nix.

Manuals for 'Nix,' 'Nixpkgs,' and 'NixOS'.

Nix documentation.

Definitions

There are just a few new phrases you may want to know to make use of Nix.

Nix is predicated on declarative programming – creating applications based mostly on describing what a chunk of software program is meant to do fairly than find out how to do it. Lengthy story quick, declarative programming tries to keep away from software program based mostly on state and altering state to realize some final result.

Expressions. Nix expressions are mainly subcomponents of installable software program which might be predefined for later retrieval and set up. The thought with expressions is the part is already outlined in order that when it’s put in, it really works the identical means throughout all methods.

Every expression additionally has a search path.

Channels. A Nix channel is a selected path to a number of predefined Nix expressions that may be remotely retrieved and put in. There’s a listing of official channels at channels.nixos.org.

Most channels have variations. A channel will also be subscribed or unsubscribed.

Every channel has downloadable content material which will get put in when the channel is put in.

Retailer. Not like Homebrew and UNIX itself, Nix would not set up packages into the usual UNIX directories equivalent to /usr, /bin, /sbin, or /choose.

As an alternative, it creates its personal retailer – a particular listing and quantity used to retailer all put in packages. Through the use of a retailer, Nix packages are far more moveable as a result of the whole retailer will be moved as a unit.

Nix does set up a configuration file into /and many others/nixos/configuration.nix, which is often invisible except you activate macOS Finder’s hidden recordsdata characteristic.

Flakes are an experimental Nix characteristic that are recordsdata used to outline and management the dependencies amongst packages. Though standard, Nix flakes are nonetheless experimental and missing sturdy documentation so use them at your individual danger.

Rubbish assortment. As in some programming environments, once you take away a Nix package deal it would not truly get uninstalled immediately. To do this you run the Nix Rubbish Collector.

Consider a rubbish collector as a course of that runs silently within the background, one which cleans up any unused or stale elements which might be now not wanted.

Many fashionable methods use rubbish collectors – together with the Java VM, and the Swift and Goal-C runtimes from Apple.

You’ll be able to invoke the Nix rubbish collector any time after set up in Terminal with:

The Nix set up consists of a number of command-line instruments (CLI) you’ll be able to run from the Terminal app. These embody:

  1. nix-env – used to govern Nix consumer environments
  2. nix-build – used to construct Nix expressions
  3. nix-shell – an interactive command setting based mostly on a Nix expression
  4. nix-store – manipulate or question the Nix retailer

All these instructions and extra are detailed within the Nix Handbook.

A Nix consumer setting is solely a set of software program and instruments put in by Nix.

Putting in Nix

Nix usually installs to /nix however since macOS Catalina, the foundation of the macOS Startup Disk is read-only.

As an alternative, on post-Catalina methods, Nix will create a brand new quantity to carry the Nix retailer and mount it as a quantity within the hidden macOS folder Volumes on the root of the Startup Disk.

If you happen to do have admin entry, the installer will immediate you for sudo (superuser) permission once you run it so as to create the brand new quantity.

To run the interactive Nix installer in Terminal, kind:

curl -L https://nixos.org/nix/set up | sh

When the installer runs, it provides you a brief message about what it’s about to do and the place issues will probably be put in. It additionally creates a brand new UNIX consumer and UUID for the consumer – that are used throughout Nix container and package deal builds.

The Nix installer shops a reference to the Nix retailer quantity in /and many others/fstab.

Word the Nix retailer quantity mounts, however not on the Finder’s desktop – you will not see it in your Mac’s Desktop nevertheless it’s nonetheless there nonetheless.

As an alternative, Nix mounts it on the root of your Startup Disk in a listing named “Nix Retailer”. Within this listing, there is a retailer and a var folder.

The retailer folder accommodates all of the packages and channels NIX downloaded and put in, the var folder accommodates a log folder, and the nix folder which accommodates the DB, profiles, a connection to the background daemon, the consumer swimming pools and different components.

NIX store volume mounted in macOS's Startup Disk.

The NIX retailer quantity on the root of the Startup Disk.

fstab is the File System Desk file which tells UNIX the place all of the filesystems and their volumes stay.

When you find yourself able to proceed with the installer, enter an admin password in Terminal and press Return.

You will see the Nix installer run and because it does it can describe what it’s creating.

If the Nix put in has sudo entry, it can additionally attempt to add some configuration choices to the hidden consumer profile recordsdata in your Mac’s startup disk within the consumer and and many others folders, specifically:

/and many others/bashrc /and many others/profile.d/nix.sh /and many others/zshrc /and many others/bash.bashrc /and many others/zsh/zshrc

These profile recordsdata get loaded by macOS once you log in they usually comprise setting variables and paths to put in software program.

Lastly, the Nix installer units up a background course of, or daemon named nix-daemon which manages the Nix retailer within the background silently.

As soon as the installer finishes, you may both have to stop Terminal and re-open it, or else open a brand new Terminal shell to ensure that Terminal to load all the brand new Nix configurations.

After the installer finishes you’ll be able to initialize the default Nix packages and take a look at the Nix set up in Terminal with:

nix-shell -p nix-info --run "nix-info -m"

You must see a message about fetching paths after which a listing of all of the packages put in within the native Nix retailer.

On the backside of the message, you must see the present Nix and Darwin model quantity, channel identify, and the trail to the packages profile file.

You can too manually set up any current Nix package deal in Terminal through the use of the nix-env --install command adopted by the package deal identify. For instance:

nix-env --install firefox

Bundle uninstallation is similar, besides you employ the --uninstall flag to the nix-env command

Further sources

There are a number of good third-party Nix websites obtainable – make sure to examine them out.

Zero-to-nix.com is a information to utilizing Nix and features a Fast Begin and a Ideas part which supplies a great overview of every a part of Nix and the way they match collectively.

Determinate.methods is a Nix-centric website that accommodates many Nix tutorials in addition to a standalone Nix installer in case you do not wish to use the Terminal-based set up.

The Nix and Flakes Guide from Ryan Yin is a web-based tutorial and GitHub repo for inexperienced persons stuffed with helpful Nix-related data.

The nix-darwin repo accommodates all of the modules, packages, and documentation for the Darwin (macOS) port of the Nix package deal supervisor.

Nixpacks is a utility that may take any listing of recordsdata and containerize it for reuse.

Nix execs and cons

When you get previous the training curve, Nix will be fairly efficient and helpful. The power to configure and reinstall moveable containers throughout methods could be very highly effective.

You’ll be able to configure any set of environments and instruments, after which package deal it for redeployment on most methods.

The power to create your individual customized Nix packages and containers which might then be reused saves a whole lot of time at any time when you must configure a brand new machine.

The principle draw back of Nix as a package deal supervisor is elevated complexity and its studying curve. There additionally presently isn’t any Home windows model.

Homebrew continues to be less complicated than Nix, however apart from writing your individual customized shell scripts for set up, Homebrew lacks portability. Attempting to put in writing customized set up shell scripts for each attainable system is impractical.

When you be taught and grasp Nix, it can grow to be a robust instrument in your growth arsenal.

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here