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