diff options
author | Cara Salter <cara@devcara.com> | 2022-04-14 13:06:54 -0400 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2022-04-18 23:05:25 -0400 |
commit | ffacf1c8fc820de3890ba6231b644e9e4a65ce28 (patch) | |
tree | 475537cef44f8eb0e7ed1269fd8c76e700c62918 /flake.nix | |
parent | 9b4707192557cdd64dd82c5883e54758d0d66512 (diff) | |
download | glitch-ng-ffacf1c8fc820de3890ba6231b644e9e4a65ce28.tar.gz glitch-ng-ffacf1c8fc820de3890ba6231b644e9e4a65ce28.zip |
FLAKE
Diffstat (limited to 'flake.nix')
-rw-r--r-- | flake.nix | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b559c45 --- /dev/null +++ b/flake.nix @@ -0,0 +1,97 @@ +{ + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + naersk.url = "github:nix-community/naersk"; + }; + + outputs = { self, nixpkgs, flake-utils, naersk }: + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = nixpkgs.legacyPackages."${system}"; + naersk-lib = naersk.lib."${system}"; + in + rec { + # `nix build` + deps = with pkgs; [ + pkg-config + openssl + gcc + ]; + packages.glitch-ng = naersk-lib.buildPackage { + pname = "glitch-ng"; + root = ./.; + buildInputs = deps; + }; + defaultPackage = packages.glitch-ng; + + # `nix run` + apps.glitch-ng = flake-utils.lib.mkApp { + drv = packages.glitch-ng; + }; + defaultApp = apps.glitch-ng; + + nixosModules.glitch = { config, lib, ... }: { + options = { + services.glitch-ng.enable = lib.mkEnableOption "enable glitch NG"; + services.glitch-ng.environment-file-location = lib.mkOption { + type = lib.types.path; + default = "/var/lib/glitch-ng/.env"; + description = "The location of the environment file"; + }; + }; + + config = lib.mkIf config.services.glitch-ng.enable { + users.groups.glitch-ng = { + members = [ "glitch-ng" ]; + }; + users.users.glitch-ng = { + createHome = true; + isSystemUser = true; + home = "/var/lib/glitch-ng"; + group = "glitch-ng"; + }; + + systemd.services.glitch-ng = { + wantedBy = [ "multi-user.target" ]; + after = [ "glitch-ng-init.service" ]; + requires = [ "glitch-ng-init.service" ]; + serviceConfig = { + User = "glitch-ng"; + Group = "glitch-ng"; + Restart = "always"; + WorkingDirectory = "${defaultPackage}"; + ExecStart = "${defaultPackage}/bin/glitch-ng"; + EnvironmentFile = "${config.services.glitch-ng.environment-file-location}"; + }; + }; + + systemd.services.glitch-ng-init = { + wantedBy = [ "multi-user.target" ]; + requires = [ "postgresql.service" ]; + after = [ "postgresql.service" ]; + description = "Initialize for glitch-ng"; + + script = with pkgs; '' + if ! [ -e /var/lib/glitch-ng/.db-created ]; then + runuser -u ${config.services.postgresql.superUser} -- ${config.services.postgresql.package}/bin/createuser glitch-ng + runuser -u ${config.services.postgresql.superUser} -- ${config.services.postgresql.package}/bin/createdb -O glitch-ng glitch + touch /var/lib/glitch-ng/.db-created + fi + ''; + serviceConfig = { + Type = "oneshot"; + }; + }; + + services.postgresql.enable = true; + + }; + }; + + # `nix develop` + devShell = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ rustc cargo ] ++ deps; + }; + } + ); +} |