Partons du principe qu'un projet utilise un fichier shell.nix
partagé entre plusieurs personnes, et qu'on souhaite l'utiliser tout en ajoutant notre propre configuration (par exemple pour ajouter des paquets dont on a personnellement besoin).
Exemple de fichier shell.nix
:
# shell.nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = [
pkgs.kubectl
];
shellHook =
''
source <(kubectl completion bash)
alias k=kubectl
complete -F __start_kubectl k
'';
}
Notre fichier de surcharge, ici local.nix
:
# local.nix
let
pkgs = import <nixpkgs> { };
shellNix = import ./shell.nix { inherit pkgs; };
in
pkgs.mkShell {
buildInputs = shellNix.buildInputs ++ [
pkgs.helix
pkgs.rustc
];
nativeBuildInputs = shellNix.nativeBuildInputs ++ [];
propagatedBuildInputs = shellNix.propagatedBuildInputs ++ [];
propagatedNativeBuildInputs = shellNix.propagatedNativeBuildInputs ++ [];
shellHook = shellNix.shellHook + "\n" +
''
'';
}
On peut alors obtenir un shell avec à la fois la configuration partagée et notre configuration locale :
nix-shell local.nix
Il y a peut-être plus propre ; mais pour l'instant ça me suffit :-]