GithubHelp home page GithubHelp logo

abc-nix's Introduction

ABC Nix

How to do stuff with NixOS, for mere mortals like me, so I don't forget.

Stuff:

More stuff:

Add and remove packages from nixpkgs

System-wide

  1. As root, edit /etc/nixos/configuration.nix:

      environment.systemPackages = with pkgs; [
        abiword
        acpi
        alsaUtils
        ...
  2. Rebuild the system

    $ sudo nixos-rebuild switch

Update stuff

  1. Update the package stuff

    $ sudo nix-channel --update
  2. Rebuild with updated stuff

    $ sudo nixos-rebuild switch

Override a package

The Atom editor, in this case

The original package definition looks like this:

{ stdenv, fetchurl, buildEnv, makeDesktopItem, makeWrapper, zlib, glib, alsaLib
, dbus, gtk, atk, pango, freetype, fontconfig, libgnome_keyring3, gdk_pixbuf
, cairo, cups, expat, libgpgerror, nspr, gconf, nss, xorg, libcap, systemd
}:

let
  atomEnv = buildEnv {
    name = "env-atom";
    paths = [
      stdenv.cc.cc zlib glib dbus gtk atk pango freetype libgnome_keyring3
      fontconfig gdk_pixbuf cairo cups expat libgpgerror alsaLib nspr gconf nss
      xorg.libXrender xorg.libX11 xorg.libXext xorg.libXdamage xorg.libXtst
      xorg.libXcomposite xorg.libXi xorg.libXfixes xorg.libXrandr
      xorg.libXcursor libcap systemd
    ];
  };
in stdenv.mkDerivation rec {
  name = "atom-${version}";
  version = "1.0.4";

  src = fetchurl {
    url = "https://github.com/atom/atom/releases/download/v${version}/atom-amd64.deb";
    sha256 = "0jki2ca12mazvszy05xc7zy8nfpavl0rnzcyksvvic32l3w2yxj7";
    name = "${name}.deb";
  };

  buildInputs = [ atomEnv makeWrapper ];

  phases = [ "installPhase" "fixupPhase" ];

  installPhase = ''
    mkdir -p $out
    ar p $src data.tar.gz | tar -C $out -xz ./usr
    substituteInPlace $out/usr/share/applications/atom.desktop \
      --replace /usr/share/atom $out/bin
    mv $out/usr/* $out/
    rm -r $out/share/lintian
    rm -r $out/usr/
    patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      $out/share/atom/atom
    patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      $out/share/atom/resources/app/apm/bin/node
    wrapProgram $out/bin/atom \
      --prefix "LD_LIBRARY_PATH" : "${atomEnv}/lib:${atomEnv}/lib64"
    wrapProgram $out/bin/apm \
      --prefix "LD_LIBRARY_PATH" : "${atomEnv}/lib:${atomEnv}/lib64"
  '';

  meta = with stdenv.lib; {
    description = "A hackable text editor for the 21st Century";
    homepage = https://atom.io/;
    license = licenses.mit;
    maintainers = [ maintainers.offline ];
    platforms = [ "x86_64-linux" ];
  };
}

We'll upgrade the version of Atom to the latest, 1.0.19. As you can see, it's doing lots of fancy packaging stuff. I don't understand it and don't want to rewrite it, so we'll override just the parts we care about instead.

First, grab the tarball from github, and compute the sha256sum:

$ curl -L https://github.com/atom/atom/releases/download/v1.0.19/atom-amd64.deb | sha256sum

I get 77534b5c... -- note it, we'll need it later!

We'll edit ~/.nixpkgs/config.nix to override atom for our user account. We'll increment the version number, give it the new release url, and the sha256sum we just computed.

~/.nixpkgs/config.nix

with import <nixpkgs> {};

{
  packageOverrides = pkgs: rec {
    atom = let
      version = "1.0.19";
      name = "atom-${version}";
    in pkgs.stdenv.lib.overrideDerivation pkgs.atom (oldAttrs: {
      version = version;
      name = name;
      src = fetchurl {
        url = "https://github.com/atom/atom/releases/download/v${version}/atom-amd64.deb";
        sha256 = "77534b5c706cb2a80eb50ccd1271fcd9d4489ead954d4c08d1960371b8dcfcce";
        name = "${name}.deb";
      };
    });
  };
}

Line-by-line, what I've been able to figure out:

1 with import <nixpkgs> {}; puts some stuf in scope we need. I was getting errors about fetchurl not being defined until I added this.

4 packageOverrides = pkgs: rec { straight out of Modifying Packages on the wiki

5 atom = let I had to bind these variables in the let part of a let / in expression.

9 version = version; (and name) Puts the variables we bound into the record I guess?

11 src = fetchurl { Put in our new url and sha256sum for fetchurl

14 name = "${name}.deb"; Would be nice to leave this from the original, but I don't know how, so, copy-pasta.

With all that done, I can nix-env -i atom, and nix gets me Atom v1.0.19!

abc-nix's People

Contributors

uniphil avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.