From 1bed4d5d9f494d3f8e7a1a9a855f5247bb290b51 Mon Sep 17 00:00:00 2001 From: Nickolaj Jepsen Date: Sat, 23 Aug 2025 18:42:54 +0200 Subject: [PATCH] refactor(niri): base niri.outputs on config.monitors --- flake.nix | 5 +-- hosts/desktop/monitors.nix | 34 +++++++++++++---- hosts/desktop/niri.nix | 37 ------------------ hosts/work/monitors.nix | 30 ++++++++++++--- hosts/work/niri.nix | 23 ----------- legacy_modules/desktop/hyprland/default.nix | 7 +--- legacy_modules/desktop/niri.nix | 38 +++++++++++++++---- legacy_modules/desktop/screenshot.nix | 11 ++++-- legacy_modules/hardware/monitors.nix | 25 ++++++++---- modules/programs/llm.nix | 42 ++++++++++++--------- 10 files changed, 133 insertions(+), 119 deletions(-) delete mode 100644 hosts/desktop/niri.nix delete mode 100644 hosts/work/niri.nix diff --git a/flake.nix b/flake.nix index 431adcc..2cdd2f7 100644 --- a/flake.nix +++ b/flake.nix @@ -1,10 +1,7 @@ { description = "NixOS configuration"; - outputs = { - flake-parts, - ... - } @ inputs: + outputs = {flake-parts, ...} @ inputs: flake-parts.lib.mkFlake {inherit inputs;} { imports = [ inputs.agenix-rekey.flakeModule diff --git a/hosts/desktop/monitors.nix b/hosts/desktop/monitors.nix index de61a4d..739df91 100644 --- a/hosts/desktop/monitors.nix +++ b/hosts/desktop/monitors.nix @@ -1,22 +1,40 @@ _: { monitors = [ { - name = "DP-3"; - resolution = "2560x1440"; + name = "DP-1"; + resolution = { + width = 2560; + height = 1440; + }; refreshRate = 144; - position = "1920x0"; + position = { + x = 1920; + y = 0; + }; } { - name = "DP-1"; - resolution = "2560x1440"; + name = "DP-3"; + resolution = { + width = 2560; + height = 1440; + }; refreshRate = 144; - position = "4480x0"; + position = { + x = 4480; + y = 0; + }; } { name = "HDMI-A-1"; - resolution = "1920x1080"; + resolution = { + width = 1920; + height = 1080; + }; refreshRate = 60; - position = "0x0"; + position = { + x = 0; + y = 0; + }; } ]; } diff --git a/hosts/desktop/niri.nix b/hosts/desktop/niri.nix deleted file mode 100644 index c0449df..0000000 --- a/hosts/desktop/niri.nix +++ /dev/null @@ -1,37 +0,0 @@ -_: { - fireproof.home-manager.programs.niri.settings.outputs = { - "DP-3" = { - position = { - x = 1920; - y = 0; - }; - mode = { - refresh = 164.998; - width = 2560; - height = 1440; - }; - }; - "DP-1" = { - position = { - x = 4480; - y = 0; - }; - mode = { - refresh = 165.000; - width = 2560; - height = 1440; - }; - }; - "HDMI-A-1" = { - position = { - x = 0; - y = 0; - }; - mode = { - refresh = 60.000; - width = 1920; - height = 1080; - }; - }; - }; -} diff --git a/hosts/work/monitors.nix b/hosts/work/monitors.nix index bf39e26..38fdacd 100644 --- a/hosts/work/monitors.nix +++ b/hosts/work/monitors.nix @@ -2,18 +2,36 @@ _: { monitors = [ { name = "DP-5"; - resolution = "1920x1200"; - position = "1920x0"; + resolution = { + width = 1920; + height = 1200; + }; + position = { + x = 1920; + y = 0; + }; } { name = "HDMI-A-5"; - resolution = "1920x1080"; - position = "0x0"; + resolution = { + width = 1920; + height = 1080; + }; + position = { + x = 0; + y = 0; + }; } { name = "DP-4"; - resolution = "1920x1200"; - position = "3840x0"; + resolution = { + width = 1920; + height = 1200; + }; + position = { + x = 3840; + y = 0; + }; transform = 1; } ]; diff --git a/hosts/work/niri.nix b/hosts/work/niri.nix deleted file mode 100644 index 1503ac3..0000000 --- a/hosts/work/niri.nix +++ /dev/null @@ -1,23 +0,0 @@ -_: { - fireproof.home-manager.programs.niri.settings.outputs = { - "DP-5" = { - position = { - x = 1920; - y = 0; - }; - }; - "HDMI-A-5" = { - position = { - x = 0; - y = 0; - }; - }; - "DP-4" = { - position = { - x = 3840; - y = 0; - }; - transform.rotation = 90; - }; - }; -} diff --git a/legacy_modules/desktop/hyprland/default.nix b/legacy_modules/desktop/hyprland/default.nix index 608f80c..7fba8f7 100644 --- a/legacy_modules/desktop/hyprland/default.nix +++ b/legacy_modules/desktop/hyprland/default.nix @@ -101,16 +101,13 @@ in { else ""; resolution = if m.resolution != null - then m.resolution + then "${builtins.toString m.resolution.width}x${builtins.toString m.resolution.height}" else "preferred"; refreshRate = if m.refreshRate != null then "@${builtins.toString m.refreshRate}" else ""; - position = - if m.position != null - then m.position - else "auto"; + position = "${builtins.toString m.position.x}x${builtins.toString m.position.y}"; transform = if m.transform != null then ", transform, ${builtins.toString m.transform}" diff --git a/legacy_modules/desktop/niri.nix b/legacy_modules/desktop/niri.nix index 8a03a8b..ec765f0 100644 --- a/legacy_modules/desktop/niri.nix +++ b/legacy_modules/desktop/niri.nix @@ -1,8 +1,12 @@ { pkgs, inputs, + config, + lib, ... -}: { +}: let + primaryMonitorName = (builtins.head config.monitors).name or ""; +in { # TODO: Move these to a separate module fireproof.home-manager.programs.waybar = { enable = true; @@ -145,21 +149,21 @@ } ]; - workspaces = { + workspaces = lib.mkIf (primaryMonitorName != "") { "01" = { - open-on-output = "DP-5"; + open-on-output = primaryMonitorName; }; "02" = { - open-on-output = "DP-5"; + open-on-output = primaryMonitorName; }; "03" = { - open-on-output = "DP-5"; + open-on-output = primaryMonitorName; }; "04" = { - open-on-output = "DP-5"; + open-on-output = primaryMonitorName; }; "05" = { - open-on-output = "DP-5"; + open-on-output = primaryMonitorName; }; }; @@ -280,5 +284,25 @@ "Mod+Space".action.spawn = ["fuzzel"]; "Mod+Backspace".action.close-window = {}; }; + + outputs = lib.mkIf (config.monitors != []) ( + lib.listToAttrs (map (monitor: let + refreshRateFloat = lib.mkIf (monitor.refreshRate != null) (builtins.fromJSON "${builtins.toString monitor.refreshRate}.0"); + in { + inherit (monitor) name; + value = { + inherit (monitor) position; + mode = { + inherit (monitor.resolution) width height; + refresh = refreshRateFloat; + }; + transform.rotation = + if (monitor.transform != null) + then monitor.transform * 90 + else 0; + }; + }) + config.monitors) + ); }; } diff --git a/legacy_modules/desktop/screenshot.nix b/legacy_modules/desktop/screenshot.nix index b4f9cbf..e5ce3ab 100644 --- a/legacy_modules/desktop/screenshot.nix +++ b/legacy_modules/desktop/screenshot.nix @@ -1,11 +1,14 @@ -{pkgs, lib, ...}: let +{ + pkgs, + lib, + ... +}: let screenshotPkg = pkgs.writeShellScriptBin "screenshot" '' AREA=$(${lib.getExe pkgs.slurp} -d) ${lib.getExe pkgs.grim} -t ppm -g "$AREA" - | ${lib.getExe pkgs.satty} -f - --initial-tool=arrow --copy-command=${pkgs.wl-clipboard}/bin/wl-copy --action-on-enter="save-to-clipboard" --disable-notifications ''; - -in { +in { environment.systemPackages = [ screenshotPkg ]; -} \ No newline at end of file +} diff --git a/legacy_modules/hardware/monitors.nix b/legacy_modules/hardware/monitors.nix index cd63ece..7c1c8ca 100644 --- a/legacy_modules/hardware/monitors.nix +++ b/legacy_modules/hardware/monitors.nix @@ -1,5 +1,9 @@ # https://github.com/ChangeCaps/nixos-config/tree/0cec356abc0e46ca6ba27b3cf01cd51273bd4a69 -{lib, ...}: { +{ + lib, + config, + ... +}: { options.monitors = lib.mkOption { type = lib.types.listOf (lib.types.submodule { options = { @@ -9,10 +13,13 @@ example = "DP-1"; }; - resolution = lib.mkOption { - type = lib.types.nullOr lib.types.str; + resolution.width = lib.mkOption { + type = lib.types.nullOr lib.types.int; + default = null; + }; + resolution.height = lib.mkOption { + type = lib.types.nullOr lib.types.int; default = null; - example = "1920x1080"; }; refreshRate = lib.mkOption { @@ -21,9 +28,13 @@ example = 60; }; - position = lib.mkOption { - type = lib.types.str; - default = "0x0"; + position.x = lib.mkOption { + type = lib.types.int; + default = 0; + }; + position.y = lib.mkOption { + type = lib.types.int; + default = 0; }; scale = lib.mkOption { diff --git a/modules/programs/llm.nix b/modules/programs/llm.nix index 87d0c8d..5628315 100644 --- a/modules/programs/llm.nix +++ b/modules/programs/llm.nix @@ -1,26 +1,32 @@ -{pkgs, config, username, pkgsUnstable, ...}: let - llmConfig = if pkgs.stdenv.isDarwin then - "Library/Application Support/io.datasette.llm" - else - ".config/io.datasette.llm"; - pythonEnv = pkgsUnstable.python3.withPackages (pp: with pp; [ - llm - llm-anthropic - llm-gemini - llm-tools-sqlite - llm-fragments-github - llm-cmd - llm-jq - llm-github-copilot - llm-git - ]); +{ + pkgs, + config, + username, + pkgsUnstable, + ... +}: let + llmConfig = + if pkgs.stdenv.isDarwin + then "Library/Application Support/io.datasette.llm" + else ".config/io.datasette.llm"; + pythonEnv = pkgsUnstable.python3.withPackages (pp: + with pp; [ + llm + llm-anthropic + llm-gemini + llm-tools-sqlite + llm-fragments-github + llm-cmd + llm-jq + llm-github-copilot + llm-git + ]); llmPkgWithPlugins = pkgs.writeShellScriptBin "llm" '' unset PYTHONPATH # Otherwise it breaks in Python devenvs export $(grep -v '^#' ${config.age.secrets.llm-api-key.path} | xargs) exec ${pythonEnv}/bin/llm "''${@}" ''; -in - { +in { age.secrets.llm-api-key = { rekeyFile = ../../secrets/llm-api-key.env.age; mode = "0600";