Giter Site home page Giter Site logo

nix-monitored's Introduction

nix-monitored

Pipe Nix through Nix Output Monitor without hassle.

Motivation

Everyone I know wants to have nom's pretty output, but no one I know remembers to put |& nom after every command. Further, nix-monitored can integrate with direnv and nixos-rebuild, which is difficult to do without overriding the Nix package.

Shouldn't this be a shell script / wrapProgram / etc.?

The reasons it is C++ rather than a shell wrapper are:

  • It runs on every Nix invocation, so overhead should be minimal.
  • Building C++ is trivial with stdenv.
  • Nix itself is written in C++, so it should be easier to maintain.
  • Bash is notoriously terrible with string / parameter manipulation. The first version of this wrapper was Bash, and I kept running into weird string splitting errors, despite using "$@".

Shouldn't this be upstreamed into Nix?

I don't think so.

The Nix project has a stated mission of having low a runtime and dependencies. That's why it was authored in C++ and not something more respectable like Haskell. This design goal makes Nix attractive in a wide range of applications, e.g. on embedded devices with limited resources.

Nix Output Monitor does not share this design goal, and is therefore more resource heavy. In fact introducing any kind of fanciness in the Nix CLI, even with C++ or Rust, would likely increase Nix' runtime and dependency footprint.

With a wrapper like this, we can have our cake and eat it too: Nix stays appreciably small, but we can still use Nix Output Monitor on developer workstations if we wish. It's a win-win.

Usage

On NixOS and nix-darwin, simply replace your nix.package, like so:

nix.package = pkgs.nix-monitored;

To make it work with nix-direnv and nixos-rebuild, we can override those packages:

nixpkgs.overlays = [
  (self: super: {
    nixos-rebuild = super.nixos-rebuild.override {
      nix = super.nix-monitored;
    };
    nix-direnv = super.nix-direnv.override {
      nix = super.nix-monitored;
    };
  })
];

If you're feeling adventurous, you can also simply try to override the Nix package entirely:

nixpkgs.overlays = [
  (self: super: {
    nix = super.nix-monitored.override {
	  inherit (super) nix;
    };
  })
];

A PR is in the works to bring this to NixOS as a module: NixOS/nixpkgs#207108.

Does it work?

The wrapper should work at least with the following tools:

  • nix commands on the CLI, with and without flakes
  • nix-direnv
  • nixos-rebuild

It's been tested on both NixOS and macOS.

nix-monitored's People

Contributors

lovesegfault avatar ners avatar rekk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

m-bdf krutonium rekk

nix-monitored's Issues

Apps don't run correctly

Currently nix-monitored converts nix run <flake-ref> to nix build <flake-ref> && nix run <flake-ref>. This breaks for flake apps outputs, where what we should actually build is <flake-ref>.program.

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.