@@ -96,32 +96,11 @@ func (d *DerivationBuilder) Build(ctx context.Context, pkgStorePath string) erro
96
96
97
97
func (d * DerivationBuilder ) build (ctx context.Context , pkg , out * packageFS ) error {
98
98
if d .RestoreRefs {
99
- // Find store path references to build inputs that were removed
100
- // from Python.
101
- refs , err := d .findRemovedRefs (ctx , pkg )
102
- if err != nil {
103
- return err
104
- }
105
-
106
- // Group the references we want to restore by file path.
107
- d .bytePatches = make (map [string ][]fileSlice , len (refs ))
108
- for _ , ref := range refs {
109
- d .bytePatches [ref .path ] = append (d .bytePatches [ref .path ], ref )
110
- }
111
-
112
- // If any of those references have shared libraries, add them
113
- // back to Python's RPATH.
114
- if d .glibcPatcher != nil {
115
- nixStore := cmp .Or (os .Getenv ("NIX_STORE" ), "/nix/store" )
116
- seen := make (map [string ]bool )
117
- for _ , ref := range refs {
118
- storePath := filepath .Join (nixStore , string (ref .data ))
119
- if seen [storePath ] {
120
- continue
121
- }
122
- seen [storePath ] = true
123
- d .glibcPatcher .prependRPATH (newPackageFS (storePath ))
124
- }
99
+ if err := d .restoreMissingRefs (ctx , pkg ); err != nil {
100
+ // Don't break the flake build if we're unable to
101
+ // restore some of the refs. Having some is still an
102
+ // improvement.
103
+ slog .ErrorContext (ctx , "unable to restore all removed refs" , "err" , err )
125
104
}
126
105
}
127
106
@@ -152,6 +131,37 @@ func (d *DerivationBuilder) build(ctx context.Context, pkg, out *packageFS) erro
152
131
return cmd .Run ()
153
132
}
154
133
134
+ func (d * DerivationBuilder ) restoreMissingRefs (ctx context.Context , pkg * packageFS ) error {
135
+ // Find store path references to build inputs that were removed
136
+ // from Python.
137
+ refs , err := d .findRemovedRefs (ctx , pkg )
138
+ if err != nil {
139
+ return err
140
+ }
141
+
142
+ // Group the references we want to restore by file path.
143
+ d .bytePatches = make (map [string ][]fileSlice , len (refs ))
144
+ for _ , ref := range refs {
145
+ d .bytePatches [ref .path ] = append (d .bytePatches [ref .path ], ref )
146
+ }
147
+
148
+ // If any of those references have shared libraries, add them
149
+ // back to Python's RPATH.
150
+ if d .glibcPatcher != nil {
151
+ nixStore := cmp .Or (os .Getenv ("NIX_STORE" ), "/nix/store" )
152
+ seen := make (map [string ]bool )
153
+ for _ , ref := range refs {
154
+ storePath := filepath .Join (nixStore , string (ref .data ))
155
+ if seen [storePath ] {
156
+ continue
157
+ }
158
+ seen [storePath ] = true
159
+ d .glibcPatcher .prependRPATH (newPackageFS (storePath ))
160
+ }
161
+ }
162
+ return nil
163
+ }
164
+
155
165
func (d * DerivationBuilder ) copyDir (out * packageFS , path string ) error {
156
166
path , err := out .OSPath (path )
157
167
if err != nil {
0 commit comments