From 8d707f9a5390f08139bb873ba6fe8b9261f7c07a Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Sat, 24 Aug 2024 21:18:34 +0200 Subject: [PATCH] Get loomio server to start Crashes immediately on hitting any route because vue js stuff is not compiled yet. --- flake.lock | 6 +- flake.nix | 1 + hosts/test/configuration.nix | 25 ++---- hosts/test/loomio-credentials.yml.enc | 1 + hosts/test/loomio-master.key | 1 + modules/loomio.nix | 110 +++++++++++++++++++++++++- pkg/loomio/creds.patch | 21 +++++ pkg/loomio/default.nix | 63 ++++++++++----- pkg/loomio/gemfile-patch.nix | 4 +- pkg/loomio/gemset.nix | 20 +++-- pkg/loomio/puma.rb | 26 ++++++ pkg/loomio/update.sh | 2 +- 12 files changed, 226 insertions(+), 54 deletions(-) create mode 100644 hosts/test/loomio-credentials.yml.enc create mode 100644 hosts/test/loomio-master.key create mode 100644 pkg/loomio/creds.patch create mode 100644 pkg/loomio/puma.rb diff --git a/flake.lock b/flake.lock index 13821c5..c2af4a6 100644 --- a/flake.lock +++ b/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1710889954, - "narHash": "sha256-Pr6F5Pmd7JnNEMHHmspZ0qVqIBVxyZ13ik1pJtm2QXk=", + "lastModified": 1724334015, + "narHash": "sha256-5sfvc0MswIRNdRWioUhG58rGKGn2o90Ck6l6ClpwQqA=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "7872526e9c5332274ea5932a0c3270d6e4724f3b", + "rev": "6d204f819efff3d552a88d0a44b5aaaee172b784", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index a7b0aaf..4c617a0 100644 --- a/flake.nix +++ b/flake.nix @@ -19,6 +19,7 @@ system = "x86_64-linux"; modules = [ (import ./modules/overlay.nix) + ./modules/loomio.nix ./hosts/test/configuration.nix ]; }; diff --git a/hosts/test/configuration.nix b/hosts/test/configuration.nix index 23dbf96..92492d3 100644 --- a/hosts/test/configuration.nix +++ b/hosts/test/configuration.nix @@ -19,11 +19,10 @@ users.users.nixosvmtest.group = "nixosvmtest"; users.groups.nixosvmtest = {}; - users.groups.loomio = {}; - users.users.loomio = { - description = "User to run loomio"; - group = "loomio"; - isSystemUser = true; + services.loomio = { + enable = true; + encyrptedCredentials = ./loomio-credentials.yml.enc; + credentialEncryptionKeyFile = ./loomio-master.key; }; services.postgresql = { @@ -32,23 +31,9 @@ ensureUsers = [{ name = "loomio"; ensureDBOwnership = true; - # ensurePermissions = { "DATABASE loomio" = "ALL PRIVILEGES"; }; + ensureClauses.superuser = true; }]; }; - systemd.services.loomio = { - enable = true; - after = [ "basic.target" ]; - - serviceConfig = { - User = "loomio"; - Restart = "always"; - ExecStart = "${pkgs.loomio}/bin/loomio"; - }; - environment = { - DATABASE_URL = "postgresql://localhost/loomio"; - }; - }; - system.stateVersion = "23.11"; } diff --git a/hosts/test/loomio-credentials.yml.enc b/hosts/test/loomio-credentials.yml.enc new file mode 100644 index 0000000..45640a9 --- /dev/null +++ b/hosts/test/loomio-credentials.yml.enc @@ -0,0 +1 @@ +1LR0cmifVLl04EAAtWPaoBhy85l6u7pGPjiSheUe/vkKbu3S3MK4XV6vBOmGnki4yMrOvdpvpLomnlCxCxEyOYcDRtBh3LkgZ3+9Bx37IcRHfgobzWVG/ik1/ZA4w2zbo8u/oJD6/gtuJNXBTkWNgpo4/WCJddxrzbF1Jo/FawT/ecwPO5898x/VBZn79rMFqcSJ2NKY4noOhOr2+EosFBjEkU7T5QVag64WQDT5/Np2vVhFWPvCgyoXziKTjBpCIUE9dDcA7HFIPgZ5nZXIwdSmVdAN3cA1zDlQMGqA27R4tt9zuRkPCvnfNvfuuVp9FHuok7tUTFPNR6v6NPzvHNceHugUvFF9zu33MAl8tH9j5W3Wd7zPVxuYp9nU8nHPmQF5DlPUoqUERLq/0biF7+F/4KGkNl+DFkZW--EGCnUuZJQoZORDG3--UsPRfjEX4LFxe6ECg8uR9Q== \ No newline at end of file diff --git a/hosts/test/loomio-master.key b/hosts/test/loomio-master.key new file mode 100644 index 0000000..7073936 --- /dev/null +++ b/hosts/test/loomio-master.key @@ -0,0 +1 @@ +dd587169f25e5ed7e391a511da13f491 \ No newline at end of file diff --git a/modules/loomio.nix b/modules/loomio.nix index 3c18730..a3b89b2 100644 --- a/modules/loomio.nix +++ b/modules/loomio.nix @@ -1,12 +1,116 @@ -{lib, ...}: -{ +{pkgs, lib, config, ...}: +let + cfg = config.services.loomio; + package = pkgs.loomio; + + env = { + RAILS_ENV = "production"; + BUNDLE_FORCE_RUBY_PLATFORM = "true"; + + LOOMIO_DATABASE = "loomio"; + LOOMIO_ENCRYPTED_CREDENTIALS_PATH = cfg.encyrptedCredentials; + }; + cfgService = { + User = "loomio"; + Group = "loomio"; + WorkingDirectory = package; + StateDirectory = "loomio"; + }; +in { imports = []; options = { - enable = lib.mkEnableOption "loomio"; + services.loomio = { + enable = lib.mkEnableOption "loomio"; + encyrptedCredentials = lib.mkOption { + description = "Credentials required to run loomio"; + type = lib.types.path; + }; + credentialEncryptionKeyFile = lib.mkOption { + description = "File containing encryption key for the encyptedCredentials"; + type = lib.types.path; + }; + }; }; config = { + users.groups.loomio = {}; + users.users.loomio = { + description = "User to run loomio"; + group = "loomio"; + isSystemUser = true; + }; + + systemd.services.loomio-init-dirs = { + enable = true; + after = ["network.target" ]; + serviceConfig = cfgService // { + Type = "oneshot"; + }; + script = '' + cat > /var/lib/loomio/.secrets_env < + adapter: postgresql + database: <%= ENV['LOOMIO_DATABASE'] %> + host: /var/run/postgresql ''; + in stdenv.mkDerivation { name = "loomio"; inherit src; + nativeBuildInputs = [ gems gems.wrappedRuby ]; buildInputs = [gems ruby_3_2]; + buildPhase = '' + runHook preBuild + + cp ${databaseConfig} config/database.yml + cp ${./puma.rb} config/puma.rb + + export BUNDLE_FORCE_RUBY_PLATFORM=true + ${gems}/bin/bundle exec bootsnap precompile --gemfile app/ lib/ + + patchShebangs bin/ + + for b in $(ls ${gems}/bin/) + do + if [ ! -f bin/$b ]; then + ln -s ${gems}/bin/$b bin/$b + fi + done + + runHook postBuild + ''; + installPhase = '' - mkdir -p $out/{bin,share/loomio} - cp -r * $out/share/loomio - bin=$out/bin/loomio - cp ${databaseConfig} $out/share/loomio/config/database.yml - cat > $bin <