From 3a57cfa44938b2e71126e8fa6e2d7e899b7ade1c Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 10 Apr 2021 16:44:46 -0400 Subject: [PATCH] Add postgrest --- features/postgrest.nix | 45 ++++++++++++++++++++++++++++++++++++++++++ flake.nix | 5 ++++- hosts/p71.nix | 2 ++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 features/postgrest.nix diff --git a/features/postgrest.nix b/features/postgrest.nix new file mode 100644 index 0000000..e912ece --- /dev/null +++ b/features/postgrest.nix @@ -0,0 +1,45 @@ +{ pkgs, ... }: +let + postgrest = pkgs.haskellPackages.postgrest; +in +{ + # PostgreSQL itself + services.postgresql = { + enable = true; + package = pkgs.postgresql_12; + enableTCPIP = false; + # https://nixos.wiki/wiki/PostgreSQL + authentication = pkgs.lib.mkOverride 10 + '' + # Unix domain socket + local all all trust + # TCP/IP connections from loopback only + host all all ::1/128 trust + ''; + initialScript = pkgs.writeText "backend-initScript" '' + CREATE ROLE nixcloud WITH LOGIN PASSWORD 'nixcloud' CREATEDB; + CREATE DATABASE nixcloud; + GRANT ALL PRIVILEGES ON DATABASE nixcloud TO nixcloud; + ''; + }; + + # PostgREST as systemd service + systemd.services.postgrest = { + enable = true; + description = "PostgREST daemon"; + after = [ "postgresql.service" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = + let pgrstConf = pkgs.writeText "pgrst.conf" '' + db-uri = "postgres://postgres@localhost/postgres" + db-schema = "public" + db-anon-role = "postgres" + server-port = 7000 + ''; + in + "${postgrest}/bin/postgrest ${pgrstConf}"; + Restart = "always"; + }; + }; +} diff --git a/flake.nix b/flake.nix index 953bb87..81bdce5 100644 --- a/flake.nix +++ b/flake.nix @@ -17,7 +17,8 @@ modules = ([ # System configuration configurationNix - # ./features/virtualization.nix + + # Features common to all of my machines ./features/passwordstore.nix ./features/syncthing.nix ./features/email @@ -44,6 +45,8 @@ [ inputs.nixos-hardware.nixosModules.lenovo-thinkpad-p53 ./features/desktopish + # ./features/virtualization.nix + ./features/postgrest.nix ]; nixosConfigurations.x1c7 = mkHomeMachine ./hosts/x1c7.nix diff --git a/hosts/p71.nix b/hosts/p71.nix index ac7c44d..89059d4 100644 --- a/hosts/p71.nix +++ b/hosts/p71.nix @@ -84,6 +84,8 @@ obsidian signal-desktop ripgrep + fzf + htop ];