diff options
Diffstat (limited to 'nix/lazy-deps/default.nix')
-rw-r--r-- | nix/lazy-deps/default.nix | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/nix/lazy-deps/default.nix b/nix/lazy-deps/default.nix index 3cce48d8a5..fbdb30b38e 100644 --- a/nix/lazy-deps/default.nix +++ b/nix/lazy-deps/default.nix @@ -9,11 +9,11 @@ # evaluation, and expects both `git` and `nix-build` to exist in the # user's $PATH. If required, this can be done in the shell # configuration invoking this function. -{ pkgs, ... }: +{ pkgs, lib, ... }: let inherit (builtins) attrNames attrValues mapAttrs; - inherit (pkgs.lib) concatStringsSep; + inherit (lib) fix concatStringsSep; # Create the case statement for a command invocations, optionally # overriding the `TARGET_TOOL` variable. @@ -28,20 +28,21 @@ let invocations = tools: concatStringsSep "\n" (attrValues (mapAttrs invoke tools)); in +fix (self: # Attribute set of tools that should be lazily-added to the $PATH. - - # The name of each attribute is used as the command name (on $PATH). - # It must contain the keys 'attr' (containing the Nix attribute path - # to the tool's derivation from the top-level), and may optionally - # contain the key 'cmd' to override the name of the binary inside the - # derivation. +# +# The name of each attribute is used as the command name (on $PATH). +# It must contain the keys 'attr' (containing the Nix attribute path +# to the tool's derivation from the top-level), and may optionally +# contain the key 'cmd' to override the name of the binary inside the +# derivation. tools: -pkgs.writeTextFile { - name = "lazy-dispatch"; - executable = true; - destination = "/bin/__dispatch"; +pkgs.runCommandNoCC "lazy-dispatch" +{ + passthru.overrideDeps = newTools: self (tools // newTools); + passthru.tools = tools; text = '' #!${pkgs.runtimeShell} @@ -68,8 +69,23 @@ pkgs.writeTextFile { exec "''${TARGET_TOOL}" "''${@}" ''; - checkPhase = '' - ${pkgs.stdenv.shellDryRun} "$target" - ${concatStringsSep "\n" (map link (attrNames tools))} - ''; + # Access this to get a compatible nix-shell + passthru.devShell = pkgs.mkShellNoCC { + name = "${self.name}-shell"; + packages = [ self ]; + }; } + '' + # Write the dispatch code + target=$out/bin/__dispatch + mkdir -p "$(dirname "$target")" + echo "$text" > $target + chmod +x $target + + # Add symlinks from all the tools to the dispatch + ${concatStringsSep "\n" (map link (attrNames tools))} + + # Check that it's working-ish + ${pkgs.stdenv.shellDryRun} $target + '' +) |