From 38b7d7e849fe008c566328ff568c7a7aa26c2904 Mon Sep 17 00:00:00 2001 From: Tom Prince <tom.prince@private.storage> Date: Tue, 21 Sep 2021 12:18:50 -0600 Subject: [PATCH] Make `tools/default.nix` more easily extendable. --- tools/default.nix | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/tools/default.nix b/tools/default.nix index 6273dd2b..f9a0b1ff 100644 --- a/tools/default.nix +++ b/tools/default.nix @@ -13,22 +13,37 @@ let echo ${lib.escapeShellArg ./pylib} > $out/${lib.escapeShellArg python.sitePackages}/tools.pth ''; }; + python-commands = [ + ./update-nixpkgs + ]; in -# This derivation creates a package that wraps our tools to setup an environment -# with there dependencies available. + # This derivation creates a package that wraps our tools to setup an environment + # with there dependencies available. pkgs.runCommand "ps_tools" { nativeBuildInputs = [ makeWrapper ]; shellHook = '' + # Only display the help if we are running an interactive shell. if [[ $- == *i* ]]; then cat <<MOTD Tools (pass --help for details): - - update-nixpkgs + ${lib.concatStringsSep "\n" (map (path: + "- ${baseNameOf path}" + ) python-commands)} MOTD fi ''; -} '' - mkdir -p $out/bin - # makeWrapper <executable> <wrapperfile> <args> - # See https://nixos.org/manual/nixpkgs/stable/#fun-makeWrapper - makeWrapper ${python-env}/bin/python $out/bin/update-nixpkgs --add-flags ${toString ./update-nixpkgs} -'' + } '' + mkdir -p $out/bin + ${lib.concatStringsSep "\n" (map (path: + let + baseName = baseNameOf path; + # We use toString so that we wrap the in-tree scripts, rather than copying + # them to the nix-store. This means that we don't need to run nix-shell again + # to pick up changes. + sourcePath = toString path; + in + # makeWrapper <executable> <wrapperfile> <args> + # See https://nixos.org/manual/nixpkgs/stable/#fun-makeWrapper + "makeWrapper ${python-env}/bin/python $out/bin/${baseName} --add-flags ${sourcePath}" + ) python-commands)} + '' -- GitLab