Code Monkey home page Code Monkey logo

nh-darwin's Introduction

dependency status

nh_darwin

Because the name "yet-another-nix-helper" was too long to type...
Works on NixOS, NixDarwin, and HomeManager Standalone

Why fork?

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

What has been added?

  • nh_darwin 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_darwin os switch --update works when the flake is at /etc/nixos or in a root owned directory

What does it do?

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

build: passing

Installation

NixDarwin Module

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_darwin.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_darwin.url = "github:ToyVo/nh_darwin";
  };

  outputs = inputs@{ self, nix-darwin, nixpkgs, nh_darwin }:
  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_darwin.packages.${pkgs.stdenv.hostPlatform.system}.default;
        ];

      # Alias for nh_darwin
      environment.shellAliases.nh = "nh_darwin";

      programs.nh = {
        enable = true;
        clean.enable = true;
        # Installation option once https://github.com/LnL7/nix-darwin/pull/942 is merged:
        # package = nh_darwin.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_darwin.nixDarwinModules.default
      ];
    };

    # Expose the package set, including overlays, for convenience.
    darwinPackages = self.darwinConfigurations."simple".pkgs;
  };
}

NixOS module

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";
  };
}

FLAKE environment variable

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.

Specialisations support

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
  };
}

Hacking

Just nix develop. We also provide an .envrc for direnv.

nh-darwin's People

Contributors

viperml avatar toyvo avatar web-flow avatar notashelf avatar msfjarvis avatar henriquekirchheck avatar mrene avatar eclairevoyant avatar kapsikkum avatar gigamonster256 avatar eopb avatar starrfox avatar psfloyd 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.