Skip to content

Commit

Permalink
add default.nix, add venv* to pytest's norecursedirs
Browse files Browse the repository at this point in the history
  • Loading branch information
risicle committed Sep 25, 2017
1 parent bddd379 commit 0a162af
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
40 changes: 40 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
argsOuter@{...}:
let
# specifying args defaults in this slightly non-standard way to allow us to include the default values in `args`
args = rec {
pkgs = import <nixpkgs> {};
pythonPackages = pkgs.python36Packages;
forDev = true;
localOverridesPath = ./local.nix;
} // argsOuter;
in (with args; {
digitalMarketplaceUtilsEnv = (pkgs.stdenv.mkDerivation rec {
name = "digitalmarketplace-utils-frontend-env";
shortName = "dm-utils";
buildInputs = [
pythonPackages.virtualenv
] ++ pkgs.stdenv.lib.optionals forDev ([
] ++ pkgs.stdenv.lib.optionals pkgs.stdenv.isDarwin [
]
);

hardeningDisable = pkgs.stdenv.lib.optionals pkgs.stdenv.isDarwin [ "format" ];

VIRTUALENV_ROOT = "venv${pythonPackages.python.pythonVersion}";
VIRTUAL_ENV_DISABLE_PROMPT = "1";
SOURCE_DATE_EPOCH = "315532800";

# if we don't have this, we get unicode troubles in a --pure nix-shell
LANG="en_GB.UTF-8";

shellHook = ''
export PS1="\[\e[0;36m\](nix-shell\[\e[0m\]:\[\e[0;36m\]${shortName})\[\e[0;32m\]\u@\h\[\e[0m\]:\[\e[0m\]\[\e[0;36m\]\w\[\e[0m\]\$ "
if [ ! -e $VIRTUALENV_ROOT ]; then
${pythonPackages.virtualenv}/bin/virtualenv $VIRTUALENV_ROOT
fi
source $VIRTUALENV_ROOT/bin/activate
make requirements${pkgs.stdenv.lib.optionalString forDev "-dev"}
'';
}).overrideAttrs (if builtins.pathExists localOverridesPath then (import localOverridesPath args) else (x: x));
})
22 changes: 22 additions & 0 deletions local.example.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# default.nix calls out to the file local.nix if it exists, expecting a function which it will call, applying first
# the args passed to the original default.nix and then `oldAttrs`, the attrset originally applied to mkDerivation.
#
# the function should return an attrset altered to the local user's desires, as they would wish to be applied to
# mkDerivation to produce the env

args: oldAttrs: oldAttrs // {
# here we add some of our favourite packages to the environment which aren't necessarily to everyone's tastes
buildInputs = oldAttrs.buildInputs ++ [
args.pkgs.vim
args.pythonPackages.ipython
];

shellHook = oldAttrs.shellHook + ''
# PS1 can't be set as a normal derivation attr as it gets clobbered early on in the upstream shellHook script
export PS1="⚡$PS1⚡"
# inject some whimsy into our session - note here we access a package which we don't actually end up
# explicitly exposing to the final environment
${args.pkgs.fortune}/bin/fortune
'';
}
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ max-line-length = 120
exclude = ./venv*

[pytest]
norecursedirs = venv venv3 src
norecursedirs = venv* src

0 comments on commit 0a162af

Please sign in to comment.