From 3d140394740f431284b7630b33ca6e59dd74d000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 26 Jul 2023 08:29:34 +0200 Subject: [PATCH] using flakes for devshell without reimporting nixpkgs multiple times --- pkgs/clan-cli/.envrc | 2 +- pkgs/clan-cli/default.nix | 16 +++---- pkgs/clan-cli/flake-module.nix | 2 + pkgs/clan-cli/shell.nix | 81 ++++++++++++++++------------------ 4 files changed, 48 insertions(+), 53 deletions(-) diff --git a/pkgs/clan-cli/.envrc b/pkgs/clan-cli/.envrc index 1d953f4bd..b1cca6359 100644 --- a/pkgs/clan-cli/.envrc +++ b/pkgs/clan-cli/.envrc @@ -1 +1 @@ -use nix +use flake .#clan diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index 916f5b898..0eeb62d43 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -1,11 +1,11 @@ -{ pkgs ? import { } -, lib ? pkgs.lib -, python3 ? pkgs.python3 -, ruff ? pkgs.ruff -, runCommand ? pkgs.runCommand -, installShellFiles ? pkgs.installShellFiles -, zerotierone ? pkgs.zerotierone -, bubblewrap ? pkgs.bubblewrap +{ pkgs +, lib +, python3 +, ruff +, runCommand +, installShellFiles +, zerotierone +, bubblewrap }: let pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml); diff --git a/pkgs/clan-cli/flake-module.nix b/pkgs/clan-cli/flake-module.nix index b8df40737..3af30b89b 100644 --- a/pkgs/clan-cli/flake-module.nix +++ b/pkgs/clan-cli/flake-module.nix @@ -4,9 +4,11 @@ pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml); name = pyproject.project.name; package = pkgs.callPackage ./default.nix { }; + shell = pkgs.callPackage ./shell.nix { }; in { packages.${name} = package; + devShells.${name} = shell; packages.default = package; checks = package.tests; }; diff --git a/pkgs/clan-cli/shell.nix b/pkgs/clan-cli/shell.nix index fa99766fd..99665fb2a 100644 --- a/pkgs/clan-cli/shell.nix +++ b/pkgs/clan-cli/shell.nix @@ -1,13 +1,7 @@ -{ pkgs ? import { } -, -}: +{ pkgs }: let - lib = pkgs.lib; - python3 = pkgs.python3; - package = import ./default.nix { - inherit lib python3; - }; - pythonWithDeps = python3.withPackages ( + package = pkgs.callPackage ./default.nix { }; + pythonWithDeps = pkgs.python3.withPackages ( ps: package.propagatedBuildInputs ++ package.devDependencies @@ -18,39 +12,38 @@ let checkScript = pkgs.writeScriptBin "check" '' nix build -f . tests -L "$@" ''; - devShell = pkgs.mkShell { - packages = [ - pkgs.ruff - pythonWithDeps - ]; - # sets up an editable install and add enty points to $PATH - CLAN_NIXPKGS = pkgs.path; - shellHook = '' - tmp_path=$(realpath ./.pythonenv) - repo_root=$(realpath .) - rm -rf $tmp_path - mkdir -p "$tmp_path/${pythonWithDeps.sitePackages}" - - ${pythonWithDeps.interpreter} -m pip install \ - --quiet \ - --disable-pip-version-check \ - --no-index \ - --no-build-isolation \ - --prefix "$tmp_path" \ - --editable $repo_root - - export PATH="$tmp_path/bin:${checkScript}/bin:$PATH" - export PYTHONPATH="$repo_root:$tmp_path/${pythonWithDeps.sitePackages}" - - export XDG_DATA_DIRS="$tmp_path/share''${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}" - export fish_complete_path="$tmp_path/share/fish/vendor_completions.d''${fish_complete_path:+:$fish_complete_path}" - mkdir -p \ - $tmp_path/share/fish/vendor_completions.d \ - $tmp_path/share/bash-completion/completions \ - $tmp_path/share/zsh/site-functions - register-python-argcomplete --shell fish clan > $tmp_path/share/fish/vendor_completions.d/clan.fish - register-python-argcomplete --shell bash clan > $tmp_path/share/bash-completion/completions/clan - ''; - }; in -devShell +pkgs.mkShell { + packages = [ + pkgs.ruff + pythonWithDeps + ]; + # sets up an editable install and add enty points to $PATH + CLAN_NIXPKGS = pkgs.path; + shellHook = '' + tmp_path=$(realpath ./.pythonenv) + repo_root=$(realpath .) + rm -rf $tmp_path + mkdir -p "$tmp_path/${pythonWithDeps.sitePackages}" + + ${pythonWithDeps.interpreter} -m pip install \ + --quiet \ + --disable-pip-version-check \ + --no-index \ + --no-build-isolation \ + --prefix "$tmp_path" \ + --editable $repo_root + + export PATH="$tmp_path/bin:${checkScript}/bin:$PATH" + export PYTHONPATH="$repo_root:$tmp_path/${pythonWithDeps.sitePackages}" + + export XDG_DATA_DIRS="$tmp_path/share''${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}" + export fish_complete_path="$tmp_path/share/fish/vendor_completions.d''${fish_complete_path:+:$fish_complete_path}" + mkdir -p \ + $tmp_path/share/fish/vendor_completions.d \ + $tmp_path/share/bash-completion/completions \ + $tmp_path/share/zsh/site-functions + register-python-argcomplete --shell fish clan > $tmp_path/share/fish/vendor_completions.d/clan.fish + register-python-argcomplete --shell bash clan > $tmp_path/share/bash-completion/completions/clan + ''; +}