7

I've got a program which depends on the static and config directories being available on the server along with the binary. The default build phases for NixOps doesn't include these files, as far as I can tell it just compiles the binary and then copies the binary to the server.

How can I modify the build phases such that the static and config directories are available on the server? I tried adding:

preInstall = ''
  echo "copying static and config files"
  cp -a ../static $out/static
  cp -a ../config $out/config
'';

But that doesn't seem to actually copy the files over, and I never see the echo command executed. Here is a gist of the configuration file used by NixOps. The error on the server is:

[root@pprjam:~]# systemctl status pprjam
● pprjam.service - pprjam webapp
   Loaded: loaded (/nix/store/z2s52f39p3dx8q9b06rkaqqw5mhdvnmq-unit-pprjam.service/pprjam.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2018-02-17 01:29:57 UTC; 1min 27s ago
  Process: 6917 ExecStart=/nix/store/khilhwldcbm0xm3a3bzhy6f0kwdk8w1p-pprjam-0.0.0/bin/pprjam (code=exited, status=1/FAILURE)
 Main PID: 6917 (code=exited, status=1/FAILURE)

Feb 17 01:29:51 pprjam systemd[1]: Started pprjam webapp.
Feb 17 01:29:56 pprjam pprjam[6917]: pprjam: static: getDirectoryContents:openDirStream: does not exist (No such file or directory)
Feb 17 01:29:57 pprjam systemd[1]: pprjam.service: Main process exited, code=exited, status=1/FAILURE
Feb 17 01:29:57 pprjam systemd[1]: pprjam.service: Unit entered failed state.
Feb 17 01:29:57 pprjam systemd[1]: pprjam.service: Failed with result 'exit-code'.
user2407038
  • 14,400
  • 3
  • 29
  • 42
Ben
  • 574
  • 3
  • 12
  • Reading [this issue](https://github.com/NixOS/nixpkgs/issues/25507), can I use `runCommand` in the `preInstall` hook to execute the `cp` commands? – Ben Feb 17 '18 at 03:13
  • As far as I can tell, this has nothing to do with Haskell nor Yesod (except that coincidentally you are encountering this issue when building a Haskell program). I've edited to reflect this. If you believe this to be incorrect please feel free to revert the edit, but also elaborate as to why this is a Haskell and/or Yesod -specific issue. – user2407038 Feb 17 '18 at 12:44
  • Did you check the out directory manually with `ls /nix/store/khilhwldcbm0xm3a3bzhy6f0kwdk8w1p-pprjam-0.0.0` or similar? Also note that you're referencing the `static` directory by relative path. Did you set up the working directory correctly? – Robert Hensing Feb 17 '18 at 14:42
  • It's not in the `/nix/store/...pprjam-0.0.0` directory. How would I be able to check that the working directory is correct and that I'm referencing `static` correctly? The `echo` call doesn't show up in the `nixops` output – Ben Feb 17 '18 at 17:25
  • [Here](https://gist.github.com/bsima/1f8b9fea22cf20e4547b16f4abe8f1a4) is the nixops output – Ben Feb 17 '18 at 17:32

1 Answers1

3

In your gist it looks like you are merging the preInstall attribute onto the existing attributes for your pprjam package. That would mean that you are changing the attributes of your package after it has already been built. If that's right then you probably want to make use of overrideAttrs instead (see the manual and source).

Also by config and static directories do you mean those in /etc? AFAIK they are fairly fundamental to a NixOS system and should always be present.

brocking
  • 821
  • 6
  • 9
  • `config` and `static` are directories in my project, specific only to my code. – Ben Feb 23 '18 at 19:32
  • 1
    @Ben: Would you be willing to show how you got it to work? – hhefesto Jun 04 '19 at 01:43
  • 1
    FWIW: I face a similar problem and my tech setup is similar. Deploying a Yesod app with NixOps. In my case, I make things work by declaring my static files as `data-files` in the cabal file, and I use nginx to help requests get to the right place on the file system. Check [here](https://github.com/spencerjanssen/rotothopter/blob/78ad27ce2def8baca1be02c1261414aef18eca5b/deploy/single.nix#L80-L82) and [here](https://github.com/spencerjanssen/rotothopter/blob/78ad27ce2def8baca1be02c1261414aef18eca5b/rotothopter.cabal#L9-L24). – Jezen Thomas Jul 15 '19 at 11:10