Simple script and config (type-safe) for building custom Linux kernels for Firecracker MicroVMs

refactor: enhance type definitions for configuration schemas

+56 -8
+56 -8
config.ts
··· 10 */ 11 12 // Base config value types 13 - const ConfigValueSchema = z.union([ 14 z.literal("y"), // Built-in 15 z.literal("m"), // Module 16 z.literal("n"), // Not set (explicit) ··· 20 ]); 21 22 // Individual config entry 23 - const ConfigEntrySchema = z.object({ 24 key: z.string(), 25 value: ConfigValueSchema.optional(), 26 comment: z.string().optional(), ··· 42 ); 43 44 // Main kernel config schema 45 - export const KernelConfigSchema = z.object({ 46 version: z.string().optional(), 47 buildInfo: z 48 .object({ ··· 56 }); 57 58 // Specific schemas for common config categories 59 - export const ProcessorConfigSchema = z.object({ 60 SMP: z.boolean().optional(), 61 NR_CPUS: z.number().optional(), 62 X86_64: z.boolean().optional(), ··· 66 PREEMPT_NONE: z.boolean().optional(), 67 }); 68 69 - export const SecurityConfigSchema = z.object({ 70 SECURITY: z.boolean().optional(), 71 SECURITY_SELINUX: z.boolean().optional(), 72 SECURITY_APPARMOR: z.boolean().optional(), ··· 76 FORTIFY_SOURCE: z.boolean().optional(), 77 }); 78 79 - export const NetworkingConfigSchema = z.object({ 80 NET: z.boolean().optional(), 81 INET: z.boolean().optional(), 82 IPV6: z.boolean().optional(), ··· 85 UNIX: z.boolean().optional(), 86 }); 87 88 - export const FilesystemConfigSchema = z.object({ 89 EXT4_FS: z.boolean().optional(), 90 XFS_FS: z.boolean().optional(), 91 BTRFS_FS: z.boolean().optional(), ··· 753 } 754 } 755 756 - export const validateKernelConfig = (data: unknown) => { 757 return KernelConfigSchema.safeParse(data); 758 }; 759
··· 10 */ 11 12 // Base config value types 13 + const ConfigValueSchema: z.ZodType< 14 + "y" | "m" | "n" | number | string | boolean 15 + > = z.union([ 16 z.literal("y"), // Built-in 17 z.literal("m"), // Module 18 z.literal("n"), // Not set (explicit) ··· 22 ]); 23 24 // Individual config entry 25 + const ConfigEntrySchema: z.ZodType<{ 26 + key: string; 27 + value?: z.infer<typeof ConfigValueSchema>; 28 + comment?: string; 29 + }> = z.object({ 30 key: z.string(), 31 value: ConfigValueSchema.optional(), 32 comment: z.string().optional(), ··· 48 ); 49 50 // Main kernel config schema 51 + export const KernelConfigSchema: z.ZodType<{ 52 + version?: string | undefined; 53 + buildInfo?: 54 + | { 55 + compiler?: string | undefined; 56 + gccVersion?: string | undefined; 57 + buildSalt?: string | undefined; 58 + } 59 + | undefined; 60 + sections: ConfigSection[]; 61 + flatConfig: Record<string, ConfigValue | undefined>; 62 + }> = z.object({ 63 version: z.string().optional(), 64 buildInfo: z 65 .object({ ··· 73 }); 74 75 // Specific schemas for common config categories 76 + export const ProcessorConfigSchema: z.ZodType<{ 77 + SMP?: boolean | undefined; 78 + NR_CPUS?: number | undefined; 79 + X86_64?: boolean | undefined; 80 + NUMA?: boolean | undefined; 81 + PREEMPT?: boolean | undefined; 82 + PREEMPT_VOLUNTARY?: boolean | undefined; 83 + PREEMPT_NONE?: boolean | undefined; 84 + }> = z.object({ 85 SMP: z.boolean().optional(), 86 NR_CPUS: z.number().optional(), 87 X86_64: z.boolean().optional(), ··· 91 PREEMPT_NONE: z.boolean().optional(), 92 }); 93 94 + export const SecurityConfigSchema: z.ZodType<{ 95 + SECURITY?: boolean | undefined; 96 + SECURITY_SELINUX?: boolean | undefined; 97 + SECURITY_APPARMOR?: boolean | undefined; 98 + SECURITY_SMACK?: boolean | undefined; 99 + SECCOMP?: boolean | undefined; 100 + STACKPROTECTOR?: boolean | undefined; 101 + FORTIFY_SOURCE?: boolean | undefined; 102 + }> = z.object({ 103 SECURITY: z.boolean().optional(), 104 SECURITY_SELINUX: z.boolean().optional(), 105 SECURITY_APPARMOR: z.boolean().optional(), ··· 109 FORTIFY_SOURCE: z.boolean().optional(), 110 }); 111 112 + export const NetworkingConfigSchema: z.ZodType<{ 113 + NET?: boolean | undefined; 114 + INET?: boolean | undefined; 115 + IPV6?: boolean | undefined; 116 + NETFILTER?: boolean | undefined; 117 + PACKET?: boolean | undefined; 118 + UNIX?: boolean | undefined; 119 + }> = z.object({ 120 NET: z.boolean().optional(), 121 INET: z.boolean().optional(), 122 IPV6: z.boolean().optional(), ··· 125 UNIX: z.boolean().optional(), 126 }); 127 128 + export const FilesystemConfigSchema: z.ZodType<{ 129 + EXT4_FS?: boolean | undefined; 130 + XFS_FS?: boolean | undefined; 131 + BTRFS_FS?: boolean | undefined; 132 + NFS_FS?: boolean | undefined; 133 + TMPFS?: boolean | undefined; 134 + }> = z.object({ 135 EXT4_FS: z.boolean().optional(), 136 XFS_FS: z.boolean().optional(), 137 BTRFS_FS: z.boolean().optional(), ··· 799 } 800 } 801 802 + export const validateKernelConfig = ( 803 + data: unknown 804 + ): ReturnType<typeof KernelConfigSchema.safeParse> => { 805 return KernelConfigSchema.safeParse(data); 806 }; 807