this fork is winding down, nix darwin is now supported with v4.0.0 of upstream nh
The original owner is unwilling to pull in changes to support darwin because they don't have a mac to be able to
maintain support viperML#67 & viperML#97
support has been added upstream with 4.0.0
nh os switch
works on nix-darwin- nixDarwinModules.default is similar to the nixosModule for nix.gc and programs.nh.clean
- Use this fork of nh in nixDarwinModules.default and nixosModules.default
- When $FLAKE isn't defined, default to
/etc/nixos
nh os switch --update
works when the flake is at/etc/nixos
or in a root owned directory
NH reimplements some basic nix commands. Adding functionality on top of the existing solutions, like nixos-rebuild, home-manager cli or nix itself.
As the main features:
- Tree of builds with nix-output-monitor
- Visualization of the upgrade diff with nvd
- Asking for confirmation before performing activation
This fork defines a nixDarwin module inspired by the nixosModule and the nixDarwin nix gc module
This PR adds a nixDarwin module to nixDarwin itself LnL7/nix-darwin#942
and once that is pulled in and before I update my nixDarwin module, they will conflict, in which case you
can manually override programs.nh.package = inputs.nh_plus.packages.${pkgs.stdenv.hostPlatform.system}.default;
Once that PR is pulled in I will update my nixDarwin module similarily to the nixos module in which case will then be able to choose between importing the module from this repo or just overriding the package
Example NixDarwin Flake
{
description = "Example Darwin system flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nix-darwin.url = "github:LnL7/nix-darwin";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
nh_plus.url = "github:ToyVo/nh_plus";
};
outputs = inputs@{ self, nix-darwin, nixpkgs, nh_plus }:
let
configuration = { pkgs, ... }: {
# List packages installed in system profile. To search by name, run:
# $ nix-env -qaP | grep wget
environment.systemPackages =
[ pkgs.vim
# Always an option
# nh_plus.packages.${pkgs.stdenv.hostPlatform.system}.default;
];
programs.nh = {
enable = true;
clean.enable = true;
# Installation option once https://github.com/LnL7/nix-darwin/pull/942 is merged:
# package = nh_plus.packages.${pkgs.stdenv.hostPlatform.system}.default;
};
# Auto upgrade nix package and the daemon service.
services.nix-daemon.enable = true;
# nix.package = pkgs.nix;
# Necessary for using flakes on this system.
nix.settings.experimental-features = "nix-command flakes";
# Create /etc/zshrc that loads the nix-darwin environment.
programs.zsh.enable = true; # default shell on catalina
# programs.fish.enable = true;
# Set Git commit hash for darwin-version.
system.configurationRevision = self.rev or self.dirtyRev or null;
# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 4;
# The platform the configuration will be used on.
nixpkgs.hostPlatform = "x86_64-darwin";
};
in
{
# Build darwin flake using:
# $ darwin-rebuild build --flake .#simple
darwinConfigurations."simple" = nix-darwin.lib.darwinSystem {
modules = [
configuration
# Primary installation option:
nh_plus.nixDarwinModules.default
];
};
# Expose the package set, including overlays, for convenience.
darwinPackages = self.darwinConfigurations."simple".pkgs;
};
# Binary cache so you don't have to build yourself, builds for aarch64 and x86_64, linux and darwin.
nixConfig = {
extra-substituters = [
"https://toyvo.cachix.org"
];
extra-trusted-public-keys = [
"toyvo.cachix.org-1:s++CG1te6YaS9mjICre0Ybbya2o/S9fZIyDNGiD4UXs="
];
};
}
This fork has a nixos module that simply sets programs.nh.package to this fork
The NixOS module has some niceties, like an alternative to nix.gc.automatic
which also cleans XDG profiles, result and
direnv GC roots.
{ config, pkgs, ... }:
{
programs.nh = {
enable = true;
clean.enable = true;
clean.extraArgs = "--keep-since 4d --keep 3";
flake = "/home/user/my-nixos-config";
};
}
nh uses the FLAKE
environment variable as the default flake to use for its operations. This can be configured by
whichever method you want,
or use the programs.nh.flake
NixOS option.
nh is capable of detecting which specialisation you are running, so it runs the proper activation script.
To do so, you need to give nh some information of the spec that is currently running by writing its name to
/etc/specialisation
. The config would look like this:
{config, pkgs, ...}: {
specialisation."foo".configuration = {
environment.etc."specialisation".text = "foo";
# ..rest of config
};
specialisation."bar".configuration = {
environment.etc."specialisation".text = "bar";
# ..rest of config
};
}
Just nix develop
. We also provide an .envrc
for direnv.