# Error: creating directory '/nix/var': Permission denied

**URL:** https://discourse.nixos.org/t/error-creating-directory-nix-var-permission-denied/7048
**Category:** Help
**Created:** [May 5, 2020, 5:19pm UTC](https://discourse.nixos.org/t/error-creating-directory-nix-var-permission-denied/7048 "2020-05-05T17:19:59Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mhwombat](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mhwombat/32/762_2.png) [@mhwombat](https://discourse.nixos.org/u/mhwombat)
#### Post date: [May 5, 2020, 5:20pm UTC](https://discourse.nixos.org/t/error-creating-directory-nix-var-permission-denied/7048/1 "2020-05-05T17:20:00Z")

</div>

I’ve had success building several libraries using the method outlined in [Skyfold’s post](https://discourse.nixos.org/t/nix-haskell-development-2020/6170).

However, today **I’m trying to build an executable for a simple Haskell hello world program, but both `nix-shell` and `nix-build` give me errors**. I can’t figure out why.

```auto
$ nix-shell
building '/nix/store/hjsvi026mfmwabpgxhhpkyzzqgrsprma-cabal2nix-wombat.drv'...
installing
error: creating directory '/nix/var': Permission denied
error: creating directory '/nix/var': Permission denied
** need a revision for VCS when the hash is given. skipping.
** need a revision for VCS when the hash is given. skipping.
** need a revision for VCS when the hash is given. skipping.
** need a revision for VCS when the hash is given. skipping.
cabal2nix: user error (Failed to fetch source. Does this source exist? Source {sourceUrl = "/nix/store/rwbrabf73sgn8isgv7y2lybaqv4w44zw-wombat.cabal", sourceRevision = "", sourceHash = Guess "", sourceCabalDir = ""})
builder for '/nix/store/hjsvi026mfmwabpgxhhpkyzzqgrsprma-cabal2nix-wombat.drv' failed with exit code 1
error: build of '/nix/store/hjsvi026mfmwabpgxhhpkyzzqgrsprma-cabal2nix-wombat.drv' failed

```

I did find this [post on SO](https://stackoverflow.com/questions/60838230/how-can-i-fix-the-nix-shell-error-error-creating-directory-nix-var-permiss) with the same error message. Their diagnosis was that `cabal2nix` is invoking a Nix command inside the sandbox, probably caused by a mistake in the version of Nixpkgs in `NIX_PATH` . However, as you’ll see below, I’ve pinned nixpkgs. (And anyway, their workaround just gives me the same error.)

```auto
$ cat default.nix
{ nixpkgs ? import ./nix/nixos-20-03.nix }:
let
  overlay = self: super: {
    myHaskellPackages =
      super.haskell.packages.ghc865.override (old: {
        overrides = self.lib.composeExtensions (old.overrides or (_: _: {}))
          (hself: hsuper: {
            ghc = hsuper.ghc // { withPackages = hsuper.ghc.withHoogle; };
            ghcWithPackages = hself.ghc.withPackages;
          });
      });
  };

  pkgs = import nixpkgs {
    overlays = [overlay];
  };

  drv = pkgs.myHaskellPackages.callCabal2nix "wombat" ./wombat.cabal {};

  drvWithTools = drv.env.overrideAttrs (
    old: with pkgs.myHaskellPackages; {
      nativeBuildInputs = old.nativeBuildInputs ++ [
        ghcid
        # Add other development tools like ormolu here
      ];
# shellHook = ''
# source .config/secrets '';
      }
  );
in
  drvWithTools

```

```auto
$ cat wombat.cabal
cabal-version: >=1.10
name: wombat
version: 0.1.0.0
license-file: LICENSE
author: Amy de Buitléir
maintainer: amy@nualeargais.ie
build-type: Simple
extra-source-files: CHANGELOG.md

executable wombat
  main-is: Main.hs
  build-depends: base >=4.11 && <4.12,
                       directory ==1.3.* -- workaround NixOS bug #82245
  default-language: Haskell2010

```

```auto
$ cat Main.hs
module Main where

main :: IO ()
main = putStrLn "Hello, Wombat!"

```

```auto
$ cat nix/nixos-20-03.json
{
  "url": "https://github.com/nixos/nixpkgs-channels.git",
  "rev": "ab3adfe1c769c22b6629e59ea0ef88ec8ee4563f",
  "date": "2020-04-28T17:56:19-04:00",
  "sha256": "1m4wvrrcvif198ssqbdw897c8h84l0cy7q75lyfzdsz9khm1y2n1",
  "fetchSubmodules": false
}

```

```auto
$ cat nix/nixos-20-03.nix
let
  hostNix = import <nixpkgs> {};
  nixpkgsPin = hostNix.pkgs.lib.importJSON ./nixos-20-03.json;

  pinnedPkgs = hostNix.pkgs.fetchFromGitHub {
    owner = "NixOS";
    repo = "nixpkgs-channels";
    inherit (nixpkgsPin) rev sha256;
  };
in
  pinnedPkgs

```

```auto
$ echo $NIX_PATH
/home/amy/.nix-defexpr/channels:nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels

```
