From 38cdcebddd71831c504f76e9c8951540b8f22872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Jane=C5=BEi=C4=8D?= Date: Fri, 27 Mar 2026 15:05:09 +0100 Subject: [PATCH] feat: dev-registry for dev environments --- features/dev-registry.nix | 16 ++++++ flake.nix | 1 + flake/devshell.nix | 110 ++++++++++++++++++++++++++++++++++---- flake/hosts.nix | 2 + 4 files changed, 119 insertions(+), 10 deletions(-) create mode 100644 features/dev-registry.nix diff --git a/features/dev-registry.nix b/features/dev-registry.nix new file mode 100644 index 0000000..22b06c8 --- /dev/null +++ b/features/dev-registry.nix @@ -0,0 +1,16 @@ +{ + nixos = + { inputs, ... }: + { + nix.registry.dev = { + from = { + type = "indirect"; + id = "dev"; + }; + to = { + type = "path"; + path = inputs.self.outPath; + }; + }; + }; +} diff --git a/flake.nix b/flake.nix index 28489bb..d24df88 100644 --- a/flake.nix +++ b/flake.nix @@ -36,6 +36,7 @@ }; neovim-nightly-overlay.url = "github:nix-community/neovim-nightly-overlay"; + }; outputs = diff --git a/flake/devshell.nix b/flake/devshell.nix index f2f7f69..eda9995 100644 --- a/flake/devshell.nix +++ b/flake/devshell.nix @@ -1,17 +1,107 @@ _: { perSystem = - { pkgs, ... }: + { pkgs, lib, ... }: + let + # libraries needed by python native extensions + pythonLibraries = [ + pkgs.stdenv.cc.cc.lib + pkgs.zlib + pkgs.openssl + pkgs.curl + ]; + + mkUv = python: { + packages = [ + python + pkgs.uv + ]; + libraries = pythonLibraries; + env = { + UV_PYTHON_DOWNLOADS = "never"; + UV_PYTHON_PREFERENCE = "only-system"; + UV_PYTHON = "${python}/bin/python"; + }; + shellHook = '' + unset PYTHONPATH + export UV_PROJECT_ENVIRONMENT="$HOME/.venvs/$(basename "$PWD")-$(echo "$PWD" | md5sum | cut -c1-8)" + ''; + }; + + # composable dev environment components + # each is exposed as its own devShell, layered via `use dev` in .envrc + components = { + uv_10 = mkUv pkgs.python310; + uv_11 = mkUv pkgs.python311; + uv_12 = mkUv pkgs.python312; + uv_13 = mkUv pkgs.python313; + uv_14 = mkUv pkgs.python314; + + pg_15 = { + packages = [ pkgs.postgresql_15 ]; + }; + pg_16 = { + packages = [ pkgs.postgresql_16 ]; + }; + pg_17 = { + packages = [ pkgs.postgresql_17 ]; + }; + pg_18 = { + packages = [ pkgs.postgresql_18 ]; + }; + + rust = { + packages = [ + pkgs.rustc + pkgs.cargo + pkgs.rust-analyzer + pkgs.openssl + pkgs.pkg-config + ]; + }; + + cmake = { + packages = [ + pkgs.cmake + pkgs.ninja + ]; + }; + }; + + mkComponentShell = + component: + let + c = components.${component}; + libraries = c.libraries or [ ]; + libPath = lib.makeLibraryPath libraries; + in + pkgs.mkShell ( + { + packages = c.packages or [ ]; + shellHook = + (lib.optionalString (libraries != [ ]) '' + export LD_LIBRARY_PATH="${libPath}''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" + '') + + (c.shellHook or ""); + } + // lib.optionalAttrs (c ? env) { inherit (c) env; } + ); + + componentShells = lib.mapAttrs (name: _: mkComponentShell name) components; + in { formatter = pkgs.nixfmt-tree; - devShells.default = pkgs.mkShell { - packages = [ - pkgs.pre-commit - pkgs.statix - pkgs.shellcheck - pkgs.shfmt - pkgs.qemu - ]; - }; + devShells = { + default = pkgs.mkShell { + packages = [ + pkgs.pre-commit + pkgs.statix + pkgs.shellcheck + pkgs.shfmt + pkgs.qemu + ]; + }; + } + // componentShells; }; } diff --git a/flake/hosts.nix b/flake/hosts.nix index aec8f7a..1783e2c 100644 --- a/flake/hosts.nix +++ b/flake/hosts.nix @@ -30,6 +30,7 @@ in "yubikey" "calibre" "steam" + "dev-registry" "neovim" "dev" "claude" @@ -56,6 +57,7 @@ in "calibre" "steam" "initrd-ssh" + "dev-registry" "neovim" "dev" "claude"