DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Nix as an OS X Package Manager

Nix as an OS X Package Manager

Linux users have long enjoyed package management and its useful grasp of dependencies. Nix is a tool now available on OSX, which translates some of the simplicity of *nix-style management.

Ariya Hidayat user avatar by
Ariya Hidayat
·
May. 31, 16 · Tutorial
Like (2)
Save
Tweet
Share
6.96K Views

Join the DZone community and get the full member experience.

Join For Free

power users on os x are familiar with homebrew or macports for installing and managing software packages conveniently. yet, those two well-known tools are not the exclusive players. there is a growing interest in nix , particularly for its use on os x.

package management using nix is quite simple and intuitive. it does work quite well to replace homebrew and macports. to get started, install nix following the instructions :

curl https://nixos.org/nix/install | sh

nix only needs access to /nix , it does not touch any other top-level directories (nix will never pollute your /usr or /usr/local ). hence, removing nix is a matter to nuking that /nix directory.

once it is installed, the main command-line tool you will interact the most will be nix-env . try installing a trivial package like this:

$ nix-env -i hello
installing ‘hello-2.10’
these paths will be fetched (0.02 mib download, 0.07 mib unpacked):
 /nix/store/b6bxihaz9s5c79dsgbbxvjg8w44a036i-hello-2.10
fetching path ‘/nix/store/b6bxihaz9s5c79dsgbbxvjg8w44a036i-hello-2.10’...
$ hello --version
hello (gnu hello) 2.10

note the installation path, a peculiar subdirectory under /nix/store . the name contains the cryptographic hash of all inputs necessary to build the package, essentially capturing the complete build dependencies. this enables powerful nix features such as easy handling of multiple package versions, atomic installation, and many more.

nix also creates a profile for every user, which you once you search for an executable (the importance of nix profile itself will be more obvious once you start to be more familiar with nix).

$ which hello
/users/ariya/.nix-profile/bin/hello

removing a package is as easy as installing it:

$ nix-env -e hello
uninstalling ‘hello-2.10’

in many cases, nix will install a package in its binary form (as built and cached by the hydra-based build farm).

packages

wondering what you can install with nix? well, nix’s collection of packages (especially on os x, around seven thousand) is not as impressive as homebrew and macports. yet, you may find the common packages already available, from git to vim (and its plugins). to list all available packages:

just like every package manager, nix is also useful to upgrade your arsenal of tools. for instance, os x el capitan is armed with git 2.6 by default. but perhaps you want to use the most recent git 2.8 instead. this is not a difficult endeavor:

$ git --version
git version 2.6.4 (apple git-63)
$ nix-env -i git
warning: there are multiple derivations named ‘git-2.8.0’; using the first one
installing ‘git-2.8.0’
$ which git
/users/ariya/.nix-profile/bin/git
$ git --version
git version 2.8.0

later on, if you decide that you don’t like the latest version and you prefer to stick with the default one, the rollback leaves no meaningful left-over and it returns the state of the system exactly before you installed git 2.8:

$ nix-env -e git
uninstalling ‘git-2.8.0’
$ which git
/usr/bin/git
$ git --version
git version 2.6.4 (apple git-63)

these package management tasks are not unique to nix. wait for the sequel of this post, where we learn the power of nix to comfortably handle multiple environments (e.g. python 2.7 vs python 3.5).

Package manager

Published at DZone with permission of Ariya Hidayat, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • SAST: How Code Analysis Tools Look for Security Flaws
  • 3 Ways That You Can Operate Record Beyond DTO [Video]
  • How To Get Page Source in Selenium Using Python
  • Streamlining Your Workflow With the Jenkins HTTP Request Plugin: A Guide to Replacing CURL in Scripts

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: