shell: fix nixos-enter
[sourcephile-nix.git] / .envrc
diff --git a/.envrc b/.envrc
index 20c104de98ffc55540fe010e78db1c1f1ff50ff1..3550a30f2de389e537ee40ca5e64a77dc185c79b 100644 (file)
--- a/.envrc
+++ b/.envrc
@@ -1,84 +1 @@
-# manual config
-nix_version=2.3.2
-nix_openpgp=B541D55301270E0BCF15CA5D8170B4726D7198DE
-nixpkgs_channel=nixos-unstable-small
-nixshell_sources=(.envrc shell.nix $(test ! -d shell || find shell -type f -not -name "*~" | sort))
-
-# nix
-if ! has nix || test "$(nix --version)" != "nix (Nix) $nix_version"
-then log_status "installing Nix core tools"
-  gpg2 --keyserver hkp://wwwkeys.de.pgp.net:80 --recv-keys "$nix_openpgp"
-  if test ! -e .config/nix/install -o ! -e .config/nix/install.asc
-  then
-    mkdir -p .config/nix
-    (cd .config/nix; curl -OO https://nixos.org/releases/nix/nix-"$nix_version"/{install,install.asc})
-  fi
-  test -e ~/.nix-profile/etc/profile.d/nix.sh || {
-    gpg --verify .config/nix/install.asc &&
-    sh .config/nix/install || {
-      log_error "cannot install nix-$nix_version"
-      return 1
-    }
-  }
-  . ~/.nix-profile/etc/profile.d/nix.sh
-fi
-
-# nixpkgs
-if test ! -e .config/nixpkgs-channel/$nixpkgs_channel.nix
-then log_status "installing nixpkgs from $nixpkgs_channel (This may take some time. To update: delete .config/nixpkgs-channel/$nixpkgs_channel.nix)"
-  rev=$(curl -L https://nixos.org/channels/"$nixpkgs_channel"/git-revision | head -n1 | tr -dC 'a-z0-9')
-  sha256=$(nix-prefetch-url --unpack https://github.com/NixOS/nixpkgs-channels/archive/"$rev".tar.gz)
-  mkdir -p .config/nixpkgs-channel
-  echo >.config/nixpkgs-channel/$nixpkgs_channel.nix "builtins.fetchTarball {url=\"https://github.com/NixOS/nixpkgs-channels/archive/$rev.tar.gz\"; sha256=\"$sha256\";}"
-else log_status "using nixpkgs from .config/nixpkgs-channel/$nixpkgs_channel.nix"
-fi
-watch_file .config/nixpkgs-channel/$nixpkgs_channel.nix
-# Used in shell.nix
-export nixpkgs_channel
-# Get the store path of this nixpkgs,
-# it will not be registered as a root for the garbage-collector
-# but will be preserved as long as it is used by shell.nix
-# which itself will produce a registered derivation.
-#nixpkgs=$(nix-instantiate --eval .config/nixpkgs-channel/$nixpkgs_channel.nix)
-#nixpkgs=${nixpkgs#'"'}
-#nixpkgs=${nixpkgs%'"'}
-#export NIX_PATH="nixpkgs=$nixpkgs${NIX_PATH:+:$NIX_PATH}"
-
-# nix-shell
-has shasum || { log_error "shasum is needed to cache environment"; return 1; }
-for e in "${nixshell_sources[@]}"
-do watch_file "$e"; done
-hash=$(shasum -a 256 "${nixshell_sources[@]}" | shasum -a 256 | cut -c -64)
-if test -e ".cache/nix-shell/$hash/dump"
-then
-  log_status "reusing .cache/nix-shell/$hash/"
-  # Load the cached environment
-  direnv_load sh -c "cat >\$DIRENV_DUMP_FILE_PATH .cache/nix-shell/"$hash"/dump"
-  # Re-run the shellHook to update envvars like GPG_TTY,
-  # and run gpg-connect-agent updatestartuptty /bye
-  eval "$shellHook"
-else log_status "building .cache/nix-shell/$hash/"
-  mkdir -p ".cache/nix-shell/$hash"
-  local dump="$(mktemp .cache/nix-shell/$hash/dump-XXXXXXXX)"
-  # Register the derivation as a root for the garbage-collector,
-  # then cache a dump of the environment from within the nix-shell,
-  # then unregister previous derivations,
-  # then load the cached environment.
-  nix-instantiate >/dev/null ./shell.nix \
-   --indirect --add-root .cache/nix-shell/"$hash"/shell.drv \
-   ${TRACE:+--show-trace} \
-   ${OFFLINE:+--option substituters ""} &&
-  nix-store >/dev/null \
-   --indirect --add-root .cache/nix-shell/"$hash"/shell.dep \
-   ${OFFLINE:+--option substituters ""} \
-   --realise $(nix-store --query --references .cache/nix-shell/"$hash"/shell.drv) &&
-  direnv_load sh -c "nix-shell ${TRACE:+--show-trace} --pure \
-   --run \"DIRENV_DUMP_FILE_PATH=$dump $direnv dump; cat $dump >\$DIRENV_DUMP_FILE_PATH\" \
-   ${OFFLINE:+--option substituters ""}" &&
-  mv -f "$dump" .cache/nix-shell/"$hash"/dump &&
-  find .cache/nix-shell -mindepth 1 -maxdepth 1 -not -name "$hash" -exec rm -rf {} + || {
-    rm -rf "$PWD/.cache/nix-shell/$hash"
-    log_error "cannot build shell.nix"
-    return 1
-  }
-fi
+use flake