@@ -66,6 +66,19 @@ func (p *PropolisProvider) CreateVM(ctx context.Context, env *environment.Enviro
6666 "ssh_port" , env .SSHPort ,
6767 )
6868
69+ rootfsHooks := []propolis.RootFSHook {
70+ hooks .InjectAuthorizedKeys (pubKeyContent , hooks .WithKeyUser ("/home/sandbox" , 1000 , 1000 )),
71+ }
72+ if opts .InitPath != "" {
73+ hook , err := initInjector (opts .InitPath )
74+ if err != nil {
75+ return nil , err
76+ }
77+ rootfsHooks = append (rootfsHooks , hook )
78+ } else {
79+ rootfsHooks = append (rootfsHooks , InjectInitBinary ())
80+ }
81+
6982 // Build propolis options.
7083 propolisOpts := []propolis.Option {
7184 propolis .WithName ("waggle-" + env .ID ),
@@ -77,24 +90,14 @@ func (p *PropolisProvider) CreateVM(ctx context.Context, env *environment.Enviro
7790 }),
7891 propolis .WithDataDir (envDataDir ),
7992
80- // Inject SSH authorized_keys into the rootfs before boot.
81- propolis .WithRootFSHook (hooks .InjectAuthorizedKeys (pubKeyContent , hooks .WithKeyUser ("/home/sandbox" , 1000 , 1000 ))),
93+ // Inject SSH authorized_keys and waggle-init into the rootfs before boot.
94+ propolis .WithRootFSHook (rootfsHooks ... ),
95+ propolis .WithInitOverride ("/waggle-init" ),
8296
8397 // Wait for SSH to become ready after boot.
8498 propolis .WithPostBoot (sshReadyWaiter (env .SSHPort , privateKeyPath )),
8599 }
86100
87- if opts .InitPath != "" {
88- hook , err := initInjector (opts .InitPath )
89- if err != nil {
90- return nil , err
91- }
92- propolisOpts = append (propolisOpts ,
93- propolis .WithRootFSHook (hook ),
94- propolis .WithInitOverride ("/waggle-init" ),
95- )
96- }
97-
98101 var backendOpts []libkrun.Option
99102 if opts .RunnerPath != "" {
100103 backendOpts = append (backendOpts , libkrun .WithRunnerPath (opts .RunnerPath ))
0 commit comments