From 031f47f5600756c1574ee94cfba39b92efe5abd2 Mon Sep 17 00:00:00 2001 From: atagen Date: Sun, 24 May 2026 19:08:15 +1000 Subject: [PATCH] nix: fmt + remove pkgs.system ref --- flake.nix | 163 +++++++++++++++++++++++++------------------ nix/nixos-module.nix | 17 ++++- 2 files changed, 109 insertions(+), 71 deletions(-) diff --git a/flake.nix b/flake.nix index eaa7f82..8f6f430 100644 --- a/flake.nix +++ b/flake.nix @@ -9,17 +9,28 @@ }; }; - outputs = { self, nixpkgs, rust-overlay }: + outputs = + { + self, + nixpkgs, + rust-overlay, + }: let - systems = [ "x86_64-linux" "aarch64-linux" ]; + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; forAllSystems = nixpkgs.lib.genAttrs systems; - pkgsFor = system: import nixpkgs { - inherit system; - overlays = [ rust-overlay.overlays.default ]; - }; + pkgsFor = + system: + import nixpkgs { + inherit system; + overlays = [ rust-overlay.overlays.default ]; + }; - perSystem = system: + perSystem = + system: let pkgs = pkgsFor system; @@ -48,76 +59,87 @@ in { # `nix develop` — full dev environment. - devShell = pkgs.mkShell ({ - name = "headroom-dev"; + devShell = pkgs.mkShell ( + { + name = "headroom-dev"; - nativeBuildInputs = nativeBuildTools ++ [ - rustToolchain - pkgs.rust-analyzer - ]; + nativeBuildInputs = nativeBuildTools ++ [ + rustToolchain + pkgs.rust-analyzer + ]; - buildInputs = nativeAudioBuildInputs ++ (with pkgs; [ - socat # poke the IPC socket - jq # pretty-print JSON - pipewire # for pw-cli, pw-cat, etc. - wireplumber - ]); + buildInputs = + nativeAudioBuildInputs + ++ (with pkgs; [ + socat # poke the IPC socket + jq # pretty-print JSON + pipewire # for pw-cli, pw-cat, etc. + wireplumber + ]); - shellHook = '' - echo "headroom dev shell — rustc $(rustc --version | cut -d' ' -f2)" - echo " cargo build / cargo test for iteration." - echo " nix build .#headroom for the packaged binary." - export RUST_BACKTRACE=1 - export RUST_LOG=headroom=debug,info - ''; - } // commonEnv); + shellHook = '' + echo "headroom dev shell — rustc $(rustc --version | cut -d' ' -f2)" + echo " cargo build / cargo test for iteration." + echo " nix build .#headroom for the packaged binary." + export RUST_BACKTRACE=1 + export RUST_LOG=headroom=debug,info + ''; + } + // commonEnv + ); # `nix build` — the final packaged daemon + CLI. - headroom = rustPlatform.buildRustPackage ({ - pname = "headroom"; - # Pull from the workspace Cargo.toml — the per-crate - # manifests use `version.workspace = true` which evaluates - # to a table here, not a string. - version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version; + headroom = rustPlatform.buildRustPackage ( + { + pname = "headroom"; + # Pull from the workspace Cargo.toml — the per-crate + # manifests use `version.workspace = true` which evaluates + # to a table here, not a string. + version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version; - src = ./.; + src = ./.; - cargoLock = { - lockFile = ./Cargo.lock; - # allowBuiltinFetchGit = true; - }; + cargoLock = { + lockFile = ./Cargo.lock; + # allowBuiltinFetchGit = true; + }; - nativeBuildInputs = nativeBuildTools; - buildInputs = nativeAudioBuildInputs; + nativeBuildInputs = nativeBuildTools; + buildInputs = nativeAudioBuildInputs; - # We ship one binary from the workspace: `headroom` (cli + daemon). - cargoBuildFlags = [ "-p" "headroom-cli" ]; - doCheck = true; - cargoTestFlags = [ "--workspace" ]; + # We ship one binary from the workspace: `headroom` (cli + daemon). + cargoBuildFlags = [ + "-p" + "headroom-cli" + ]; + doCheck = true; + cargoTestFlags = [ "--workspace" ]; - # Install the systemd user unit (templated with @bindir@ - # so the unit refers to the absolute path of the binary in - # this derivation, never to whatever happens to be on - # PATH) and ship the canonical profiles under - # share/headroom/profiles so users / modules can copy - # them into XDG_CONFIG_HOME on first run. - postInstall = '' - install -Dm644 contrib/systemd/headroom.service \ - "$out/lib/systemd/user/headroom.service" - substituteInPlace "$out/lib/systemd/user/headroom.service" \ - --replace-fail '@bindir@' "$out/bin" + # Install the systemd user unit (templated with @bindir@ + # so the unit refers to the absolute path of the binary in + # this derivation, never to whatever happens to be on + # PATH) and ship the canonical profiles under + # share/headroom/profiles so users / modules can copy + # them into XDG_CONFIG_HOME on first run. + postInstall = '' + install -Dm644 contrib/systemd/headroom.service \ + "$out/lib/systemd/user/headroom.service" + substituteInPlace "$out/lib/systemd/user/headroom.service" \ + --replace-fail '@bindir@' "$out/bin" - mkdir -p "$out/share/headroom/profiles" - cp -r profiles/. "$out/share/headroom/profiles/" - ''; + mkdir -p "$out/share/headroom/profiles" + cp -r profiles/. "$out/share/headroom/profiles/" + ''; - meta = with pkgs.lib; { - description = "AGC + compressor + true-peak limiter daemon for PipeWire"; - license = licenses.gpl3Plus; - platforms = platforms.linux; - mainProgram = "headroom"; - }; - } // commonEnv); + meta = with pkgs.lib; { + description = "Audio dynamic range daemon for PipeWire"; + license = licenses.gpl3Plus; + platforms = platforms.linux; + mainProgram = "headroom"; + }; + } + // commonEnv + ); }; in { @@ -125,11 +147,16 @@ default = (perSystem system).devShell; }); - packages = forAllSystems (system: - let ps = perSystem system; in rec { + packages = forAllSystems ( + system: + let + ps = perSystem system; + in + rec { default = headroom; headroom = ps.headroom; - }); + } + ); formatter = forAllSystems (system: (pkgsFor system).nixpkgs-fmt); diff --git a/nix/nixos-module.nix b/nix/nixos-module.nix index df06016..a64dad3 100644 --- a/nix/nixos-module.nix +++ b/nix/nixos-module.nix @@ -13,10 +13,21 @@ # RT-priority tuning — use the Home Manager module # (`homeModules.default`) instead. The two compose. self: -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: let - inherit (lib) mkEnableOption mkOption mkIf types literalExpression; + inherit (lib) + mkEnableOption + mkOption + mkIf + types + literalExpression + ; cfg = config.programs.headroom; in @@ -26,7 +37,7 @@ in package = mkOption { type = types.package; - default = self.packages.${pkgs.system}.headroom; + default = self.packages.${pkgs.stdenv.hostPlatform.system}.headroom; defaultText = literalExpression "headroom.packages.\${pkgs.system}.headroom"; description = '' The headroom package to install system-wide.