]> Git — Sourcephile - sourcephile-nix.git/blob - .envrc
nginx: remove deprecated enableSSL
[sourcephile-nix.git] / .envrc
1 # manual config
2 nix_version=2.3.2
3 nix_openpgp=B541D55301270E0BCF15CA5D8170B4726D7198DE
4 nixpkgs_channel=nixos-unstable-small
5 nixshell_sources=(.envrc shell.nix $(test ! -d shell || find shell -type f -not -name "*~" | sort))
6
7 # nix
8 if ! has nix || test "$(nix --version)" != "nix (Nix) $nix_version"
9 then log_status "installing Nix core tools"
10 gpg2 --keyserver hkp://wwwkeys.de.pgp.net:80 --recv-keys "$nix_openpgp"
11 if test ! -e .config/nix/install -o ! -e .config/nix/install.asc
12 then
13 mkdir -p .config/nix
14 (cd .config/nix; curl -OO https://nixos.org/releases/nix/nix-"$nix_version"/{install,install.asc})
15 fi
16 test -e ~/.nix-profile/etc/profile.d/nix.sh || {
17 gpg --verify .config/nix/install.asc &&
18 sh .config/nix/install || {
19 log_error "cannot install nix-$nix_version"
20 return 1
21 }
22 }
23 . ~/.nix-profile/etc/profile.d/nix.sh
24 fi
25
26 # nixpkgs
27 if test ! -e .config/nixpkgs-channel/$nixpkgs_channel.nix
28 then log_status "installing nixpkgs from $nixpkgs_channel (This may take some time. To update: delete .config/nixpkgs-channel/$nixpkgs_channel.nix)"
29 rev=$(curl -L https://nixos.org/channels/"$nixpkgs_channel"/git-revision | head -n1 | tr -dC 'a-z0-9')
30 sha256=$(nix-prefetch-url --unpack https://github.com/NixOS/nixpkgs-channels/archive/"$rev".tar.gz)
31 mkdir -p .config/nixpkgs-channel
32 echo >.config/nixpkgs-channel/$nixpkgs_channel.nix "builtins.fetchTarball {url=\"https://github.com/NixOS/nixpkgs-channels/archive/$rev.tar.gz\"; sha256=\"$sha256\";}"
33 else log_status "using nixpkgs from .config/nixpkgs-channel/$nixpkgs_channel.nix"
34 fi
35 watch_file .config/nixpkgs-channel/$nixpkgs_channel.nix
36 # Used in shell.nix
37 export nixpkgs_channel
38 # Get the store path of this nixpkgs,
39 # it will not be registered as a root for the garbage-collector
40 # but will be preserved as long as it is used by shell.nix
41 # which itself will produce a registered derivation.
42 #nixpkgs=$(nix-instantiate --eval .config/nixpkgs-channel/$nixpkgs_channel.nix)
43 #nixpkgs=${nixpkgs#'"'}
44 #nixpkgs=${nixpkgs%'"'}
45 #export NIX_PATH="nixpkgs=$nixpkgs${NIX_PATH:+:$NIX_PATH}"
46
47 # nix-shell
48 has shasum || { log_error "shasum is needed to cache environment"; return 1; }
49 for e in "${nixshell_sources[@]}"
50 do watch_file "$e"; done
51 hash=$(shasum -a 256 "${nixshell_sources[@]}" | shasum -a 256 | cut -c -64)
52 if test -e ".cache/nix-shell/$hash/dump"
53 then
54 log_status "reusing .cache/nix-shell/$hash/"
55 # Load the cached environment
56 direnv_load cat .cache/nix-shell/"$hash"/dump
57 # Re-run the shellHook to update envvars like GPG_TTY,
58 # and run gpg-connect-agent updatestartuptty /bye
59 eval "$shellHook"
60 else log_status "building .cache/nix-shell/$hash/"
61 mkdir -p ".cache/nix-shell/$hash"
62 local dump="$(mktemp .cache/nix-shell/$hash/dump-XXXXXXXX)"
63 # Register the derivation as a root for the garbage-collector,
64 # then cache a dump of the environment from within the nix-shell,
65 # then unregister previous derivations,
66 # then load the cached environment.
67 nix-instantiate >/dev/null ./shell.nix \
68 --indirect --add-root .cache/nix-shell/"$hash"/shell.drv \
69 ${TRACE:+--show-trace} \
70 ${OFFLINE:+--option substituters ""} &&
71 nix-store >/dev/null \
72 --indirect --add-root .cache/nix-shell/"$hash"/shell.dep \
73 ${OFFLINE:+--option substituters ""} \
74 --realise $(nix-store --query --references .cache/nix-shell/"$hash"/shell.drv) &&
75 nix-shell >"$dump" ${TRACE:+--show-trace} --pure \
76 --run "$(join_args "$direnv" dump)" \
77 ${OFFLINE:+--option substituters ""} &&
78 mv -f "$dump" .cache/nix-shell/"$hash"/dump &&
79 find .cache/nix-shell -mindepth 1 -maxdepth 1 -not -name "$hash" -exec rm -rf {} + &&
80 direnv_load cat .cache/nix-shell/"$hash"/dump || {
81 rm -rf "$PWD/.cache/nix-shell/$hash"
82 log_error "cannot build shell.nix"
83 return 1
84 }
85 fi