Giter VIP home page Giter VIP logo

mymacnix's Introduction

mymacnix

The purpose of this repository is to document my exploration of the way to set up Nix for my MacOS system on both my MacBook (personal) and my Mac Mini (family shared computer).

Introduction

I first learnt about Nix from watching tech videos on YouTube and that led me to learning about Nix, NixOS, nix-darwin, and the EXPERIMENTAL Flakes. The following are some of the important I had read before I decided on the current way of setting up Nix on my MacOS systems:

My goals of my Nix journey:

  • Study how easy it will be to reproduce a macOS-based setup on another brand new machine - especially in terms of setting up non-Microsoft tools.
  • Document the learning points during my journey.
  • Add relevant tools or script that I believe would help create reproducible macOS setup

Phase 1: Experimenting on MacOS VMs

Before I started messing with my actual MacOS setup, I first setup MacOS VMs to experiment. MacOS VMs can be setup via UTM - Securely run operating systems on your Mac.

After quite After quite a few tests, I finally decided to start setting up Nix on my MacBook with the "standard" way of setting up Nix on MacOS. This page documents what actually occurs on your MacOS system during the setup process.

Phase 2: Nix and its versions

Getting the version of Nix installed

nix --version

Getting the list of subscribed channels:

sudo nix-channel --list

Channels are something like Linux Debian apt sources - they point to where packages can be downloaded and installed.

The default subscribed channel is nixpkgs which by default points to https://nixos.org/channels/nixpkgs-unstable

When you install Nix via the "official" nixos install method, it uses the latest version you can find in the nix releases folder here.

But if you subsequently execute the command nix upgrade-nix, you may likely downgrade your Nix version. You can find out the version of the Nix you are "upgrading" to before running it by executing either of the following commands:

nix-env -qaA nixpkgs.nix

or

sudo nix upgrade-nix --dry-run

Follow these instructions to install a specific version of nix.

To find the actual latest version of Nix (outside of nixpkgs):

sudo nix-env --query nix 2>/dev/null

If you had accidentally ran the command:

sudo nix upgrade-nix

that would result in an older version of Nix being installed, you can force Nix back to the latest version by running the following command:

sudo nix upgrade-nix --nix-store-paths-url https://releases.nixos.org/nix/$(nix-env --query nix)/fallback-paths.nix

Why the messy Nix version issue

This was discussed in the Nix installer bug report - see grahamc's comment on 26 Nov 2023 for context. It seems that the nixpkgs maintenance team is "responsible" for deciding on the "safe" version of Nix to use when an upgrade is executed.

I am still not yet decided which is "safe" to use - but since the purpose of Nix is to be a package manager, then it may be best to start the experiment with using the nixpkgs team's recommendation of the safe version to use.

Uninstalling Nix

There is a series of complex steps for uninstalling Nix from MacOS. Because these steps require reboots and messing around with MacOS's daemons, I created an uninstall.sh script to automate this process so that it is easier to uninstall Nix correctly.

Phase 3: Decision time

Flakes

I first experimented with flakes because it was a very popular recommendation amongst many Nix enthusiasts. And it was also recommended by Determinate Systems, a company cofounded by Eelco Dolstra - the inventor of Nix.

I decided against using flakes for starting my Nix journey for the following reasons:

  • I felt that I could transition to flakes easily later
  • After installing the Determinate Systems installer, I tried to uninstall. But I found that there are some leftover folders and services that were not removed after uninstall.
  • The articles arguing against flakes
  • Parts of the Nix development community seem to be against it because of the lack of proper process in the manner it was adopted

nix-darwin

I have not delved too much into nix-darwin except to confirm that it does not require flakes. So, it is likely I would proceed with playing around with this project to see how it helps in reproducing a macOS setup with a "declarative system approach to macOS".

Phase 4: Creating my own install tools

I created auto-install scripts to install Nix and nix-darwin with minimal user intervention. These tools can now be installed by executing this command in the Terminal window:

sh <(curl -L https://raw.githubusercontent.com/khsoh/mymacnix/main/nix-autoinstall) [--install=nixonly] [--branch=<git-feature-branch>]

The --branch option can be use to test feature branches. The --install option can be used to stop to auto-install process at a Nix-only install

INTERLUDE AND UPDATE ON 12 JUN 2024

An important update on the learning journey. I discovered this important site nix.dev by the Nix documentation team to guide newbies in their Nix journey. It would have been good if I had started on my journey with this resource. But I believe my future learning would be best spent on this site.

As of today, I have managed to get installation to the point of setting up the most important tools and configurations for them:

  • home-manager
  • neovim
  • tmux
  • git
  • 1Password (CLI)

The only non-automated step I think I need to do now is to install 1Password GUI on the MAC because nix-darwin installs this in the /Applications/Nix Apps/ folder. But 1Password does not execute because it was not installed inside of /Applications/ folder (reference: 1Password doesn't work on Darwin/macOS #254944

Next steps

Next steps are:

  • Further investigation of 1Password
  • Investigate how to use agenix package for secrets management
  • Studying nix.dev to understand Nix better

mymacnix's People

Contributors

khsoh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.