diff --git a/default.nix b/default.nix new file mode 100644 index 00000000..9c29a259 --- /dev/null +++ b/default.nix @@ -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 {}; + 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)); +}) diff --git a/local.example.nix b/local.example.nix new file mode 100644 index 00000000..3ed08740 --- /dev/null +++ b/local.example.nix @@ -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 + ''; +} diff --git a/setup.cfg b/setup.cfg index d5ba3daf..4860eae6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,5 +3,5 @@ max-line-length = 120 exclude = ./venv* [pytest] -norecursedirs = venv venv3 src +norecursedirs = venv* src