From 56db4d295e5f8b4e024c19b03b87d19f436ccda5 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Fri, 23 Aug 2024 10:24:36 +0200 Subject: [PATCH] WIP --- flake.nix | 12 +++++++- hosts/test/configuration.nix | 54 ++++++++++++++++++++++++++++++++++++ modules/overlay.nix | 7 +++++ pkg/loomio/default.nix | 9 +++++- 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 hosts/test/configuration.nix create mode 100644 modules/overlay.nix diff --git a/flake.nix b/flake.nix index 020a08c..a7b0aaf 100644 --- a/flake.nix +++ b/flake.nix @@ -13,5 +13,15 @@ loomio = pkgs.callPackage ./pkg/loomio/default.nix {}; inherit pkgs; }; - }); + }) // { + nixosConfigurations = { + test-vm = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + (import ./modules/overlay.nix) + ./hosts/test/configuration.nix + ]; + }; + }; + }; } diff --git a/hosts/test/configuration.nix b/hosts/test/configuration.nix new file mode 100644 index 0000000..23dbf96 --- /dev/null +++ b/hosts/test/configuration.nix @@ -0,0 +1,54 @@ +{pkgs, ...}: { + virtualisation.vmVariant = { + # following configuration is added only when building VM with build-vm + virtualisation = { + memorySize = 2048; # Use 2048MiB memory. + cores = 3; + }; + }; + + users.users.root.openssh.authorizedKeys.keys = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMNeQYLFauAbzDyIbKC86NUh9yZfiyBm/BtIdkcpZnSU" + ]; + + services.openssh.enable = true; + users.users.root.initialPassword = "root"; + + users.users.nixosvmtest.isSystemUser = true ; + users.users.nixosvmtest.initialPassword = "test"; + users.users.nixosvmtest.group = "nixosvmtest"; + users.groups.nixosvmtest = {}; + + users.groups.loomio = {}; + users.users.loomio = { + description = "User to run loomio"; + group = "loomio"; + isSystemUser = true; + }; + + services.postgresql = { + enable = true; + ensureDatabases = [ "loomio" ]; + ensureUsers = [{ + name = "loomio"; + ensureDBOwnership = true; + # ensurePermissions = { "DATABASE loomio" = "ALL PRIVILEGES"; }; + }]; + }; + + 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/modules/overlay.nix b/modules/overlay.nix new file mode 100644 index 0000000..279f999 --- /dev/null +++ b/modules/overlay.nix @@ -0,0 +1,7 @@ +{config, pkgs, ...}: { + nixpkgs.overlays = [ + (self: super: { + loomio = super.callPackage ../pkg/loomio {}; + }) + ]; +} diff --git a/pkg/loomio/default.nix b/pkg/loomio/default.nix index b9837b0..8965a9a 100644 --- a/pkg/loomio/default.nix +++ b/pkg/loomio/default.nix @@ -1,4 +1,4 @@ -{stdenv, callPackage, bundlerEnv, ruby_3_2 }: +{stdenv, writeText, callPackage, bundlerEnv, ruby_3_2 }: let gemfile-patch = callPackage ./gemfile-patch.nix {}; @@ -9,6 +9,11 @@ let gemset = ./. + "/gemset.nix"; gemdir = src; }; + + databaseConfig = writeText "database.yml" '' + production: + url: <%= ENV['DATABASE_URL'] %> + ''; in stdenv.mkDerivation { name = "loomio"; inherit src; @@ -17,11 +22,13 @@ in stdenv.mkDerivation { 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 <