nix example.nix

example.nix
with import <nixpkgs>{}; runCommand "shell" { buildInputs = [
(haskellPackages.ghcWithHoogle (h: with h; [
      diagrams
      diagrams-gtk
      lens
      io-memoize
      haskeline
      pointfree
      xmonad
      xmonad-contrib
      xmonad-extras
      happy
      alex
      gloss
      matrix
    ]))
]; } "exit 1"

nix example.nix

example.nix
with import <nixpkgs> {};

let
  openscenegraph' = openscenegraph.overrideAttrs (old: {
    name = "OpenSceneGraph-3.4.0";
    src = /root/OpenSceneGraph-3.4.0.zip;
  });
in stdenv.mkDerivation {
  name = "example";
  buildInputs = [ cmake mesa openscenegraph' pkgconfig ];
}

nix cmake的例子

cmake的例子

default.nix
with import <nixpkgs> {};

stdenv.mkDerivation {
  name = "fixme";
  src = fetchurl {
    url = "http://example.com/fixme.tar.gz";
    sha256 = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08";
  };
  buildInputs = [ cmake ];
}

nix default.nix

env.nix
{ runCommand, protobuf, generator }:

runCommand "proto-generator-env" { buildInputs = [ generator protobuf ]; } ''
  exit 1
''
default.nix
let
  config = {
    packageOverrides = pkgs_in: {
    };
  };
  pkgs = import <nixpkgs> { inherit config; };
  callPackage = pkgs.newScope self;
  self = rec {
    generator = callPackage ./cpp-protobuf-generator/generator.nix {};
    generator-env = callPackage ./cpp-protobuf-generator/env.nix {};
  };
in self

nix nix gluster python脚本包装

nix gluster python脚本包装

glusterfs.nix
{stdenv, fetchurl, fuse, bison, flex_2_5_35, openssl, python2, ncurses, readline,
 autoconf, automake, libtool, pkgconfig, zlib, libaio, libxml2, acl, sqlite
 , liburcu, attr, makeWrapper, coreutils, gnused, gnugrep, which, python2Packages
}:
let
  s =
  rec {
    baseName="glusterfs";
    version = "3.10.1";
    name="${baseName}-${version}";
    url="https://github.com/nh2/glusterfs/archive/v3.10.1-runner-log.tar.gz";
    sha256 = "0d0n981vhyrxxwbfkdkbhyswiipa8pipz8j80mbvwb8aiqsk6kqs";
  };
  buildInputs = [
    fuse bison flex_2_5_35 openssl ncurses readline
    autoconf automake libtool pkgconfig zlib libaio libxml2
    acl sqlite liburcu attr makeWrapper
    (python2.withPackages (pkgs: [ pkgs.flask pkgs.requests pkgs.prettytable ]))
    python2
  ];
  # Some of the headers reference acl
  propagatedBuildInputs = [
    acl
  ];
in
stdenv.mkDerivation
rec {
  inherit (s) name version;
  inherit buildInputs propagatedBuildInputs;

  # nativeBuildInputs = [
  #   (python2.withPackages (pkgs: [pkgs.flask])) # works
  # ];

  preConfigure = ''
    ./autogen.sh
    '';

  configureFlags = [
    ''--localstatedir=/var''
    ];

  makeFlags = "DESTDIR=$(out)";

  enableParallelBuilding = true;

  postInstall = ''
    cp -r $out/$out/* $out
    rm -r $out/nix
    wrapProgram $out/sbin/mount.glusterfs --set PATH "${stdenv.lib.makeBinPath [ coreutils gnused attr gnugrep which]}"
    '';

  postFixup = ''
    # Set Python environment for the Python based utilities.
    # (@nh2) I'm not sure if there's a better way to do this, automatically for all of them.
    # Also, this is brittle: If we forget a dependency or gluster adds a new one, things will break deep inside gluster.
    # We should better try to get an explicit list of Python dependencies from gluster and ensure all of them are in the PYTHONPATH of all these python scripts.

    wrapProgram $out/bin/gluster-eventsapi --set PYTHONPATH "$(toPythonPath $out)"
    wrapProgram $out/bin/gluster-mountbroker --set PYTHONPATH "$(toPythonPath $out)"
    wrapProgram $out/bin/gluster-georep-sshkey --set PYTHONPATH "$(toPythonPath $out)"
    wrapProgram $out/bin/glusterfind --set PYTHONPATH "$(toPythonPath $out)"

    wrapProgram $out/libexec/glusterfs/peer_eventsapi.py --set PYTHONPATH "$(toPythonPath $out)"
    wrapProgram $out/libexec/glusterfs/peer_georep-sshkey.py --set PYTHONPATH "$(toPythonPath $out)"
    wrapProgram $out/libexec/glusterfs/peer_mountbroker.py --set PYTHONPATH "$(toPythonPath $out)"

    wrapProgram $out/libexec/glusterfs/glusterfind/changelog.py --set PYTHONPATH "$(toPythonPath $out):$(toPythonPath ${python2Packages.xattr}):$(toPythonPath ${python2Packages.cffi}):$(toPythonPath ${python2Packages.pycparser})"
    wrapProgram $out/libexec/glusterfs/gfind_missing_files/gfid_to_path.py --set PYTHONPATH "$(toPythonPath $out):$(toPythonPath ${python2Packages.xattr}):$(toPythonPath ${python2Packages.cffi}):$(toPythonPath ${python2Packages.pycparser})"

    wrapProgram $out/share/glusterfs/scripts/eventsdash.py --set PYTHONPATH "$(toPythonPath $out)"

    mkdir a
    touch b
    echo b | $out/libexec/glusterfs/gfind_missing_files/gfid_to_path.py a
    '';

  src = fetchurl {
    inherit (s) url sha256;
  };

  meta = {
    inherit (s) version;
    description = "Distributed storage system";
    maintainers = [
      stdenv.lib.maintainers.raskin
    ];
    platforms = with stdenv.lib.platforms;
      linux ++ freebsd;
  };
}
default.nix
with import <nixpkgs> { config = {}; };
callPackage ./glusterfs.nix {}

nix 1-default.nix

3-foo.nix
{ stdenv, libxcb, pkgconfig, cmake }:

stdenv.mkDerivation rec {
      name = "VulkanExamples";
      buildDepends = [ cmake libxcb pkgconfig ];
}
3-default.nix
with import <nixpkgs> {};

{
  foo = callPackage ./3-foo.nix {};
}
2-default.nix
with import <nixpkgs> {}; 

let
  self = stdenv.mkDerivation {
      name = "VulkanExamples";
      buildDepends = [ cmake libxcb pkgconfig ];
  };
in self
1-default.nix
with import <nixpkgs> {}; 

stdenv.mkDerivation {
      name = "VulkanExamples";
      buildDepends = [ cmake libxcb pkgconfig ];
}

nix vim.nix

vim.nix
{config,pkgs,...}:

let
  myVim = pkgs.vim_configurable.customize {
    name = "vim";
    vimrcConfig = {
      customRC = ''
        syntax on
        set nu
        set foldmethod=syntax
        set listchars=tab:->
        set list
        set backspace=indent,eol,start
        set autoread
        au FocusGained,BufEnter * :silent! !
        nmap <F3> :!ninja <enter>
        map <F7> :tabp<enter>
        map <F8> :tabn<enter>
        set expandtab
        set softtabstop=2
        set shiftwidth=2
        set autoindent
        call vundle#begin()
        Plugin 'wakatime/vim-wakatime'
        call vundle#end()
      '';
      vam.pluginDictionaries = [
        {
          names = [ "vim-nix" "youcompleteme" "Syntastic" "vundle" ];
        }
      ];
    };
  };
in
{
  environment.systemPackages = [ myVim ];
  environment.shellAliases.vi = "vim";
  environment.variables.EDITOR = "vim";
  programs.bash.shellAliases = {
    vi = "vim";
  };
}

nix gistfile1.nix

gistfile1.nix
{ pkgs, ... }:

let
  script1 = pkgs.writeScript "brightnessscript" ''
    #!/bin/sh
    your script here
  '';
  script2 = pkgs.writeScriptBin "brightness" ''
    #!/bin/sh
    sudo ${script1}
  '';
in {
  environment.systemPackages = [ script2 ];
  security.sudo.extraConfig = ''
    infinisil ALL=(root) NOPASSWD: ${script1}
  '';
}

nix 黑暗的shell.nix草案

黑暗的shell.nix草案

shell.nix
(import ./default.nix {}).overrideDerivation (old: { src = null; })
default.nix
{ pkgs ? import <nixpkgs> {} }:
# Based on nixpkgs/pkgs/applications/graphics/darktable/default.nix

let stdenv = pkgs.stdenv;
#assert stdenv ? glibc;
in stdenv.mkDerivation rec {
  name = "darktable-git";

  src = pkgs.lib.cleanSource ./.;

  buildInputs = with pkgs; with xorg; with gnome2;
    [ GConf atk cairo cmake curl dbus_glib exiv2 glib libgnome_keyring gtk3
      ilmbase intltool lcms lcms2 lensfun libXau libXdmcp libexif
      libglade libgphoto2 libjpeg libpng libpthreadstubs
      librsvg libtiff libxcb openexr pixman pkgconfig sqlite libxslt
      libsoup graphicsmagick SDL json_glib openjpeg mesa lua pugixml
      colord colord-gtk libxshmfence libxkbcommon epoxy at_spi2_core
      libwebp libsecret wrapGAppsHook gnome3.adwaita-icon-theme
      osm-gps-map
    ];

  cmakeFlags = [
    "-DBUILD_USERMANUAL=False"
  ];

  # darktable changed its rpath handling in commit
  # 83c70b876af6484506901e6b381304ae0d073d3c and as a result the
  # binaries can't find libdarktable.so, so change LD_LIBRARY_PATH in
  # the wrappers:
  preFixup = ''
    gappsWrapperArgs+=(
      --prefix LD_LIBRARY_PATH ":" "$out/lib/darktable"
    )
  '';

  meta = with stdenv.lib; {
    description = "Virtual lighttable and darkroom for photographers";
    homepage = https://www.darktable.org;
    license = licenses.gpl3Plus;
    platforms = platforms.linux;
    maintainers = [ maintainers.goibhniu maintainers.rickynils maintainers.flosse ];
  };
}

nix nginx的-example.nix

nginx-example.nix
{ ... }:

{
  services.nginx = {
    enable = true;
    virtualHosts = {
      "example.com" = {
        forceSSL = true;
        enableACME = true;
        locations = {
          "/".root = "/var/www/docroot";
        };
      };
    };
  };
}