From 7998bacc15544a08de2bcb6f82e4cd3d81dc7dd1 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 2 Oct 2017 20:17:33 +0200 Subject: [PATCH] Nix build harness --- .gitignore | 3 +++ default.nix | 6 ++++++ gup/Gupfile | 4 ++++ gup/cabal2nix.gup | 8 ++++++++ gup/hpack.gup | 6 ++++++ shell.nix | 50 +++++++++++++++++++++++++++++++++++++++++++++++ stack.nix | 11 +++++++++++ stack.yaml | 6 +++++- 8 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 default.nix create mode 100644 gup/Gupfile create mode 100755 gup/cabal2nix.gup create mode 100755 gup/hpack.gup create mode 100644 shell.nix create mode 100644 stack.nix diff --git a/.gitignore b/.gitignore index d65329b85..99d4a3d3c 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ cabal.sandbox.config *~ \#* uniworx.cabal +uniworx.nix +.gup/ +.dbsettings.yml \ No newline at end of file diff --git a/default.nix b/default.nix new file mode 100644 index 000000000..21608bb19 --- /dev/null +++ b/default.nix @@ -0,0 +1,6 @@ +argumentPackages@{ ... }: + +let + defaultPackages = (import {}).haskellPackages; + haskellPackages = defaultPackages // argumentPackages; +in import ./uniworx.nix { inherit (haskellPackages) callPackage; } diff --git a/gup/Gupfile b/gup/Gupfile new file mode 100644 index 000000000..d2db73f2f --- /dev/null +++ b/gup/Gupfile @@ -0,0 +1,4 @@ +cabal2nix.gup: + *.nix +hpack.gup: + *.cabal \ No newline at end of file diff --git a/gup/cabal2nix.gup b/gup/cabal2nix.gup new file mode 100755 index 000000000..9854cec0e --- /dev/null +++ b/gup/cabal2nix.gup @@ -0,0 +1,8 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i zsh -p zsh haskellPackages.cabal2nix + +gup -u ${2:r}.cabal + +cd ${2:h} + +cabal2nix . > $1 diff --git a/gup/hpack.gup b/gup/hpack.gup new file mode 100755 index 000000000..9e1052b02 --- /dev/null +++ b/gup/hpack.gup @@ -0,0 +1,6 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i sh -p haskellPackages.hpack + +gup -u package.yaml + +hpack - >$1 \ No newline at end of file diff --git a/shell.nix b/shell.nix new file mode 100644 index 000000000..837e26c67 --- /dev/null +++ b/shell.nix @@ -0,0 +1,50 @@ +{ nixpkgs ? import {}, compiler ? null }: + +let + inherit (nixpkgs) pkgs; + + haskellPackages = if isNull compiler + then pkgs.haskellPackages + else pkgs.haskell.packages.${compiler}; + + drv = haskellPackages.callPackage ./uniworx.nix {}; + + postgresSchema = pkgs.writeText "schema.sql" '' + CREATE USER uniworx; + CREATE DATABASE uniworx_test; + GRANT ALL ON DATABASE uniworx_test TO uniworx; + ''; + + postgresHba = pkgs.writeText "hba_file" '' + local all all trust + ''; + + override = oldAttrs: { + nativeBuildInputs = oldAttrs.nativeBuildInputs ++ (with pkgs; [ postgresql ]) ++ (with haskellPackages; [ stack stack-run yesod-bin ]); + shellHook = '' + ${oldAttrs.shellHook} + export PROMPT_INFO="${oldAttrs.name}" + + pgDir=$(mktemp -d) + pgSockDir=$(mktemp -d) + pgLogFile=$(mktemp) + pg_ctl init -D ''${pgDir} + pg_ctl start -D ''${pgDir} -l ''${pgLogFile} -w -o "-k ''${pgSockDir} -c listen_addresses=''' -c hba_file='${postgresHba}' -c unix_socket_permissions=0700" + export PGHOST=''${pgSockDir} PGLOG=''${pgLogFile} + psql -f ${postgresSchema} postgres + printf "Postgres logfile is %s\nPostgres socket directory is %s\n" ''${pgLogFile} ''${pgSockDir} + cat > .dbsettings.yml < {}) }: + +let + inherit (nixpkgs) haskell pkgs; +in haskell.lib.buildStackProject { + inherit ghc; + name = "stackenv"; + buildInputs = with pkgs; + [ postgresql zlib + ]; +} diff --git a/stack.yaml b/stack.yaml index 44ef0f1f4..e845ca645 100644 --- a/stack.yaml +++ b/stack.yaml @@ -63,4 +63,8 @@ extra-package-dbs: [] # extra-lib-dirs: [/path/to/dir] # # Allow a newer minor version of GHC than the snapshot specifies -# compiler-check: newer-minor \ No newline at end of file +# compiler-check: newer-minor + +nix: + packages: [] + shell-file: ./stack.nix