summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stdenv_prefix/example.nix51
-rw-r--r--stdenv_prefix/prehook.sh98
-rw-r--r--stdenv_prefix/stdenv.md133
3 files changed, 282 insertions, 0 deletions
diff --git a/stdenv_prefix/example.nix b/stdenv_prefix/example.nix
new file mode 100644
index 0000000..0d4aa65
--- /dev/null
+++ b/stdenv_prefix/example.nix
@@ -0,0 +1,51 @@
1{ storepath_length ? 30, storepath_chunks ? 4, pkgs ? import <nixpkgs> {
2 stdenvStages = { config, overlays, localSystem, ... }@args: (import <nixpkgs/pkgs/stdenv> args) ++ [
3 (previousStage: {
4 inherit config overlays;
5 stdenv = let
6 toPreHook = withAppendOut: ''
7 storepath_length=${toString storepath_length}
8 storepath_chunks=${toString storepath_chunks}
9 '' + builtins.readFile ./prehook.sh + (pkgs.lib.optionalString withAppendOut ''
10 appendOut
11 '');
12 newlibunistring = previousStage.libunistring.overrideAttrs (attrs: {
13 preHook = attrs.preHook or "" + (toPreHook true);
14 am_cv_func_iconv_works = "yes";
15 });
16 newlibidn2 = (previousStage.libidn2.override { libunistring = newlibunistring; }).overrideAttrs (attrs: {
17 preHook = attrs.preHook or "" + (toPreHook true);
18 postFixup = ''
19 ${previousStage.nukeReferences}/bin/nuke-refs -e $(cat ${newlibunistring}/nix-support/new-out)/lib \
20 "$out"/lib/lib*.so.*.*
21 '';
22 });
23 overridenCallPackage = p: a: previousStage.callPackage p (a // { libidn2 = newlibidn2;});
24
25 newlibc = (previousStage."${localSystem.libc}".override { callPackage = overridenCallPackage; }).overrideAttrs(old: {
26 preHook = old.preHook or "" + (toPreHook true);
27 });
28 newbintools = (previousStage.binutils.override { libc = newlibc; }).overrideAttrs(old: {
29 postFixup = old.postFixup + ''
30 newlibcout=$(cat ${newlibc}/nix-support/new-out)
31 sed -i -e "s@${newlibc}@$newlibcout@g" $out/nix-support/*
32 '';
33 });
34 newStdenv = previousStage.stdenv.override {
35 allowedRequisites = null;
36 extraAttrs.bintools = newbintools;
37 cc = previousStage.gcc.override({ bintools = newbintools; libc = newlibc; });
38 overrides = self: super: rewriteMap (previousStage.stdenv.overrides self super) // {
39 ${localSystem.libc} = newlibc;
40 };
41 preHook = previousStage.stdenv.preHook + ''
42 libc_path=${newlibc}
43 '' + (toPreHook false);
44 };
45 rewriteMap = builtins.mapAttrs (n: v: v.override { stdenv = newStdenv; });
46 in
47 newStdenv;
48 })
49 ];
50} }:
51 pkgs.xar
diff --git a/stdenv_prefix/prehook.sh b/stdenv_prefix/prehook.sh
new file mode 100644
index 0000000..db9a4d2
--- /dev/null
+++ b/stdenv_prefix/prehook.sh
@@ -0,0 +1,98 @@
1count_chunks() {
2 elements="${1//[^\/]}"
3 echo $(( "${#elements}" ))
4}
5
6oldout=$out
7prefix_chunks=$(count_chunks $NIX_STORE)
8
9: ${storepath_length=${#NIX_STORE}}
10: ${storepath_chunks=$prefix_chunks}
11
12if [ "$storepath_chunks" -lt $prefix_chunks ]; then
13 echo "Need to have at least as much path elements as the initial prefix"
14 exit 1
15fi
16
17min_length=$(( ${#NIX_STORE} + 2 * $storepath_chunks - 2 * $prefix_chunks ))
18if [ "$storepath_length" -lt "$min_length" ]; then
19 echo "The storepath length needs to be at least the length of the prefix"
20 exit 1
21fi
22
23if [ "$storepath_chunks" -eq "$prefix_chunks" -a "$storepath_length" -gt "$min_length" ]; then
24 echo "You need at least one more chunk for a non-standard path length"
25 exit 1
26fi
27
28appendOut() {
29 chunk_prefix=$(for (( c=$prefix_chunks ; c < $storepath_chunks ; c++ )); do echo -n "/x"; done)
30 length_prefix=$(for (( c=$(( ${#NIX_STORE} + ${#chunk_prefix} )) ; c < $storepath_length ; c++ )); do echo -n "x"; done)
31 out="$out$chunk_prefix$length_prefix"
32 if [ -n $chunk_prefix -o -n $length_prefix ]; then
33 mkdir -p $(dirname $out)
34 fi
35
36 : ${libc_path=}
37 : ${configureFlags=}
38 configureFlags="${configureFlags//$oldout/$out}"
39 if [ -n "$libc_path" ]; then
40 libc_oldpath=$libc_path/lib
41 libc_newpath=$(cat $libc_path/nix-support/new-out)/lib
42 configureFlags="${configureFlags//$libc_oldpath/$libc_newpath}"
43 fi
44}
45
46addNixSupport() {
47 if [ ! -d $out ]; then
48 return
49 fi
50 mkdir -p $out/nix-support
51 echo $out > $out/nix-support/new-out
52}
53
54overridePlaceholder() {
55function _callImplicitHook {
56 local def="$1"
57 local hookName="$2"
58 if declare -F "$hookName" > /dev/null; then
59 "$hookName"
60 elif type -p "$hookName" > /dev/null; then
61 source "$hookName"
62 elif [ -n "${!hookName:-}" ]; then
63 content="${!hookName}"
64 eval "${content//$oldout/$out}"
65 else
66 return "$def"
67 fi
68}
69}
70
71preHooks+=(appendOut overridePlaceholder)
72
73restoreSingleFile() {
74 if [ "$out" != "$oldout" -a -f $out ]; then
75 cp -a $out ./file
76 rm -rf $oldout
77 cp -a ./file $oldout
78 fi
79}
80
81addSymlinks() {
82 if [ "$out" != "$oldout" -a -d $out ]; then
83 ln -s $out/* $oldout/
84 fi
85}
86
87rename_generic_build() {
88eval "$(echo "orig_genericBuild()"; declare -f genericBuild | tail -n +2)"
89function genericBuild {
90 orig_genericBuild "$@"
91 restoreSingleFile
92 addSymlinks
93 addNixSupport
94}
95}
96
97exitHooks+=(restoreSingleFile addSymlinks addNixSupport)
98postHooks+=(rename_generic_build)
diff --git a/stdenv_prefix/stdenv.md b/stdenv_prefix/stdenv.md
new file mode 100644
index 0000000..f58455a
--- /dev/null
+++ b/stdenv_prefix/stdenv.md
@@ -0,0 +1,133 @@
1Ce dossier contient un travail permettant de créer des dérivations qui
2vont toutes commencer par un préfix de taille et avec un nombre de
3composants donné (de la forme x/x/xxxxx)
4
5Le but étant de pouvoir copier une closure d’une dérivation, la mettre
6par exemple dans /opt/nix/store/....-foo et avec un simple `rename` +
7`sed` la rendre utilisable (dans l’exemple /nix/store/....-foo/xxx ->
8/opt/nix/store/....-foo).
9
10Ci dessous se trouvent des notes de ce que j’ai compris de la stack
11stdenv (pkgs/stdenv/linux/default.nix)
12
13# Stage -1
14 gcc-unwrapped = null
15 binutils = null
16 coreutils = null
17 gnugrep = null
18 `stagem1 = stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages`
19 -> contient cinq entrées (dont stdenv "invalide")
20
21# Stage 0
22 `stage0 = stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages`
23 (`stagem1 = stage0.stdenv.__bootPackages`)
24 `stage0.stdenv`
25 -> cc = null
26 `stage0`
27 overrides:
28 - glibc = extrait (ln -s) de bootstrapTools (bootstrap-stage0-glibc)
29 - gcc-unwrapped = bootstrapTools
30 - binutils = wrapper sur bootstrapTools (bootstrap-stage0-binutils-wrapper)
31 - coreutils = bootstrapTools
32 - gnugrep = bootstrapTools
33 - ccWrapperStdenv = stage0.stdenv
34
35# Stage 1
36 `stage1 = stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages`
37 (`stage0 = stage1.stdenv.__bootPackages`)
38 `stage1.stdenv`
39 -> cc = cc-wrapper buildé avec
40 cc = stage0.gcc-unwrapped = bootstrapTools
41 bintools = stage0.binutils = bootstrap-stage0-binutils-wrapper
42 glibc = stage0.glibc = bootstrap-stage0-glibc
43 coreutils = stage0.coreutils = bootstrapTools
44 gnugrep = stage0.gnugrep = bootstrapTools
45 stdenvNoCC = stage0.ccWrapperStdenv = stage0.stdenv
46 `stage1`
47 overrides:
48 - binutils-unwrapped = override (gold = false)
49 - ccWrapperStdenv = stage0.stdenv
50 - gcc-unwrapped = bootstrapTools
51 - coreutils = bootstrapTools
52 - gnugrep = bootstrapTools
53 - glibc = bootstrap-stage0-glibc
54 - perl = override (threading = false)
55
56# Stage 2
57 `stage2 = stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages`
58 (`stage1 = stage2.stdenv.__bootPackages`)
59 `stage2.stdenv`
60 -> cc = cc-wrapper buildé avec
61 cc = stage1.gcc-unwrapped = bootstrapTools
62 bintools = stage1.binutils = wrapper sur binutils-unwrapped (gold = false)
63 glibc = bootstrap-stage0-glibc
64 coreutils = bootstrapTools
65 gnugrep = bootstrapTools
66 stdenvNoCC = stage1.ccWrapperStdenv = stage0.stdenv
67 `stage2`
68 overrides:
69 - ccWrapperStdenv = stage0.stdenv
70 - gcc-unwrapped = bootstrapTools
71 - coreutils = bootstrapTools
72 - gnugrep = bootstrapTools
73 - perl = override (threading = false)
74 - binutils = stage1.override (libc = self.glibc)
75 - libidn2 = nuke-refs
76 - libunistring = nuke-refs
77 - dejagnu = nocheck
78 - gnum4 = stage1.gnum4
79 - bison = stage1.bison
80
81# Stage 3
82 `stage3 = stdenv.__bootPackages.stdenv.__bootPackages`
83 (`stage2 = stage3.stdenv.__bootPackages`)
84 `stage3.stdenv`
85 -> cc = cc-wrapper buildé avec
86 cc = stage2.gcc-unwrapped = bootstrapTools
87 bintools = stage2.binutils
88 glibc = stage2.glibc
89 coreutils = bootstrapTools
90 gnugrep = bootstrapTools
91 stdenvNoCC = stage2.ccWrapperStdenv = stage0.stdenv
92 `stage3`
93 overrides:
94 - ccWrapperStdenv = stage0.stdenv
95 - binutils = stage2.binutils
96 - coreutils = bootstrapTools
97 - gnugrep = bootstrapTools
98 - perl patchelf linuxHeaders gnum4 bison libidn2 libunistring = stage2
99 - glibc = stage2.glibc
100 - gmp mpfr libmpc isl_0_20 = override static
101 - gcc-unwrapped = override (isl)
102
103# Stage 4
104 `stage4 = stdenv.__bootPackages`
105 (`stage3 = stage4.stdenv.__bootPackages`)
106 `stage4.stdenv`
107 -> cc = cc-wrapper buildé avec
108 cc = stage3.gcc-unwrapped = override (isl)
109 bintools = stage2.binutils
110 glibc = stage2.glibc
111 coreutils = bootstrapTools
112 gnugrep = bootstrapTools
113 stdenvNoCC = stage3.ccWrapperStdenv = stage0.stdenv
114 `stage4`
115 overrides:
116 - gettext gnum4 bison gmp perl texinfo zlib linuxHeaders libidn2 libunistring = stage3
117 - glibc = stage3.glibc = stage2.glibc
118 - binutils = override
119 - gcc = buildé avec
120 cc = stage3.gcc-unwrapped
121 bintools = self.binutils
122 libc = self.glibc
123 stdenvNoCC coreutils gnugrep = self
124
125# Final Stage
126 `stdenv`
127 cc = stage4.gcc
128 `pkgs`
129 overrides:
130 - glibc = stage4.glibc = stage2.glibc
131 - zlib libidn2 libunistring = stage4 = stage3
132 - (hors cross-compile) binutils binutils-unwrapped = stage4
133 - (hors cross-compile) gcc = cc