]> Git — Sourcephile - sourcephile-nix.git/blob - shell.nix
nix: revamp the hierarchy (again)
[sourcephile-nix.git] / shell.nix
1 let
2 nixpkgs = import .lib/nix/nixpkgs.nix;
3 pkgs = import nixpkgs {
4 config = {}; # Make the config pure, ignoring user's config.
5 overlays = import ./overlays.nix;
6 };
7 # Using modules enables to separate specific configurations in shell/configuration.nix
8 # from reusable code in shell/modules.nix
9 # which may find its way in another git repository one day.
10 modules =
11 (import shell/modules.nix {
12 inherit pkgs;
13 inherit (pkgs) lib;
14 modules = [ ( import shell/configuration.nix ) ];
15 }).config;
16 /*
17 sourcephile-nix-build =
18 pkgs.stdenv.mkDerivation {
19 name = "sourcephile-nix-build";
20 preferLocalBuild = true;
21 allowSubstitutes = false;
22 inherit (pkgs) coreutils;
23 builder = pkgs.writeText "builder.sh" modules.init.builder;
24 };
25 */
26 sourcephile-nix-build =
27 pkgs.buildEnv {
28 name = "sourcephile-nix-build";
29 pathsToLink = [ "/bin" ];
30 paths = with modules; [
31 gnupg.init
32 #gnupg.gpg-fingerprint
33 #nix-plugins.nix-with-extra-builtins
34 ];
35 };
36 nixos = pkgs.nixos {};
37 nixos-generate-config = nixos.nixos-generate-config;
38 nixos-install = nixos.nixos-install;
39 nixos-enter = nixos.nixos-enter;
40 in
41 pkgs.stdenv.mkDerivation {
42 name = "sourcephile-nix";
43 src = null;
44 #preferLocalBuild = true;
45 #allowSubstitutes = false;
46 buildInputs = [
47 sourcephile-nix-build
48 nixpkgs
49 nixos-generate-config
50 nixos-install
51 nixos-enter
52 #pkgs.binutils
53 pkgs.coreutils
54 pkgs.cryptsetup
55 pkgs.curl
56 #pkgs.direnv
57 #pkgs.dnsutils
58 #pkgs.dropbear
59 pkgs.e2fsprogs
60 pkgs.git
61 pkgs.glibcLocales
62 pkgs.gnumake
63 pkgs.gnupg
64 pkgs.htop
65 #pkgs.inetutils
66 pkgs.less
67 pkgs.libfaketime
68 #pkgs.mailutils
69 pkgs.man
70 pkgs.mdadm
71 pkgs.gptfdisk
72 pkgs.ncdu
73 pkgs.ncurses
74 pkgs.nixops
75 #pkgs.openssl
76 pkgs.pass
77 pkgs.procps
78 #pkgs.rxvt_unicode.terminfo
79 #pkgs.sqlite
80 pkgs.sqlite
81 pkgs.sudo
82 pkgs.tig
83 pkgs.time
84 #pkgs.tmux
85 pkgs.tree
86 pkgs.utillinux
87 pkgs.vim
88 #pkgs.virtualbox
89 pkgs.which
90 pkgs.xdg_utils
91 pkgs.zfs
92 pkgs.fio
93 pkgs.strace
94 #pkgs.zfstools
95 ];
96 #enableParallelBuilding = true;
97 shellHook = ''
98 echo >&2 "nix: running shellHook"
99
100 # nix
101 export NIX_PATH="nixpkgs=${nixpkgs}:nixpkgs-sourcephile=$PWD/.lib/nixpkgs-sourcephile"
102 NIX_PATH+=":nixpkgs-overlays="$PWD"/overlays"
103 #NIX_PATH+=""
104
105 # executables
106 PATH_NIX=$(dirname $(readlink -e ~/.nix-profile/bin/nix))
107 PATH_NIXOS=/run/wrappers/bin
108 PATH_FHS="$PWD"/.lib/nix/fhs-bin
109 PATH_FHS_VBOX="$PWD"/.lib/fhs-vbox-bin
110 export PATH="$PATH_NIXOS:$PATH_FHS_VBOX:$PATH_FHS:$PATH:$PATH_NIX"
111 ln -sfn ${sourcephile-nix-build}/bin "$PWD"/.bin
112
113 # nix.conf
114 export NIX_CONF_DIR="$PWD"/.config/nix
115 install -D /dev/stdin "$PWD"/.config/nix/nix.conf <<-EOF
116 auto-optimise-store = true
117 plugin-files = ${pkgs.nix-plugins}/lib/nix/plugins/libnix-extra-builtins.so
118 extra-builtins-file = ${modules.nix-plugins.extra-builtins}
119 EOF
120
121 # NOTE: sudo needs to be own by root with the setuid bit,
122 # but this won't be the case for the sudo provided by Nix outside NixOS,
123 # hence the addition of $PATH_FHS in shellHook
124 # to provide the host system's sudo.
125 # WARNING: beware that sudo may reset the environment,
126 # and especially PATH, to some system's default.
127
128 # locales
129 export LANG=fr_FR.UTF-8
130 export LC_CTYPE=fr_FR.UTF-8
131
132 # gnupg
133 export GNUPGHOME="$PWD"/../sec/gnupg
134 install -dm700 "$GNUPGHOME"
135 export GPG_TTY=$(tty)
136 gpgconf --launch gpg-agent
137 export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
138
139 # password-store
140 export PASSWORD_STORE_DIR="$PWD"/../sec/pass
141
142 # openssl
143 export NIX_SSL_CERT_FILE="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
144 export SSL_CERT_FILE="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
145
146 # git
147 gitdir="$PWD"/.git
148 test ! -f "$gitdir" || while IFS=" :" read -r hdr gitdir; do [ "$hdr" != gitdir ] || break; done <"$gitdir"
149 ln -fnsr \
150 "$PWD"/.lib/git/hooks/prepare-commit-msg--longuest-common-prefix \
151 "$gitdir"/hooks/prepare-commit-msg
152
153 # nixops
154 #export NIXOPS_DEPLOYMENT="staging"
155 export NIXOPS_STATE="$PWD"/.sec/nixops/state.nixops
156 # Extend the Nix interpreter
157 # to enable builtins.extraBuiltins,
158 # which provides an unsafe exec useful to get secrets
159 # from the local password-store.
160 NIXOPS_OPTS+=" --show-trace"
161 NIXOPS_OPTS+=" --option plugin-files ${pkgs.nix-plugins}/lib/nix/plugins/libnix-extra-builtins.so"
162 NIXOPS_OPTS+=" --option extra-builtins-file ${modules.nix-plugins.extra-builtins}"
163 export NIXOPS_OPTS
164
165 # disnix
166 #export DISNIXOS_USE_NIXOPS=1
167 #export DISNIX_CLIENT_INTERFACE=disnix-nixops-client
168 #export DISNIX_PROFILE=default
169 #export DISNIX_TARGET_PROPERTY=hostname
170 #export DYSNOMIA_STATEDIR="$PWD"/.sec/dysnomia
171 '';
172 }