aboutsummaryrefslogtreecommitdiff
path: root/.config/nixpkgs
diff options
context:
space:
mode:
authortdro <tdro@users.noreply.github.com>2022-03-16 21:47:07 -0400
committertdro <tdro@users.noreply.github.com>2022-03-16 21:47:07 -0400
commit0aac4414559235f8cd8c454acce30c0471e0f6b1 (patch)
treeda3a12206fdd522964d94bc66d8a2c8fcfef46e1 /.config/nixpkgs
parent9cb74d9137443adc15dc1b005b651bf31526d8dd (diff)
downloaddotfiles-0aac4414559235f8cd8c454acce30c0471e0f6b1.tar.gz
dotfiles-0aac4414559235f8cd8c454acce30c0471e0f6b1.tar.bz2
dotfiles-0aac4414559235f8cd8c454acce30c0471e0f6b1.zip
.config/nixpkgs/helpers/mkShellMinimal: Modify mkShell directly
Mimic upstream mkShell but insert pure path and reduce closure size (package size).
Diffstat (limited to '.config/nixpkgs')
-rw-r--r--.config/nixpkgs/helpers/mkShellMinimal.nix99
1 files changed, 52 insertions, 47 deletions
diff --git a/.config/nixpkgs/helpers/mkShellMinimal.nix b/.config/nixpkgs/helpers/mkShellMinimal.nix
index 1f41fde..a2d0ae6 100644
--- a/.config/nixpkgs/helpers/mkShellMinimal.nix
+++ b/.config/nixpkgs/helpers/mkShellMinimal.nix
@@ -1,54 +1,59 @@
### Source: https://github.com/NixOS/nixpkgs/commit/459771518d44f60b59a19381d07b12297908215d
### Article: https://fzakaria.com/2021/08/02/a-minimal-nix-shell.html
-### Usage:
-
-# let
-#
-# name = "nix-shell.minimal";
-# pkgs = import <nixpkgs> { };
-#
-# mkShellMinimal = pkgs.callPackage (builtins.fetchurl {
-# url = "https://raw.githubusercontent.com/tdro/dotfiles/b710281b132056105709c03dda1899a6afc68a93/.config/nixpkgs/helpers/mkShellMinimal.nix";
-# sha256 = "0smaflcj4r9q0ix45hx904sfmrhdkav6pvv2m7xapc68ykw0ry1i";
-# }) { };
-#
-# in mkShellMinimal {
-# packages = [ pkgs.hello pkgs.gnugrep ];
-# shellHook = ''
-# hello
-# printf "$PATH\n"
-# grep --version
-# export PS1='\h (${name}) \W \$ '
-# '';
-# }
-
-{ writeTextFile, writeScript, system }:
-
-{ shellHook ? "", packages ? [ ], ... }@attrs:
-derivation ({
- inherit system;
-
- name = "minimal-nix-shell";
-
- "stdenv" = writeTextFile rec {
- name = "setup";
- executable = true;
- destination = "/${name}";
- text = ''
- set -e
- PATH=
- for package in ${toString packages}; do
- export PATH=$package/bin:$PATH
- done
- ${shellHook}
- '';
+
+{ lib }:
+
+{ packages ? [ ], inputsFrom ? [ ], buildInputs ? [ ], nativeBuildInputs ? [ ]
+, propagatedBuildInputs ? [ ], propagatedNativeBuildInputs ? [ ], ... }@attrs:
+let
+ mergeInputs = name:
+ (attrs.${name} or [ ]) ++ (lib.subtractLists inputsFrom
+ (lib.flatten (lib.catAttrs name inputsFrom)));
+
+ rest = builtins.removeAttrs attrs [
+ "packages"
+ "inputsFrom"
+ "buildInputs"
+ "nativeBuildInputs"
+ "propagatedBuildInputs"
+ "propagatedNativeBuildInputs"
+ "shellHook"
+ ];
+
+ pkgs = import (builtins.fetchTarball {
+ url = "https://releases.nixos.org/nixos/21.05/nixos-21.05.1510.a165aeceda9/nixexprs.tar.xz";
+ sha256 = "124s05b0xk97arw0vvq8b4wcvsw6024dfdzwcx9qjxf3a2zszmam";
+ }) { };
+
+ stdenv = pkgs.stdenvNoCC.override {
+ cc = null;
+ preHook = "";
+ allowedRequisites = null;
+ initialPath = pkgs.coreutils;
+ extraNativeBuildInputs = [ ];
};
- builder = writeScript "builder.sh" ''
- #!/bin/sh
+in stdenv.mkDerivation ({
+ name = "nix-shell";
+ phases = [ "nobuildPhase" ];
+
+ buildInputs = mergeInputs "buildInputs";
+ nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs");
+ propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
+ propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
+
+ shellHook = ''
+ PATH=${stdenv.initialPath}/bin
+ for package in ${toString buildInputs}; do
+ export PATH=$package/bin:$PATH
+ done
+ '' + lib.concatStringsSep "\n"
+ (lib.catAttrs "shellHook" (lib.reverseList inputsFrom ++ [ attrs ]));
+
+ nobuildPhase = ''
echo
- echo "This derivation is not meant to be built, unless you want to capture the dependency closure.";
+ echo "This derivation is not meant to be built, aborting";
echo
- export > $out
+ exit 1
'';
-} // attrs)
+} // rest)