From 84131562a94a3352c1c4229ad78289600e678154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20K=C3=A1n=C4=9B?= Date: Thu, 21 Jan 2021 18:18:44 +0100 Subject: [PATCH] Add common dev environment in Nix --- db.nix | 12 ------------ flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 27 +++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 12 deletions(-) delete mode 100644 db.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/db.nix b/db.nix deleted file mode 100644 index 436bc20..0000000 --- a/db.nix +++ /dev/null @@ -1,12 +0,0 @@ -with - import (builtins.fetchTarball { - url = "https://github.com/nixos/nixpkgs/archive/4d373182597cff60b3a820affb5a73dd274e205b.tar.gz"; - sha256 = "1kvsnlsq1czgk085rllg1b427n6lv5w3a2z1igfc95n81jpvcf58"; - }) {}; -let -in - stdenv.mkDerivation rec { - name = "tinyquiz-db-env"; - - buildInputs = [ postgresql ]; - } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..58ef169 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1611053426, + "narHash": "sha256-ZYcn9Jz7S3Ib3PPcPsn6lE9HGtH5ofacOYsu/puZd9o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "646f528cce6db1f89f6e635a7589bf1be6169ffb", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-20.09", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e5d07c9 --- /dev/null +++ b/flake.nix @@ -0,0 +1,27 @@ +{ + description = "Tinyquiz – an open source online quiz platform"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-20.09"; + + outputs = { self, nixpkgs }: + let + pkgs = nixpkgs.legacyPackages.x86_64-linux; + in + { + defaultPackage.x86_64-linux = self.packages.x86_64-linux.tinyquiz; + packages.x86_64-linux.tinyquiz = pkgs.hello; # TODO + packages.x86_64-linux.dev = pkgs.writeShellScriptBin "dev" '' + echo "This dev script must be run from the project root, otherwise unexpected behavior might occur." + read -p "Are you in the right directory and shall I continue? (y/n): " ack + + if [ "$ack" != y ]; then exit 1; fi + + unset GOROOT # Use the one bundled into the binary. I don't currently know who sets this to the wrong one + + '${pkgs.findutils}/bin/find' cmd pkg ui/html | '${pkgs.entr}/bin/entr' -dr '${pkgs.go_1_14}/bin/go' run ./cmd/web + ''; + packages.x86_64-linux.devDb = pkgs.writeShellScriptBin "devDb" '' + '${pkgs.postgresql}/bin/postgres' -D .pg-data -k "$PWD/.pg-sockets" #-c listen_addresses="" # Goland does not support connecting over socket + ''; + }; +}