diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..4cda12f --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +watch_file flake.nix +watch_file flake.lock +use_flake ./dev diff --git a/.github/workflows/attic.yml b/.github/workflows/attic.yml index 8b433fc..552ae4b 100644 --- a/.github/workflows/attic.yml +++ b/.github/workflows/attic.yml @@ -22,4 +22,4 @@ jobs: endpoint: https://attic.chvp.be cache: accentor token: '${{ secrets.ATTIC_AUTH_TOKEN }}' - - run: nix build -L --no-link .#devShells.x86_64-linux.default + - run: nix build -L --no-link ./dev#devShells.x86_64-linux.default diff --git a/default.nix b/default.nix index 9b71b64..c5abcb7 100644 --- a/default.nix +++ b/default.nix @@ -1,4 +1,9 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: with lib; @@ -21,9 +26,7 @@ let RAILS_TRANSCODES_PATH = "${cfg.home}/transcodes"; RUBY_ENABLE_YJIT = "1"; }; - exports = concatStringsSep - "\n" - (mapAttrsToList (name: value: "export ${name}=\"${value}\"") env); + exports = concatStringsSep "\n" (mapAttrsToList (name: value: "export ${name}=\"${value}\"") env); console = pkgs.writeShellScriptBin "accentor-console" '' set -ex ${exports} @@ -34,7 +37,8 @@ let in { options.services.accentor = { - enable = mkEnableOption ''Accentor music server. + enable = mkEnableOption '' + Accentor music server. Accentor provides an API through a Ruby on Rails application which can be accessed using the Web UI. @@ -67,7 +71,11 @@ in Queues can be configured in different ways. Please check the good job docs for the possibilities: https://github.com/bensheldon/good_job#optimize-queues-threads-and-processes ''; default = [ "+within_30_seconds,within_5_minutes,within_30_minutes,whenever" ]; - example = [ "within_30_seconds" "within_5_minutes:5;within_30_minutes:2;whenever:2" "+within_30_seconds,within_5_minutes,within_30_minutes,whenever" ]; + example = [ + "within_30_seconds" + "within_5_minutes:5;within_30_minutes:2;whenever:2" + "+within_30_seconds,within_5_minutes,within_30_minutes,whenever" + ]; type = types.listOf types.str; }; @@ -132,10 +140,12 @@ in environment.systemPackages = [ console ]; services.postgresql = { - ensureUsers = [{ - name = "accentor"; - ensureDBOwnership = true; - }]; + ensureUsers = [ + { + name = "accentor"; + ensureDBOwnership = true; + } + ]; ensureDatabases = [ "accentor" ]; }; @@ -149,11 +159,21 @@ in systemd.services = { accentor-api = { - after = [ "network.target" "postgresql.service" ]; - requires = [ "postgresql.service" "accentor-api.socket" ]; + after = [ + "network.target" + "postgresql.service" + ]; + requires = [ + "postgresql.service" + "accentor-api.socket" + ]; wantedBy = [ "multi-user.target" ]; environment = env; - path = [ pkgs.ffmpeg gems gems.wrappedRuby ]; + path = [ + pkgs.ffmpeg + gems + gems.wrappedRuby + ]; serviceConfig = { EnvironmentFile = cfg.environmentFile; Type = "simple"; @@ -167,16 +187,25 @@ in ExecStart = "${gems}/bin/puma -C ${api}/config/puma.rb"; }; }; - } // (builtins.foldl' (x: y: x // y) { } (lib.lists.imap0 - (index: value: { + } + // (builtins.foldl' (x: y: x // y) { } ( + lib.lists.imap0 (index: value: { "accentor-worker-${toString (index)}" = { - after = [ "network.target" "accentor-api.service" "postgresql.service" ]; + after = [ + "network.target" + "accentor-api.service" + "postgresql.service" + ]; requires = [ "postgresql.service" ]; wantedBy = [ "multi-user.target" ]; environment = env // { GOOD_JOB_QUEUES = value; }; - path = [ pkgs.ffmpeg gems gems.wrappedRuby ]; + path = [ + pkgs.ffmpeg + gems + gems.wrappedRuby + ]; serviceConfig = { EnvironmentFile = cfg.environmentFile; Type = "simple"; @@ -187,8 +216,7 @@ in ExecStart = "${gems}/bin/bundle exec good_job start"; }; }; - }) - cfg.workers + }) cfg.workers )) // lib.optionalAttrs cfg.rescanTimer.enable { accentor-rescan = { @@ -196,7 +224,10 @@ in restartIfChanged = false; unitConfig.X-StopOnRemoval = false; environment = env; - path = [ gems gems.wrappedRuby ]; + path = [ + gems + gems.wrappedRuby + ]; serviceConfig = { EnvironmentFile = cfg.environmentFile; Type = "oneshot"; @@ -213,7 +244,10 @@ in accentor-api = { wantedBy = [ "sockets.target" ]; wants = [ "accentor-api.service" ]; - listenStreams = [ "[::]:3000" "/run/accentor/server.socket" ]; + listenStreams = [ + "[::]:3000" + "/run/accentor/server.socket" + ]; socketConfig = { Backlog = 1024; NoDelay = true; diff --git a/dev/flake.lock b/dev/flake.lock new file mode 100644 index 0000000..28f2bfd --- /dev/null +++ b/dev/flake.lock @@ -0,0 +1,45 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1791918082, + "narHash": "sha256-oN9JrhRfHa7MUTdUq+11dHn7u0Z4WfEA4mhzBq0/zoQ=", + "owner": "numtide", + "repo": "devshell", + "rev": "9e29c63dde99a2d80c94b3d024c9768c01544558", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1794042290, + "narHash": "sha256-VZ8WvA9m3XN36juXyg/GwbDRU2OezOHJlXpJCXkccv0=", + "rev": "f4a03c008967841f2a0b3cb7c436fc6fc31671f6", + "type": "tarball", + "url": "https://releases.nixos.org/nixos/unstable/nixos-26.11pre1113206.f4a03c008967/nixexprs.tar.zst" + }, + "original": { + "type": "tarball", + "url": "https://channels.nixos.org/nixos-unstable/nixexprs.tar.zst" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/dev/flake.nix b/dev/flake.nix new file mode 100644 index 0000000..b4c10b5 --- /dev/null +++ b/dev/flake.nix @@ -0,0 +1,25 @@ +{ + description = "Development flake for accentor nixos modules"; + inputs = { + nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.zst"; + devshell = { + url = "github:numtide/devshell"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + outputs = inputs: { + devShells = builtins.mapAttrs ( + system: pkgs': + let + pkgs = pkgs'.extend inputs.devshell.overlays.default; + in + { + flake = pkgs.devshell.mkShell { + name = "Accentor flake"; + packages = [ pkgs.nixfmt ]; + }; + default = inputs.self.devShells.${system}.flake; + } + ) inputs.nixpkgs.legacyPackages; + }; +} diff --git a/flake.lock b/flake.lock index 502898d..b4cf2ee 100644 --- a/flake.lock +++ b/flake.lock @@ -3,9 +3,7 @@ "api": { "inputs": { "bundix": "bundix", - "devshell": [ - "devshell" - ], + "devshell": "devshell", "flake-utils": "flake-utils", "nixpkgs": [ "nixpkgs" @@ -50,15 +48,37 @@ "devshell": { "inputs": { "nixpkgs": [ + "api", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1768818222, + "narHash": "sha256-460jc0+CZfyaO8+w8JNtlClB2n4ui1RbHfPTLkpwhU8=", + "owner": "numtide", + "repo": "devshell", + "rev": "255a2b1725a20d060f566e4755dbf571bbbb5f76", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "devshell_2": { + "inputs": { + "nixpkgs": [ + "web", "nixpkgs" ] }, "locked": { - "lastModified": 1791918082, - "narHash": "sha256-oN9JrhRfHa7MUTdUq+11dHn7u0Z4WfEA4mhzBq0/zoQ=", + "lastModified": 1768818222, + "narHash": "sha256-460jc0+CZfyaO8+w8JNtlClB2n4ui1RbHfPTLkpwhU8=", "owner": "numtide", "repo": "devshell", - "rev": "9e29c63dde99a2d80c94b3d024c9768c01544558", + "rev": "255a2b1725a20d060f566e4755dbf571bbbb5f76", "type": "github" }, "original": { @@ -108,11 +128,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1793726008, - "narHash": "sha256-iNjybNORi/2+shilhMlkNr01UHWKOHRGzQyIyvobs9o=", - "rev": "1d060086d60cb76a40cf37109f979d88a5bd6396", + "lastModified": 1794042290, + "narHash": "sha256-VZ8WvA9m3XN36juXyg/GwbDRU2OezOHJlXpJCXkccv0=", + "rev": "f4a03c008967841f2a0b3cb7c436fc6fc31671f6", "type": "tarball", - "url": "https://releases.nixos.org/nixos/unstable/nixos-26.11pre1107793.1d060086d60c/nixexprs.tar.zst" + "url": "https://releases.nixos.org/nixos/unstable/nixos-26.11pre1113206.f4a03c008967/nixexprs.tar.zst" }, "original": { "type": "tarball", @@ -122,7 +142,6 @@ "root": { "inputs": { "api": "api", - "devshell": "devshell", "nixpkgs": "nixpkgs", "web": "web" } @@ -159,9 +178,7 @@ }, "web": { "inputs": { - "devshell": [ - "devshell" - ], + "devshell": "devshell_2", "flake-utils": "flake-utils_2", "nixpkgs": [ "nixpkgs" diff --git a/flake.nix b/flake.nix index 0b59793..5925ab3 100644 --- a/flake.nix +++ b/flake.nix @@ -3,52 +3,28 @@ inputs = { api = { url = "github:accentor/api/v0.24.0"; - inputs = { - devshell.follows = "devshell"; - nixpkgs.follows = "nixpkgs"; - }; + inputs.nixpkgs.follows = "nixpkgs"; }; web = { url = "github:accentor/web/v0.35.0"; - inputs = { - devshell.follows = "devshell"; - nixpkgs.follows = "nixpkgs"; - }; - }; - devshell = { - url = "github:numtide/devshell"; inputs.nixpkgs.follows = "nixpkgs"; }; nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.zst"; }; - outputs = inputs: - { - packages = builtins.mapAttrs - (system: pkgs: { - accentor-api = inputs.api.packages.${system}.default; - accentor-web = inputs.web.packages.${system}.default; - }) - inputs.nixpkgs.legacyPackages; - devShells = builtins.mapAttrs - (system: pkgs': - let - pkgs = pkgs'.extend inputs.devshell.overlays.default; - in - { - flake = pkgs.devshell.mkShell { - name = "Accentor flake"; - packages = [ pkgs.nixpkgs-fmt ]; - }; - default = inputs.self.devShells.${system}.flake; - }) - inputs.nixpkgs.legacyPackages; - nixosModules = { - accentor = import ./default.nix; - default = inputs.self.nixosModules.accentor; - }; - overlays.default = (self: super: { + outputs = inputs: { + packages = builtins.mapAttrs (system: pkgs: { + accentor-api = inputs.api.packages.${system}.default; + accentor-web = inputs.web.packages.${system}.default; + }) inputs.nixpkgs.legacyPackages; + nixosModules = { + accentor = import ./default.nix; + default = inputs.self.nixosModules.accentor; + }; + overlays.default = ( + self: super: { accentor-api = inputs.api.packages.${self.stdenv.hostPlatform.system}.default; accentor-web = inputs.web.packages.${self.stdenv.hostPlatform.system}.default; - }); - }; + } + ); + }; }