From add18037afad4ba47a1d00dd72eccbcb37947721 Mon Sep 17 00:00:00 2001 From: Arthur Noel Date: Thu, 14 Dec 2023 02:01:10 +0000 Subject: [PATCH 1/2] make self-contained using resholve --- default.nix | 48 +++++++++++++++++++++++++++++++-------- direnvrc | 4 ---- scripts/create-release.sh | 1 + 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/default.nix b/default.nix index 407b5ad..b72343d 100644 --- a/default.nix +++ b/default.nix @@ -1,18 +1,48 @@ -{ stdenv, nix, lib }: +{ resholve, lib, coreutils, direnv, nix }: -stdenv.mkDerivation { - name = "nix-direnv"; +# resholve does not yet support `finalAttrs` call pattern hence `rec` +# https://github.com/abathur/resholve/issues/107 +resholve.mkDerivation rec { + pname = "nix-direnv"; + version = "3.0.0"; - src = ./.; - - postPatch = '' - sed -i "2iNIX_BIN_PREFIX=${nix}/bin" direnvrc - ''; + src = builtins.path { + path = ./.; + name = pname; + }; installPhase = '' - install -m400 -D direnvrc $out/share/nix-direnv/direnvrc + install -m400 -D direnvrc $out/share/${pname}/direnvrc ''; + solutions = { + default = { + scripts = [ "share/${pname}/direnvrc" ]; + interpreter = "none"; + inputs = [ coreutils direnv nix ]; + fake = { + builtin = [ + "PATH_add" + "direnv_layout_dir" + "has" + "log_error" + "log_status" + "watch_file" + ]; + function = [ + # not really a function - this is in an else branch for macOS/homebrew that + # cannot be reached when built with nix + "shasum" + ]; + }; + keep."$cmd" = true; + execer = [ + "cannot:${direnv}/bin/direnv" + "cannot:${nix}/bin/nix" + ]; + }; + }; + meta = with lib; { description = "A fast, persistent use_nix implementation for direnv"; homepage = "https://github.com/nix-community/nix-direnv"; diff --git a/direnvrc b/direnvrc index f0c0650..dd05926 100644 --- a/direnvrc +++ b/direnvrc @@ -59,10 +59,6 @@ _nix_direnv_preflight() { _nix_direnv_fatal '$direnv environment variable was not defined. Was this script run inside direnv?' fi - if [[ -n ${NIX_BIN_PREFIX:-} ]]; then - PATH_add "$NIX_BIN_PREFIX" - fi - # check command min versions, bash check uses $BASH_VERSION with _require_version # instead of _require_cmd_version because _require_cmd_version uses =~ operator which # would be a syntax error on bash < 3 diff --git a/scripts/create-release.sh b/scripts/create-release.sh index 7269ee0..dfb8f80 100755 --- a/scripts/create-release.sh +++ b/scripts/create-release.sh @@ -16,6 +16,7 @@ if [[ "$(git symbolic-ref --short HEAD)" != "master" ]]; then exit 1 fi +sed -Ei "s!(version = ).*!\1\"$version\";!" default.nix sed -Ei "s!(NIX_DIRENV_VERSION=).*!\1$version!" direnvrc sed -i README.md templates/flake/.envrc \ From c951a47df05073d57d3039599ae9a1bc0ccd9e78 Mon Sep 17 00:00:00 2001 From: Arthur Noel Date: Fri, 15 Dec 2023 13:52:55 +0000 Subject: [PATCH 2/2] drop min version checks for nix build --- default.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/default.nix b/default.nix index b72343d..6c4f7d9 100644 --- a/default.nix +++ b/default.nix @@ -11,6 +11,11 @@ resholve.mkDerivation rec { name = pname; }; + # drop min version checks which are redundant when built with nix + postPatch = '' + sed -i "/_require_version bash/,+2d" direnvrc + ''; + installPhase = '' install -m400 -D direnvrc $out/share/${pname}/direnvrc '';