cachix/ghcide-nix

How long should the build take when using Cachix?

Closed this issue ยท 19 comments

I'm wondering if I don't have Cachix setup correctly here,

I ran:

nix-env -iA cachix -f https://cachix.org/api/v1/install
cachix use hercules-ci

And

environment.systemPackages = [
  (import (builtins.fetchTarball "https://github.com/hercules-ci/ghcide-nix/tarball/master") {}).ghcide-ghc865
];

When rebuilding nixos it does actually seem to be compiling a bunch of things - and has been running for about 5+ minutes at this point?

sudo  nixos-rebuild switch

I just tried the nix-env -iA ghcide-ghc865 -f https://github.com/hercules-ci/ghcide-nix/tarball/master which completed in a few seconds.

Did you cachix use the cache on your user profile or also on your root user or system config (cachix use --nixos)?

I got the same experience without using cachix use (well I cannot use cachix use hercules-ci due to some weird due to lack of write permission).

@roberth is there a command --nixos? I don't see it in cachix --help.

@roberth I don't think I've set up anything with my system config for cachix no (besides running the cachix use... command).

If you could point me to any resource to setting this up (or whether it's possibly just something I should ask in the nixos IRC channel?) - I'd be thankful!

Regarding cachix use --nixos:

cachix use --nixos 
Invalid option `--nixos'

Usage: cachix use NAME [-m|--mode ARG] [-d|--nixos-folder ARG]
  Configure nix.conf to enable binary cache during builds

cachix use normally only applies to configuration of the user that invokes it.
nixos-rebuild is performed by root, which will not read your user configuration. This is why your nix-env call substituted as expected but nixos-rebuild did not.

To make a cachix cache apply system-wide, I recommend to run and apply the suggested change:

$ nix-env -iA cachix -f https://cachix.org/api/v1/install
$ sudo cachix use hercules-ci
Cachix configuration written to /etc/nixos/cachix.nix.
Binary cache hercules-ci configuration written to /etc/nixos/cachix/hercules-ci.nix.

To start using cachix add the following to your /etc/nixos/configuration.nix:

    imports = [ ./cachix.nix ];

Then run:

    $ nixos-rebuild switch

@chrissound did you manage to resolve this? If not, could you provide an update on the current status (if anything changed?)

I found that on NixOS the following worked just fine when logged in as non-root:

$ nix-env -iA cachix -f https://cachix.org/api/v1/install`
unpacking 'https://cachix.org/api/v1/install'...
installing 'cachix-0.3.4'
[snip]

I tried using cachix:

$ cachix use hercules-ci

MustBeRoot "Run command as root OR execute: $ echo \"trusted-users = root $USER\" | sudo tee -a /etc/nix/nix.conf && sudo pkill nix-daemon"

So I ran as root with sudo:

$ sudo cachix use hercules-ci
Cachix configuration written to /etc/nixos/cachix.nix.
Binary cache hercules-ci configuration written to /etc/nixos/cachix/hercules-ci.nix.

To start using cachix add the following to your /etc/nixos/configuration.nix:

    imports = [ ./cachix.nix ];

Then run:

    $ nixos-rebuild switch

I followed the instructions to modify /etc/nixos/configuration.nix. Attempting to run nixos-rebuild switch here fails as I'm logged in a non-root. So I use sudo:

$ sudo nixos-rebuild switch
building Nix...
building the system configuration...
these derivations will be built:
[snip]

I then installed ghcide in my user environment with nix:

$ nix-env -iA ghcide-ghc865 -f https://github.com/hercules-ci/ghcide-nix/tarball/master
warning: ignoring untrusted substituter 'https://cache.nixos.org'
unpacking 'https://github.com/hercules-ci/ghcide-nix/tarball/master'...
unpacking 'https://github.com/input-output-hk/haskell.nix/archive/ff4958c3eacf44a124407055da452fc6840fbc2a.tar.gz'...
unpacking 'https://github.com/input-output-hk/stackage.nix/archive/deb4573dc8e2ffe6b2175f43b2cc80b7e9179046.tar.gz'...
warning: dumping very large path (> 256 MiB); this may run out of memory
[snip]

This installed precompiled packages.

$ which ghcide
/home/steshaw/.nix-profile/bin/ghcide

Sweet. Thanks ๐Ÿ‘

I did experience a full rebuild on macOS. Is that expected? Though I did get a ghcide at the end of a very long compilation process on my MacBook Air.

Really good experience report, thank you!

I'll fix Cachix to say sudo.

Also need to add macos binaries for ghcide, leaving this open to complete that.

Yup all working now after sudo cachix use hercules-ci and the further instructions. Many thanks!

Slightly off topic:
I think I have actually run into this very same behavior before though (running cachix use... as a regular user, and then still confusingly getting long build times) - so possibly cachix could be documented to better emphasize the user-specific configuration. Or perhaps I've not thoroughly read the return output from the cachix use.

Very happy to finally have gotten this working though!

I need to finish documentation on the topic of "What can go wrong if I'm not getting binaries from the cache".

macOS will now be part of the cache once https://github.com/hercules-ci/ghcide-nix/pull/17 is merged.

Thanks both for feedback :)

@domenkozar is the warning expected ?
warning: dumping very large path (> 256 MiB); this may run out of memory
Cheers

Yes I think it is due to haskell.nix

It seems like I'm not getting binaries from the cache -- when i run

nix-env -iA ghcide-ghc865 -f https://github.com/hercules-ci/ghcide-nix/tarball/master

i see stuff like this and it's taking 20+ minutes:

Building library for free-5.1.2..
[ 1 of 20] Compiling Control.Alternative.Free ( src/Control/Alternative/Free.hs, dist/build/Control/Alternative/Free.o )
[ 2 of 20] Compiling Control.Alternative.Free.Final ( src/Control/Alternative/Free/Final.hs, dist/build/Control/Alternative/Free/Final.o )
[ 3 of 20] Compiling Control.Applicative.Free ( src/Control/Applicative/Free.hs, dist/build/Control/Applicative/Free.o )
[ 4 of 20] Compiling Control.Applicative.Free.Fast ( src/Control/Applicative/Free/Fast.hs, dist/build/Control/Applicative/Free/Fast.o )
[ 5 of 20] Compiling Control.Applicative.Free.Final ( src/Control/Applicative/Free/Final.hs, dist/build/Control/Applicative/Free/Final.o )
[ 6 of 20] Compiling Control.Applicative.Trans.Free ( src/Control/Applicative/Trans/Free.hs, dist/build/Control/Applicative/Trans/Free.o )
[ 7 of 20] Compiling Control.Comonad.Cofree.Class ( src/Control/Comonad/Cofree/Class.hs, dist/build/Control/Comonad/Cofree/Class.o )
[ 8 of 20] Compiling Control.Comonad.Trans.Cofree ( src/Control/Comonad/Trans/Cofree.hs, dist/build/Control/Comonad/Trans/Cofree.o )
[ 9 of 20] Compiling Control.Monad.Free.Class ( src/Control/Monad/Free/Class.hs, dist/build/Control/Monad/Free/Class.o )
[10 of 20] Compiling Control.Monad.Free.TH ( src/Control/Monad/Free/TH.hs, dist/build/Control/Monad/Free/TH.o )
[11 of 20] Compiling Data.Functor.Classes.Compat ( src/Data/Functor/Classes/Compat.hs, dist/build/Data/Functor/Classes/Compat.o )
[12 of 20] Compiling Control.Monad.Trans.Iter ( src/Control/Monad/Trans/Iter.hs, dist/build/Control/Monad/Trans/Iter.o )
[13 of 20] Compiling Control.Monad.Trans.Free.Ap ( src/Control/Monad/Trans/Free/Ap.hs, dist/build/Control/Monad/Trans/Free/Ap.o )

Repository moved to a new owner.

@domenkozar what do you mean? what should i change?

edit - when following readme instructions:

โžœ  personal-website-server git:(master) โœ— sudo cachix use ghcide-nix                
Password:
Configured https://ghcide-nix.cachix.org binary cache in /etc/nix/nix.conf
โžœ  personal-website-server git:(master) โœ— nix-env -iA ghcide-ghc865 -f https://github.com/cachix/ghcide-nix/tarball/master
trace: Get `stack-sha256` with `nix-hash --base32 --type sha256 /nix/store/vzlv92sclddb618w2h39hk8rv289p64c-stack-to-nix-pkgs/`
installing 'ghcide-0.1.0-exe-ghcide'
these derivations will be built:
  /nix/store/rfq06nkrjvi6wriqbipwjr6vavl96mdc-vector-0.12.0.3-lib-vector.drv
  /nix/store/9ccm8qvgpslv5m70whf8yiqxnzxdih27-monoid-subclasses-0.4.6.1-lib-monoid-subclasses-config.drv
  /nix/store/q3r9ly9i873c6q3jvsnghjy566a4i81s-monoid-subclasses-0.4.6.1-lib-monoid-subclasses-ghc-8.6.5.drv
  /nix/store/z11nqqmzchgxm66j1jlgq9ggc7n0p0fa-monoid-subclasses-0.4.6.1-lib-monoid-subclasses.drv
  /nix/store/0qdb7fr5cgh8418v79p6l425vbjjvnvb-fuzzy-0.1.0.0-lib-fuzzy-config.drv
  /nix/store/cnjd46x3spydiv49855anw3gn6l957sd-uuid-types-1.0.3-lib-uuid-types.drv
  /nix/store/8pi6y8lh44pd80hdhmvpkr94bpcwpcd2-aeson-1.4.4.0-lib-aeson-config.drv
  /nix/store/yi8rxq3j06i2zh8jxa4fbmzi6r41zabv-fuzzy-0.1.0.0-lib-fuzzy-ghc-8.6.5.drv
  /nix/store/9jk3z659ff6j7wcrclmsf1cxsv5k63jy-fuzzy-0.1.0.0-lib-fuzzy.drv
  /nix/store/zk7lpxpgwkdsv5wlkm0iml5jqldhlgxz-void-0.7.3-lib-void-config.drv
  /nix/store/pscrm80lvz46h5gf1iwx0qwsqb2c3i8x-void-0.7.3-lib-void-ghc-8.6.5.drv
  /nix/store/sq74qv8hzxx27rpqrgc3nwdwy20bf84m-void-0.7.3-lib-void.drv
  /nix/store/mzhmfqmjyyb9x2200w451cslsc7gc4i6-adjunctions-4.4-lib-adjunctions-config.drv
  /nix/store/j93ljpflnqj1n0apy518s1yw3ixh532k-adjunctions-4.4-lib-adjunctions-ghc-8.6.5.drv
  /nix/store/iri6rv4ckg91mw1j25hzz60lj3zqh8b1-adjunctions-4.4-lib-adjunctions.drv
  /nix/store/mb0x6m9n83h6yg3w92d0xr5756kvqrn7-kan-extensions-5.2-lib-kan-extensions-config.drv
  /nix/store/l7iig1pqzjrb4np43myhik83hkihalvd-kan-extensions-5.2-lib-kan-extensions-ghc-8.6.5.drv
  /nix/store/m3s4wdggw318ndv8j8sx9m6a7axyinwm-kan-extensions-5.2-lib-kan-extensions.drv
  /nix/store/v5a518122iir33dih0c1s3bya1nca8k6-lens-4.17.1-lib-lens-config.drv
  /nix/store/9clsmy888l963hmsz71bp4wdwpqfgzwf-lens-4.17.1-lib-lens-ghc-8.6.5.drv
  /nix/store/3abdfnsmsjaf0bqrb2icvfnbslsz4v48-lens-4.17.1-lib-lens.drv
  /nix/store/g4gj6vbwbvx7ij68izmacsk9mna42zf2-aeson-1.4.4.0-lib-aeson-ghc-8.6.5.drv
  /nix/store/lqqv557l6m09aghd7qgm3b1k79yjmbbn-aeson-1.4.4.0-lib-aeson.drv
  /nix/store/jgab3pwzrgdz9n6aaqjhyy4labsh9q4c-haskell-lsp-types-0.19.0.0-lib-haskell-lsp-types-config.drv
  /nix/store/axl5z22nz43jlgpv5z9r7v52h5wsrgjf-haskell-lsp-types-0.19.0.0-lib-haskell-lsp-types-ghc-8.6.5.drv
  /nix/store/grl3gpc2m25j5nw86h76dakmgaqybh3h-haskell-lsp-types-0.19.0.0-lib-haskell-lsp-types.drv
  /nix/store/qlr0y29jljnna8f2n81r4d10bqm5h4vx-haskell-lsp-0.19.0.0-lib-haskell-lsp-config.drv
  /nix/store/6i3pm8ff5nvcm42n4g910mk3rva5sw5d-haskell-lsp-0.19.0.0-lib-haskell-lsp-ghc-8.6.5.drv
  /nix/store/ba663v9b6y43jnp30bnshc04m8x2dddl-haskell-lsp-0.19.0.0-lib-haskell-lsp.drv
  /nix/store/j334gxsk5c81m17xwlhjn4jichf144aw-ghcide-0.1.0-lib-ghcide-config.drv
  /nix/store/h0j9j2h5ill6c0pbx6wwqfk8fgwdcvqx-ghcide-0.1.0-lib-ghcide-ghc-8.6.5.drv
  /nix/store/0yp92v7559zqkbkm5nxa2hzshjvnkpy6-ghcide-0.1.0-lib-ghcide.drv
  /nix/store/c8ry7031lib4ayn6cv43amh8w2jpxkss-zlib-0.6.2.1-lib-zlib-config.drv
  /nix/store/saqhncf8hj39wccih7rvilrbbwlvw6nz-zlib-0.6.2.1-lib-zlib-ghc-8.6.5.drv
  /nix/store/vl526mnjl7fxrb7bg89a4awvhnl99wr9-zlib-0.6.2.1-lib-zlib.drv
  /nix/store/j4fd193zb9zpmms9p6ckxkzri1l91scz-streaming-commons-0.2.1.1-lib-streaming-commons-config.drv
  /nix/store/rfndss1zhkj47bw1bpya6y262wz18vf1-vector-algorithms-0.8.0.1-lib-vector-algorithms-config.drv
  /nix/store/vhhi4y813nnqqxs28klcmznzvqp9i4ya-vector-algorithms-0.8.0.1-lib-vector-algorithms-ghc-8.6.5.drv
  /nix/store/21dlvhi0g33w74k4n08smgdzd7yynadf-vector-algorithms-0.8.0.1-lib-vector-algorithms.drv
  /nix/store/yjpryxrsmfyz5swm17lkp3r1gzk2r5jp-mono-traversable-1.0.12.0-lib-mono-traversable-config.drv
  /nix/store/bvw03gvk5p7dp7206ghn49rlqif6vzlj-mono-traversable-1.0.12.0-lib-mono-traversable-ghc-8.6.5.drv
  /nix/store/mlm0jh3bm2464hy7xzyk52djlnc6w04g-mono-traversable-1.0.12.0-lib-mono-traversable.drv
  /nix/store/vdi62mwwp41y1p8cjkqn2w2a7calqc6n-conduit-1.3.1.1-lib-conduit-config.drv
  /nix/store/g7pzjfc6xcv242y035iipy8qyg46sxxg-conduit-1.3.1.1-lib-conduit-ghc-8.6.5.drv
  /nix/store/wldmmmifzz8gzd2y3fyi4q317gbksagz-conduit-1.3.1.1-lib-conduit.drv
  /nix/store/ixb2zk3rzrsk4zs94p1hb7hwfmxgw1x4-streaming-commons-0.2.1.1-lib-streaming-commons-ghc-8.6.5.drv
  /nix/store/x8wh5x5kfzsqi1chrvf660lg7y6z58a7-streaming-commons-0.2.1.1-lib-streaming-commons.drv
  /nix/store/2yvs57sva9zz4bi66g2acmmjs3y62kj8-conduit-extra-1.3.4-lib-conduit-extra-config.drv
  /nix/store/9fc74fnnan8fjjfq6m0cq2aysbxxbffa-libyaml-0.1.1.0-lib-libyaml-config.drv
  /nix/store/i6z6d876r0imabax0rqm0pzqrf1rhc9n-libyaml-0.1.1.0-lib-libyaml-ghc-8.6.5.drv
  /nix/store/mj3q3ba6hs98d26h2hm6ka74hwbbgcc1-libyaml-0.1.1.0-lib-libyaml.drv
  /nix/store/d5dkyx6j2zfwgnxzy29ckcnvi23yf9cb-yaml-0.11.1.2-lib-yaml-config.drv
  /nix/store/y6m2nhq4pypa170l38h978nvvb4m91kj-conduit-extra-1.3.4-lib-conduit-extra-ghc-8.6.5.drv
  /nix/store/nmjsm761bgp53f0g6ic41wiayvry10ig-conduit-extra-1.3.4-lib-conduit-extra.drv
  /nix/store/w1y5zbrj07kg9fms4k09vi0cd7cfgpkc-yaml-0.11.1.2-lib-yaml-ghc-8.6.5.drv
  /nix/store/rlng22bndpr6piklq196vaylz8mma0c2-yaml-0.11.1.2-lib-yaml.drv
  /nix/store/1a166fb2ryp4mzpk5k3nlna4zx0gndvd-hie-bios-0.4.0-lib-hie-bios-config.drv
  /nix/store/1ps1hrq1kkkc687widnrz44q4m8c9ny3-hie-bios-0.4.0-lib-hie-bios-ghc-8.6.5.drv
  /nix/store/4i2658rkf96mbyc6mjywxyv5fc1r79x4-hie-bios-0.4.0-lib-hie-bios.drv
  /nix/store/5cbavn3v2nmwcb2n3ca23l1392n2bgax-ghcide-0.1.0-exe-ghcide-config.drv
  /nix/store/pb619g6bsa1msd965y85v0l539dn189z-ghcide-0.1.0-exe-ghcide-ghc-8.6.5.drv
  /nix/store/8dlxx8rfp7ns4xx5q44dbj6fzvlzi0ns-ghcide-0.1.0-exe-ghcide.drv
building '/nix/store/rfq06nkrjvi6wriqbipwjr6vavl96mdc-vector-0.12.0.3-lib-vector.drv'...
unpacking sources
unpacking source archive /nix/store/rf18cam13shch0mn3xhpnk1w3lx1m077-vector-0.12.0.3.tar.gz
source root is vector-0.12.0.3
setting SOURCE_DATE_EPOCH to timestamp 1000000000 of file vector-0.12.0.3/vector.cabal
patching sources
configuring
Configure flags:
--prefix=/nix/store/9cj8s83a52ry11drhapfcldd0r3rqa8v-vector-0.12.0.3-lib-vector lib:vector --package-db=clear --package-db=/nix/store/bz0z60sa74y0b6js23y6bbdwd1di75yc-vector-0.12.0.3-lib-vector-config/package.conf.d --flags=boundschecks --flags=-internalchecks --flags=-unsafechecks --flags=-wall --exact-configuration --dependency=primitive=primitive-0.6.4.0-EHFk47SD0sDIICRhZfAwV --dependency=rts=rts --dependency=ghc-heap=ghc-heap-8.6.5 --dependency=ghc-prim=ghc-prim-0.5.3 --dependency=integer-gmp=integer-gmp-1.0.2.0 --dependency=base=base-4.12.0.0 --dependency=deepseq=deepseq-1.4.4.0 --dependency=array=array-0.5.3.0 --dependency=ghc-boot-th=ghc-boot-th-8.6.5 --dependency=pretty=pretty-1.1.3.6 --dependency=template-haskell=template-haskell-2.14.0.0 --with-ghc=ghc --with-ghc-pkg=ghc-pkg --with-hsc2hs=hsc2hs --with-gcc=cc --with-ld=ld --with-ar=ar --with-strip=strip --disable-executable-stripping --disable-library-stripping --disable-library-profiling --disable-executable-profiling --enable-static --enable-shared --docdir=/nix/store/3ib35hxxjzvgs4lcz15saxg2hzfl5yij-vector-0.12.0.3-lib-vector-doc/share/doc/vector
Configuring library for vector-0.12.0.3..
Warning: The flag --disable-executable-profiling is deprecated. Please use
--disable-profiling instead.
building
Preprocessing library for vector-0.12.0.3..
Building library for vector-0.12.0.3..
[ 1 of 21] Compiling Data.Vector.Fusion.Util ( Data/Vector/Fusion/Util.hs, dist/build/Data/Vector/Fusion/Util.o )
[ 2 of 21] Compiling Data.Vector.Fusion.Bundle.Size ( Data/Vector/Fusion/Bundle/Size.hs, dist/build/Data/Vector/Fusion/Bundle/Size.o )
[ 3 of 21] Compiling Data.Vector.Generic.Mutable.Base ( Data/Vector/Generic/Mutable/Base.hs, dist/build/Data/Vector/Generic/Mutable/Base.o )
[ 4 of 21] Compiling Data.Vector.Generic.Base ( Data/Vector/Generic/Base.hs, dist/build/Data/Vector/Generic/Base.o )
[ 5 of 21] Compiling Data.Vector.Internal.Check ( Data/Vector/Internal/Check.hs, dist/build/Data/Vector/Internal/Check.o )
[ 6 of 21] Compiling Data.Vector.Fusion.Stream.Monadic ( Data/Vector/Fusion/Stream/Monadic.hs, dist/build/Data/Vector/Fusion/Stream/Monadic.o )
cachix use ghcide-nix
nix-env -iA ghcide-ghc865 -f https://github.com/cachix/ghcide-nix/tarball/master

i think thats' what i tried in the above comment and it still tries to build vector e.g. from scratch

You ran the command as sudo, which configured cachix for root, but not for your user.

@domenkozar yep this fixed for me -- thank you!