From 6f1b17a6007dea2afbd239848be97ffbca9105fe Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Thu, 4 Apr 2024 18:37:40 -0400 Subject: [PATCH] meta: Merge postgres module with shell Realistically this might be more related to "system" than shell, however it may also be advantageous to keep system as minimal as possible since it could also be argued that interpreted programming languages are a part of the system. --- modules/postgres.nix | 25 ------------------------- modules/shell.nix | 28 ++++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 29 deletions(-) delete mode 100644 modules/postgres.nix diff --git a/modules/postgres.nix b/modules/postgres.nix deleted file mode 100644 index b1e5f593..00000000 --- a/modules/postgres.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ pkgs, ... }: - -{ - services.postgresql = { - enable = true; - - ensureUsers = [ - { - name = "user"; - } - { - name = "cooldbname"; - ensureDBOwnership = true; - } - ]; - - ensureDatabases = [ - "cooldbname" - ]; - }; - - environment.systemPackages = with pkgs; [ - pgcli - ]; -} diff --git a/modules/shell.nix b/modules/shell.nix index 5d0e6c72..3c0e14a3 100644 --- a/modules/shell.nix +++ b/modules/shell.nix @@ -2,15 +2,19 @@ let inherit (pkgs) fish htop-vim; - inherit (lib) mkEnableOption mkIf; + inherit (lib) mkEnableOption mkIf mkMerge singleton; + inherit (builtins) attrValues; + inherit (cfg) postgres; + inherit (config.modules.system) username; cfg = config.modules.shell; in { options.modules.shell = { + postgres = mkEnableOption "postgres database and pgcli for containers"; }; - config = with cfg; { + config = { users.defaultUserShell = fish; environment.shells = [ fish ]; @@ -24,8 +28,24 @@ in VISUAL = "nvim"; }; - environment.systemPackages = builtins.attrValues { - inherit (pkgs) wget jq eza fd fzf ripgrep; + environment.systemPackages = mkMerge [ + (attrValues { + inherit (pkgs) wget jq eza fd fzf ripgrep; + }) + + (mkIf postgres (attrValues { + inherit (pkgs) pgcli; + })) + ]; + + services.postgresql = mkIf postgres { + enable = true; + + ensureUsers = singleton { + name = username; + }; + + ensureDatabases = [ username ]; }; programs = {