Skip to content

Instantly share code, notes, and snippets.

@manojkarthick
Last active October 21, 2020 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manojkarthick/3767b946ad45d5e4a2b5bca257154983 to your computer and use it in GitHub Desktop.
Save manojkarthick/3767b946ad45d5e4a2b5bca257154983 to your computer and use it in GitHub Desktop.
Sample nix derivations
with import <nixpkgs> {};
stdenv.mkDerivation rec {
pname = "avro-tools";
version = "1.9.2";
src = fetchurl {
url =
"https://repo1.maven.org/maven2/org/apache/avro/avro-tools/${version}/${pname}-${version}.jar";
sha256 = "169cv4fjsj69fa2s87gh1i7wk0xzh3l7sx5yyz3cgyjalg4a12n1";
};
dontUnpack = true;
buildInputs = [ jre ];
nativeBuildInputs = [ makeWrapper ];
sourceRoot = ".";
installPhase = ''
mkdir -p $out/bin
mkdir -p $out/libexec/avro-tools
cp $src $out/libexec/avro-tools/${pname}.jar
makeWrapper ${jre}/bin/java $out/bin/avro-tools \
--add-flags "-jar $out/libexec/avro-tools/${pname}.jar"
'';
}
let
go113Tarball = fetchTarball https://github.com/NixOS/nixpkgs/archive/6148f6360310366708dff42055a0ba0afa963101.tar.gz;
pkgs = import <nixpkgs> {};
goAlternate = import go113Tarball {};
drv = pkgs.stdenv.mkDerivation rec {
name = "env";
env = pkgs.buildEnv { name = name; paths = buildInputs; };
buildInputs = [
goAlternate.go_1_13
];
shellHook = ''
# export PS1="[nix@${name}:\W]\[$(tput sgr0)\] "
export PS1="[\[\e[32m\]nix\[\e[m\]@\[\e[31m\]${name}\[\e[m\] \[\e[36m\]\W\[\e[m\]] "
bind '"\e\e[C": forward-word'
bind '"\e\e[D": backward-word'
'';
};
in drv
with import <nixpkgs> {};
let
wmiPackage = pkgs.writeShellScriptBin "whatsMyIp" ''
${pkgs.curl}/bin/curl -sL http://httpbin.org/get | ${pkgs.jq}/bin/jq -r '.origin'
'';
in
stdenv.mkDerivation rec {
name = "test-environment";
buildInputs = [ wmiPackage];
}
// sourced from: https://nathan.gs/2019/04/19/using-jekyll-and-nix-to-blog/
with import <nixpkgs> { };
let jekyll_env = bundlerEnv rec {
name = "jekyll_env";
inherit ruby;
gemfile = ./Gemfile;
lockfile = ./Gemfile.lock;
gemset = ./gemset.nix;
};
in
stdenv.mkDerivation rec {
name = "nathan.gs";
buildInputs = [ jekyll_env bundler ruby ];
shellHook = ''
exec ${jekyll_env}/bin/jekyll serve --watch
'';
}
with import <nixpkgs> {};
stdenv.mkDerivation rec {
name = "env";
env = buildEnv { name = name; paths = buildInputs; };
buildInputs = [
python36
python36Packages.virtualenv
python36Packages.pip
];
shellHook = ''
# export PS1="[nix@${name}:\W]\[$(tput sgr0)\] "
export PS1="[\[\e[32m\]nix\[\e[m\]@\[\e[31m\]${name}\[\e[m\] \[\e[36m\]\W\[\e[m\]] "
bind '"\e\e[C": forward-word'
bind '"\e\e[D": backward-word'
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment