nix opengl.nix

opengl.nix
with import <nixpkgs> {};

buildEnv {
  name = "opengl-drivers";
  paths = [ mesa_noglu mesa_noglu.drivers ];
}

nix bammmf.nix

bammmf.nix
{ stdenv
, fetchurl
, libwnck3
, autoconf
, pkgconfig
, wrapGAppsHook
, vala_0_32
, libgtop
, python2Packages
, libstartup_notification
, gtk_doc
, libxslt
, libxml2Python, libxml2
}:

let

  pkgver = "0.5.3";
  pythonEnv = python2Packages.python.withPackages(ps : [ ps.lxml ]);
  
in stdenv.mkDerivation {

  name = "bamf-${pkgver}";
  src =
    if stdenv.system == "x86_64-linux" then
      fetchurl {
        url = "https://launchpad.net/bamf/0.5/${pkgver}/+download/bamf-${pkgver}.tar.gz";
        sha256 = "340d7b5a463afcd33135ae73a7e4cf6a93a4daaf6f72b70abc09dc66d18a3b14";
      }
    else throw "BAMF is not supported on ${stdenv.system}";

  nativeBuildInputs = [ pkgconfig autoconf wrapGAppsHook ];

  buildInputs = [ gtk_doc libwnck3 vala_0_32  pythonEnv libgtop libstartup_notification libxml2Python python2Packages.lxml ];

  NIX_CFLAGS_COMPILE = [ "-Wno-error=deprecated-declarations" ];
  makeFlags = [ "PREFIX=$(out)" "SYSCONFDIR=/etc" "LOCALSTATEDIR=/var" "LIBEXECDIR=$(out)/lib" "--disable-static" "--disable-webapps" ];
  
 meta = {
    homepage = https://launchpad.net/bamf;
    description = "Application matching framework";
    license = stdenv.lib.licenses.lgpl3;
  };
}

nix jobify.nix

jobify.nix
let
  lib = (import <nixpkgs> {}).lib;
  configuration = { pkgs, ... }: {
    environment.systemPackages = [ pkgs.hello ];
  };
  eval = import <nixpkgs/nixos> { inherit configuration; };
in {
  jobs = lib.listToAttrs (map (x: { name = x.name; value = x; }) eval.config.environment.systemPackages);
}

nix util.nix

util.nix
{ writeScriptBin, runCommand, xterm }:

let
  nixposition = writeScriptBin "nix-position" ''
nix-position () {
    usage () {
        echo "Usage: nix-position <attribute-path-under-pkgs>"
        echo "Shows the Nix source file for a given attribute path."
    }
    if [ $# -ne 1 ]; then usage; return -1; fi
    local EXPR="(import <nixpkgs> {}).pkgs.${1}.meta.position"
    nix-instantiate --eval -E "''${EXPR}" | sed 's:"$::g' | sed 's:^"::g'
    return 0
}
'';
in runCommand "util-1" {} ''
  mkdir -pv $out/bin

  cat << EOF > $out/bin/loginto
  #!$SHELL
  exec ${xterm}/bin/xterm -e ssh \$1 -t screen -xRRU
  EOF
  chmod +x $out/bin/loginto

  cat << EOF > $out/bin/showsize
  #!$SHELL
  nix-store --query --tree "\$1" | sed 's,[-+| ]*/,/,' | awk '{print \$1}' | sort | uniq | xargs nix-store --query --size | paste -sd+ | ( echo -n '( ';sed 's,+, + ,g';echo ' ) / 1024 / 1024' ) | xargs expr
  EOF
  chmod +x $out/bin/showsize

  cat << EOF > $out/bin/nix-lookup
  #!$SHELL
  local USAGE
  USAGE="$USAGE Usage: nix-lookup <expression-path-under-pkgs>"
  USAGE="$USAGE Shows the directory for the given attribute path."
  if [ $# -ne 1 ]; then echo "$USAGE"; return -1; fi
  nix-instantiate --eval -E "\"\''${(import <nixpkgs> {}).pkgs.$1}\"" | sed 's:"::g'
  EOF
  chmod +x $out/bin/nix-lookup
''

nix pgsql.nix

pgsql.nix
with import <nixpkgs/nixos> {
  configuration = { pkgs, ... }: {
    services.postgresql.enable = true;
    services.postgresql.package = pkgs.postgresql92;
  };
};

config.systemd.services.postgresql

nix core.nix

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

let
  pixfix = if (builtins.currentSystem == "armv6l-linux") then
    [ ./pixman.nix ]
  else
    [];
  passwords = import ./passwords.nix;
  keys = import ./keys.nix;
in
{
  imports = [ ./vim.nix ./iscsi-boot.nix ./iscsi_module.nix ] ++ pixfix;
  environment.systemPackages = with pkgs; [ sqlite screen git util nix-repl utillinuxCurses psmisc ];
  programs = {
    screen.screenrc = ''
      defscrollback 5000
      caption always
    '';
    ssh = {
      knownHosts = [
        { hostNames = [ "192.168.2.1" "router.localnet" ]; publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMSvyvC18BHfivZJDhWSm7VU3kEElfNfMIfeohkil614"; }
        { hostNames = [ "192.168.2.15" "amd.localnet" ]; publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJhJRINrY5cFcqZ76GsAK7FU+wQhErlS6APdOIm7xcnW"; }
      ];
    };
  };
  nixpkgs.config = {
    sqlite.interactive = true;
    packageOverrides = (import ./overrides.nix).packageOverrides;
  };
  system.extraSystemBuilderCmds = ''
    ln -sv ${./.} $out/nixcfg
  '';
  services = {
    openssh = {
      enable = true;
      permitRootLogin = "yes";
    };
  };

nix default.nix

public_html.nix
{ stdenv, aedb, writeTextFile, cfg }:

let
  config = writeTextFile {
    name = "config.php";
    text = ''
      <?php
      $master_server = "${cfg.master}";
      $this_server = "${cfg.hostname}";
      $base = 'nixos';
    '';
  };
in
stdenv.mkDerivation {
  name = "public_html";
  
  phases = [ "installPhase" ];

  installPhase = ''
    mkdir -pv $out/dsis/
    cp -vi ${aedb}/root/index.php $out/
    ln -sv ${aedb}/web/css $out/dsis/
    ln -sv ${aedb}/web/java $out/dsis/
    ln -sv ${aedb}/web/js $out/dsis/
    ln -sv ${aedb}/web/sounds $out/dsis/
    ln -sv ${aedb}/web/help $out/dsis/
    ln -sv ${aedb}/web/images $out/dsis/
    substituteInPlace $out/index.php --replace @AEDB@ ${aedb} --replace @CONFIGFILE@ ${config};
  '';
}
default.nix
{ lib, config, pkgs, ... }:

with lib;

let
  aedb = pkgs.callPackage ./aedb.nix {};
  public_html = pkgs.callPackage ./public_html.nix { aedb = aedb; cfg = config.services.AEDB; };
in
{
  config = {
    services = {
      lighttpd = {
        enable = true;
        document-root = public_html;
        enableModules = [ "mod_fastcgi" "mod_redirect" "mod_rewrite" ];
        extraConfig =
''
#debug.log-request-handling = "enable"
$HTTP["host"] =~ "^nixos.example.com$" {
  server.document-root = "${public_html}"
  url.rewrite-once += (
    "/.*\?(.*)$" => "/index.php?$1",
    "/.*\.(js|ico|gif|jpg|png|css|html)$" => "$0",
    "/" => "/index.php"
  )
  fastcgi.server = ( ".php" =>
    ( "localhost" =>
      (
        "socket" => "/run/phpfpm/AEDB"
      )
    )
  )
}
'';
      };
    };
  };
}

nix context.nix

context.nix
with import <nixpkgs> {};

{
  # a normal dependency at build and runtime
  case1 = rec {
    a = writeText "1a.txt" "file #1";
    b = writeText "1b.txt" "file #2 refers to ${a}";
  };
  # b doesnt depent on a, so a never even got built
  # but b does contain a's path!
  case2 = rec {
    a = writeText "2a.txt" "file #1";
    b = writeText "2b.txt" "file #2 refers to ${builtins.unsafeDiscardStringContext a}";
  };
  # c depends on b at build-time, but never references it in the output, so no runtime dep
  # b depends on a properly, so a must be build before b, and hence, before c
  # but since c doesnt depend on a, a wont be copied to the correct build slave, or imported into the sandbox(chroot)
  case3 = rec {
    a = writeText "3a.txt" "file #1";
    b = runCommand "3b.txt" { inherit a; } ''
      echo "file #2" > $out
    '';
    c = runCommand "3c.txt" { inherit b; } ''
      echo "file #3 refers to ${builtins.unsafeDiscardStringContext a}" > $out
    '';
  };
}

nix default.nix

default.nix
with import <nixpkgs> {};

let
  foo = fetchFromGitHub {
    owner = "foo";
    repo = "bar";
    rev = "commithash";
    sha256 = "hash";
   };
  script = writeScriptBin "scriptname" ''
    #!${stdenv.shell}
    PYTHONPATH=${some-module}/lib/site-packages/something ${python}/bin/python ${foo}/bar.py
  '';
in runCommand "env-name" { buildInputs = [ script tool1 tool2 ]; } "dummy"

nix foo.nix

foo.nix
{ lib, config, pkgs, pkgs_i686, ... }:

let
  builders = import ./builders.nix;
  foo = pkgs.mesa_noglu.overrideDerivation (oldAttrs: {
    src = /home/clever/x/mesa-11.2.2;
    dontStrip = true;
  });
in
{
  hardware = {
    bluetooth.enable = false;
    opengl = {
      driSupport32Bit = true;
      package = pkgs.buildEnv {
        name = "custom-hack";
        paths = [
          foo foo.drivers
        ];
      };
    };
  };
}