commit 37aa2fa2a57d33ce52a749d448e181e3a77469f6
parent 1f8936cd3249477cc348f81f4cec0c78c4d12de1
Author: Silas Brack <silasbrack@gmail.com>
Date: Thu, 3 Oct 2024 13:52:33 +0200
Clean up nix modules
Diffstat:
5 files changed, 1 insertion(+), 192 deletions(-)
diff --git a/infrastructure/_apps/default.nix b/infrastructure/_apps/default.nix
@@ -1,6 +0,0 @@
-{
- imports = [
- # ./test.nix
- ./hello.nix
- ];
-}
diff --git a/infrastructure/_apps/hello.nix b/infrastructure/_apps/hello.nix
@@ -1,36 +0,0 @@
-{ lib, pkgs, config, ... }:
-with lib;
-let
- # Shorter name to access final settings a
- # user of hello.nix module HAS ACTUALLY SET.
- # cfg is a typical convention.
- cfg = config.services.hello;
-in {
- # Declare what settings a user of this "hello.nix" module CAN SET.
- options.services.hello = {
- enable = mkEnableOption "hello service";
- greeter = mkOption {
- type = types.str;
- default = "world";
- };
- };
-
- # Define what other settings, services and resources should be active IF
- # a user of this "hello.nix" module ENABLED this module
- # by setting "services.hello.enable = true;".
- # config = mkIf cfg.enable {
- # systemd.services.hello = {
- # wantedBy = [ "multi-user.target" ];
- # serviceConfig.ExecStart = "${pkgs.hello}/bin/hello -g'Hello, ${escapeShellArg cfg.greeter}!'";
- # };
- # };
- config.services.postgres = {
- enable = true;
- ensureDatabases = [ "test" ];
- authentication = pkgs.lib.mkOverride 10 ''
- #type database DBuser auth-method
- local all all trust
- '';
- };
-}
-
diff --git a/infrastructure/_apps/test.nix b/infrastructure/_apps/test.nix
@@ -1,148 +0,0 @@
-{ config, lib, pkgs, ... }:
-
-with lib;
-
-let
-
- pkg = import ./.;
-
- migrations = pkg.migrations;
- server = pkg.server;
-
- cfg = config.services.myapp;
-
-in {
-
- options = {
- services.myapp = {
- enable = mkEnableOption "My App";
-
- environment = mkOption {
- type = types.enum [ "dev" "prod" ];
- default = "dev";
- example = "prod";
- description = "The environment (dev / prod) to deploy as.";
- };
-
- user = mkOption {
- type = types.str;
- default = "myapp";
- description = "User account under which my app runs.";
- };
-
- port = mkOption {
- type = types.nullOr types.int;
- default = 3003;
- example = 8080;
- description = ''
- The port to bind my app server to.
- '';
- };
- };
- };
-
- config = mkIf cfg.enable {
-
- networking.firewall.allowedTCPPorts = [ cfg.port ];
-
- users.users.${cfg.user} = {
- name = cfg.user;
- description = "My app service user";
- isSystemUser = true;
- createHome = false;
- packages = with pkgs; [
- gleam
- erlang_27
- rebar3
- ];
- };
-
- systemd.services = {
- # postgres-migration = {
- # description = "Postgres migrations";
- # wantedBy = [ "multi-user.target" ];
- # after = [ "postgresql.service" ];
- # requires = [ "postgresql.service" ];
- # };
-
- myapp = {
- wantedBy = [ "multi-user.target" ];
- description = "Start my app server.";
- after = [ "network.target" ];
- # requires = [ "db-migration.service" ];
-
- # environment = {
- # DB_URI = "";
- # };
-
- serviceConfig = {
- Type = "simple";
- User = cfg.user;
- ExecStart = "/root/apps/myapp/test_pgo_app";
- Restart = "always";
- KillMode = "process";
- };
- };
- };
-
- services = mkIf cfg.environment == "dev" {
- postgresql = {
- enable = true;
- enableTCPIP = true;
- ensureDatabases = [ cfg.user ];
- ensureUsers = [
- {
- name = cfg.user;
- ensurePermissions = {
- "DATABASE ${cfg.user}" = "ALL PRIVILEGES";
- };
- }
- ];
- authentication = pkgs.lib.mkOverride 10 ''
- local sameuser all peer
- host sameuser all ::1/32 trust
- '';
- };
- };
-
- # systemd.services = {
- #
- # # db-migration = {
- # # description = "DB migrations script";
- # # wantedBy = [ "multi-user.target" ];
- # # after = [ "postgresql.service" ];
- # # requires = [ "postgresql.service" ];
- # #
- # # environment = {
- # # DATABASE_URL = "postgres://${cfg.user}@localhost:5432/myapp?sslmode=disable";
- # # };
- # #
- # # serviceConfig = {
- # # User = cfg.user;
- # # Type = "oneshot";
- # # ExecStart = "${pkgs.dbmate}/bin/dbmate -d ${migrations} --no-dump-schema up";
- # # };
- # # };
- #
- # myapp = {
- # wantedBy = [ "multi-user.target" ];
- # description = "Start my app server.";
- # after = [ "network.target" ];
- # # requires = [ "db-migration.service" ];
- #
- # # environment = {
- # # APP_PORT = toString cfg.port;
- # # DATABASE_URL = "postgres:///${cfg.user}";
- # # };
- #
- # serviceConfig = {
- # Type = "simple";
- # User = cfg.user;
- # ExecStart = ''${server}/bin/server'';
- # Restart = "always";
- # KillMode = "process";
- # };
- # };
- # };
- };
-}
diff --git a/apps/my-app/module.nix b/infrastructure/default.nix
diff --git a/infrastructure/hive.nix b/infrastructure/hive.nix
@@ -45,8 +45,7 @@ in {
imports = [
./vpn.nix
sops_nix
- # ./_apps/hello.nix
- # ../apps/my-app/module.nix
+ # ../apps/my-app/
];
# networking.firewall.allowedTCPPorts = [ 8000 ];
security.pki.certificateFiles = [ ./secrets/ca-certificate.crt ];