Gabriella439 / nixfmt

Automatic code formatter for the Nix programming language
BSD 3-Clause "New" or "Revised" License
52 stars 6 forks source link

Can't parse .drv files #4

Open nh2 opened 6 years ago

nh2 commented 6 years ago

Hi Gabriel,

should nixfmt be able to format .drv files?

I'm trying like this:

% /home/niklas/.local/bin/nixfmt < /nix/store/b8dbxr52jb300sdmsknsjb86j0v9syb2-pipes-4.3.4.drv
Report {position = 6, expected = ["one of \"+-.\"","letter or digit","':'","one of \"._-+\"","letter or digit","'/'","one of \"_'-\"","letter or digit","space","\":\"","space","\"@\"","\".\"","\".\"","space","\"or\"","space","space","space","\"==\"","space","\"!=\"","space","\"<\"","space","\"<=\"","space","\">\"","space","\">=\"","space","\"&&\"","space","\"||\"","space","\"->\"","space","\"//\"","space","\"?\"","space","\"+\"","space","\"*\"","space","space","space","\"++\""], unconsumed = "([(\"doc\",\"/nix/store/lmljx9pm3ywgmclcdr8r43gsx36qslcd-pipes-4.3.4-doc\",\"\",\"\"),(\"out\",\"/nix/store/cbxjf5c25qci46xzf7f8lxqzxiaylb1r-pipes-4...

File contents are these:

% cat /nix/store/b8dbxr52jb300sdmsknsjb86j0v9syb2-pipes-4.3.4.drv
Derive([("doc","/nix/store/lmljx9pm3ywgmclcdr8r43gsx36qslcd-pipes-4.3.4-doc","",""),("out","/nix/store/cbxjf5c25qci46xzf7f8lxqzxiaylb1r-pipes-4.3.4","","")],[("/nix/store/1221b30v30p9al48j35ghi9f8adbqanp-stdenv.drv",["out"]),("/nix/store/3bm8xqc0lhxmwpf50g0g0qhn3s2gs2hh-exceptions-0.8.3.drv",["out"]),("/nix/store/43w26kdfgzzwrhxvgm5krcw5ing148s5-hscolour-1.24.1.drv",["out"]),("/nix/store/4wsgcr45r27lq3big4s5i2zcqx5favkw-ghc-8.2.1.drv",["out"]),("/nix/store/5jgg368ksn8fqg8rcbbryikmd5fdxhar-coreutils-8.28.drv",["out"]),("/nix/store/62n7ccfdihfm5qgyjbfhfcc9bfc6x3jq-test-framework-0.8.1.1.drv",["out"]),("/nix/store/8pv4j3nanl7azbc79cdd1mcgj4vqdrwj-gnugrep-3.1.drv",["out"]),("/nix/store/95czgn1x1fiyqklq69xpsngpn69mwdl8-bash-4.4-p12.drv",["out"]),("/nix/store/b81cvjkiwg64drmz0nk41qhj4mky14wm-remove-references-to.drv",["out"]),("/nix/store/bgawd0r38y07skmapvs680bxa67603f0-mmorph-1.0.9.drv",["out"]),("/nix/store/imdibnv3zgwqfz8bvx2bzp9iwclp2n17-gnused-4.4.drv",["out"]),("/nix/store/kvjllzap9lg5csg94m350lc2gbaqdglw-QuickCheck-2.9.2.drv",["out"]),("/nix/store/mp80g2sfix64z6ylq73zc098xsv3j3il-test-framework-quickcheck2-0.3.0.4.drv",["out"]),("/nix/store/mykdrnnygi9qwwli3ib0x6bzcwjh1jbg-void-0.7.2.drv",["out"]),("/nix/store/n3b4p4wrj0bvvhxfrhxzmdx7h4aph4g3-glibc-locales-2.25-49.drv",["out"]),("/nix/store/qq2i7hqsw29sl1wd1x319m84jzjj0i19-pipes-4.3.4.tar.gz.drv",["out"]),("/nix/store/zjmk44rn7ai11ib64l8frqqs7mgffazs-mtl-2.2.1.drv",["out"])],["/nix/store/4mdp8nhyfddh7bllbi7xszz7k9955n79-Setup.hs","/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"],"x86_64-linux","/nix/store/hvhmhd625l47wcvxrachk255j02nhkkp-bash-4.4-p12/bin/bash",["-e","/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"],[("LANG","en_US.UTF-8"),("LOCALE_ARCHIVE","/nix/store/mzcld3rk5sh5dn14n8z5skfawllpy0cb-glibc-locales-2.25-49/lib/locale/locale-archive"),("buildInputs"," /nix/store/2mlkbcw9bnl2wm6nr4wwirxhkbdsn3j0-mtl-2.2.1 /nix/store/mm8268g9qnm0p7h8yfcn3d9cnqycq6cp-QuickCheck-2.9.2 /nix/store/289gghlxmb50wy3ncdhii6n77y9anbdx-test-framework-0.8.1.1 /nix/store/1sjdva9qbxb6amxm69hdzxvi60jvzkay-test-framework-quickcheck2-0.3.0.4 "),("buildPhase","runHook preBuild\n./Setup build \nrunHook postBuild\n"),("builder","/nix/store/hvhmhd625l47wcvxrachk255j02nhkkp-bash-4.4-p12/bin/bash"),("checkPhase","runHook preCheck\n./Setup test \nrunHook postCheck\n"),("compileBuildDriverPhase","runHook preCompileBuildDriver\n\nfor i in Setup.hs Setup.lhs /nix/store/4mdp8nhyfddh7bllbi7xszz7k9955n79-Setup.hs; do\n  test -f $i && break\ndone\n\necho setupCompileFlags: $setupCompileFlags\nghc $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i\n\nrunHook postCompileBuildDriver\n"),("configureFlags",""),("configurePhase","runHook preConfigure\n\nunset GHC_PACKAGE_PATH      # Cabal complains if this variable is set during configure.\n\necho configureFlags: $configureFlags\n./Setup configure $configureFlags 2>&1 | /nix/store/1g347c2qqppdssih3f77sdsckqvsd97i-coreutils-8.28/bin/tee \"$NIX_BUILD_TOP/cabal-configure.log\"\nif /nix/store/710ahiiqihz8mc1cp729srdbi4m84yzs-gnugrep-3.1/bin/egrep -q '^Warning:.*depends on multiple versions' \"$NIX_BUILD_TOP/cabal-configure.log\"; then\n  echo >&2 \"*** abort because of serious configure-time warning from Cabal\"\n  exit 1\nfi\n\nexport GHC_PACKAGE_PATH=\"$packageConfDir:\"\n\nrunHook postConfigure\n"),("doCheck","1"),("doc","/nix/store/lmljx9pm3ywgmclcdr8r43gsx36qslcd-pipes-4.3.4-doc"),("haddockPhase","runHook preHaddock\n./Setup haddock --html \\\n  --hoogle \\\n  --hyperlink-source\n\nrunHook postHaddock\n"),("installPhase","runHook preInstall\n\n./Setup copy\nlocal packageConfDir=\"$out/lib/ghc-8.2.1/package.conf.d\"\nlocal packageConfFile=\"$packageConfDir/pipes-4.3.4.conf\"\nmkdir -p \"$packageConfDir\"\n./Setup register --gen-pkg-config=$packageConfFile\nlocal pkgId=$( /nix/store/krf1i35zgm83ifxixqzbq05d3qr7kxqn-gnused-4.4/bin/sed -n -e 's|^id: ||p' $packageConfFile )\nmv $packageConfFile $packageConfDir/$pkgId.conf\n\n\n\n\n\nfor x in $doc/share/doc/html/src/*.html; do\n  remove-references-to -t $out $x\ndone\nmkdir -p $doc\n\n\n\nrunHook postInstall\n"),("name","pipes-4.3.4"),("nativeBuildInputs","/nix/store/9a0mbp5wz32mlblgacbwhy0drqm18gj5-remove-references-to"),("out","/nix/store/cbxjf5c25qci46xzf7f8lxqzxiaylb1r-pipes-4.3.4"),("outputs","out doc"),("postPatch",""),("preConfigurePhases","compileBuildDriverPhase"),("preInstallPhases","haddockPhase"),("prePatch",""),("prePhases","setupCompilerEnvironmentPhase"),("propagatedBuildInputs"," /nix/store/07wq99anl1s1hxvs7y2dh7l2wiffjkjv-exceptions-0.8.3 /nix/store/4hv35gmkgv4jylqwqip6054ch473mk3s-mmorph-1.0.9 /nix/store/2mlkbcw9bnl2wm6nr4wwirxhkbdsn3j0-mtl-2.2.1  /nix/store/nayfz7hm14y4mhh8a5hmdzaq10z8c8am-void-0.7.2"),("propagatedNativeBuildInputs",""),("setOutputFlags",""),("setupCompilerEnvironmentPhase","runHook preSetupCompilerEnvironment\n\necho \"Build with /nix/store/n54m8fpdl9l4g9kjl27hi43rpvn3zhfs-ghc-8.2.1.\"\nexport PATH=\"/nix/store/n54m8fpdl9l4g9kjl27hi43rpvn3zhfs-ghc-8.2.1/bin:$PATH\"\nexport PATH=/nix/store/adqnj0napv7pm0xf8q42myqcw268cf6n-hscolour-1.24.1/bin:$PATH\n\npackageConfDir=\"$TMPDIR/package.conf.d\"\nmkdir -p $packageConfDir\n\nsetupCompileFlags=\"-package-db=$packageConfDir  -j$NIX_BUILD_CORES -threaded\"\nconfigureFlags=\"--verbose --prefix=$out --libdir=\\$prefix/lib/\\$compiler --libsubdir=\\$pkgid  --docdir=$doc/share/doc --with-gcc=$CC --package-db=$packageConfDir --ghc-option=-optl=-Wl,-rpath=$out/lib/ghc-8.2.1/pipes-4.3.4  --ghc-option=-j$NIX_BUILD_CORES  --disable-split-objs --disable-library-profiling --disable-profiling --enable-shared --disable-coverage --enable-library-vanilla --enable-executable-dynamic --enable-tests --ghc-option=-split-sections $configureFlags\"\n\n# nativePkgs defined in stdenv/setup.hs\nfor p in \"${nativePkgs[@]}\"; do\n  if [ -d \"$p/lib/ghc-8.2.1/package.conf.d\" ]; then\n    cp -f \"$p/lib/ghc-8.2.1/package.conf.d/\"*.conf $packageConfDir/\n    continue\n  fi\n  if [ -d \"$p/include\" ]; then\n    configureFlags+=\" --extra-include-dirs=$p/include\"\n  fi\n  if [ -d \"$p/lib\" ]; then\n    configureFlags+=\" --extra-lib-dirs=$p/lib\"\n  fi\ndone\nghc-pkg --package-db=\"$packageConfDir\" recache\n\nrunHook postSetupCompilerEnvironment\n"),("src","/nix/store/wchrs8hnjqx7jz3gv728hm42ahhmvc2j-pipes-4.3.4.tar.gz"),("stdenv","/nix/store/nhq06aa8fkjs5gz972pmffixsyz5zrhv-stdenv"),("system","x86_64-linux")])
Gabriella439 commented 6 years ago

No, but you can use the ppsh executable from the pretty-show package to format Nix derivations

domenkozar commented 6 years ago

https://hackage.haskell.org/package/nix-derivation