# Way to profide .config file in cutom kernel build

**URL:** https://discourse.nixos.org/t/way-to-profide-config-file-in-cutom-kernel-build/17219
**Category:** Help
**Created:** [January 20, 2022, 8:15am UTC](https://discourse.nixos.org/t/way-to-profide-config-file-in-cutom-kernel-build/17219 "2022-01-20T08:15:44Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![pekkari](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/958977/32.png) [@pekkari](https://discourse.nixos.org/u/pekkari)
#### Post date: [January 20, 2022, 8:15am UTC](https://discourse.nixos.org/t/way-to-profide-config-file-in-cutom-kernel-build/17219/1 "2022-01-20T08:15:44Z")

</div>

Hi,

Is there any way to provide a correct .config file to build a custom kernel  
in nixos? Currently I set my configuration.nix to build the latest LTS hardened  
kernel by using:

```auto
[...]
  boot.kernelPackages = let
      linux_hardened_pkg = { fetchurl, buildLinux, ... } @ args:

        buildLinux (args // rec {
          version = "5.10.92-hardened1";
          modDirVersion = version;

          src = fetchurl {
            url = "https://github.com/anthraxx/linux-hardened/archive/refs/tags/5.10.92-hardened1.tar.gz";
            sha256 = "be8fab989a432906c71c13c43a120a290730df040b1e89dec14e97121506a7f3";
          };
          kernelPatches = [];

          extraConfig = ''
                  '';

          extraMeta.branch = "5.10";
        } // (args.argsOverride or {}));
      linux_hardened = pkgs.callPackage linux_hardened_pkg{};
    in 
      pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor linux_hardened);
[...]

```

And it works fine, but when I put my kernel configs in the extraConfig section I run  
into a war field of errors, like failing the parse the end of file, or values that are set  
and resolve to ‘n’, between other dragons.

Thanks!

---

<div class="post-metadata">

### Author: ![nixinator](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nixinator/32/3859_2.png) [@nixinator](https://discourse.nixos.org/u/nixinator)
#### Post date: [January 20, 2022, 8:23am UTC](https://discourse.nixos.org/t/way-to-profide-config-file-in-cutom-kernel-build/17219/2 "2022-01-20T08:23:50Z")

</div>

> [@The \*correct\* way to override the latest kernel config](https://discourse.nixos.org/t/the-correct-way-to-override-the-latest-kernel-config/533/9):
>
> Note that the equivalent of [structuredExtraConfig](https://github.com/NixOS/nixpkgs/blob/a74daa0ec496a1039de74075d4db093764b2a8ec/pkgs/os-specific/linux/kernel/generic.nix#L27-L28) is called [extraStructuredConfig](https://github.com/NixOS/nixpkgs/blob/a74daa0ec496a1039de74075d4db093764b2a8ec/pkgs/os-specific/linux/kernel/generic.nix#L93-L94) in kernelPatches: { lib, ... }: { boot.kernelPatches = lib.singleton { name = "enable-lirc"; patch = null; extraStructuredConfig = with lib.kernel; { LIRC = yes; }; }; }

maybe clues there?

---

<div class="post-metadata">

### Author: ![pekkari](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/958977/32.png) [@pekkari](https://discourse.nixos.org/u/pekkari)
#### Post date: [January 20, 2022, 8:38am UTC](https://discourse.nixos.org/t/way-to-profide-config-file-in-cutom-kernel-build/17219/3 "2022-01-20T08:38:03Z")

</div>

Looks like I have to provide all configs one by one, I’d rather ask for  
sourcing the full .config file. Is it possible? I’m evaluating to port an  
existing platform based in buildroot to nixos, and I want to have same  
kernel with configs.

---

<div class="post-metadata">

### Author: ![pekkari](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/958977/32.png) [@pekkari](https://discourse.nixos.org/u/pekkari)
#### Post date: [January 20, 2022, 10:52am UTC](https://discourse.nixos.org/t/way-to-profide-config-file-in-cutom-kernel-build/17219/4 "2022-01-20T10:52:57Z")

</div>

Something like [this](https://github.com/NixOS/nixpkgs/blob/a74daa0ec496a1039de74075d4db093764b2a8ec/pkgs/os-specific/linux/kernel/generic.nix#L18) may make it, though I fail to find  
further documentation how to use it. Any hints?

**Edited:** false alarm, that seems to be to modify the make target for defconfig, which is  
not about generating your own file and providing it as a defconfig, so not an option.

Thanks!

---

<div class="post-metadata">

### Author: ![pekkari](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/958977/32.png) [@pekkari](https://discourse.nixos.org/u/pekkari)
#### Post date: [January 20, 2022, 11:18am UTC](https://discourse.nixos.org/t/way-to-profide-config-file-in-cutom-kernel-build/17219/5 "2022-01-20T11:18:10Z")

</div>

[This](https://github.com/NixOS/nixpkgs/blob/a74daa0ec496a1039de74075d4db093764b2a8ec/pkgs/os-specific/linux/kernel/manual-config.nix#L30) one it is! though I certainly don’t have any idea how to specify  
a manual config for the kernel I’m looking for, any help appreciated.

---

<div class="post-metadata">

### Author: ![julm](https://discourse.nixos.org/user_avatar/discourse.nixos.org/julm/32/9530_2.png) [@julm](https://discourse.nixos.org/u/julm)
#### Post date: [February 12, 2022, 11:49pm UTC](https://discourse.nixos.org/t/way-to-profide-config-file-in-cutom-kernel-build/17219/6 "2022-02-12T23:49:17Z")

</div>

There is a section [Customize your kernel](https://nixos.org/manual/nixos/stable/#sec-linux-config-customizing) in NixOS’ manual showing how to use `manualConfig`.

---

<div class="post-metadata">

### Author: ![GrabbenD](https://discourse.nixos.org/user_avatar/discourse.nixos.org/grabbend/32/16153_2.png) [@GrabbenD](https://discourse.nixos.org/u/GrabbenD)
#### Post date: [April 29, 2023, 12:02pm UTC](https://discourse.nixos.org/t/way-to-profide-config-file-in-cutom-kernel-build/17219/7 "2023-04-29T12:02:26Z")

</div>

I’m failing to understand how to combine `buildLinux` with `manualConfig`  
Did you find a solution @pekkari?

---

<div class="post-metadata">

### Author: ![potosi](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@potosi](https://discourse.nixos.org/u/potosi)
#### Post date: [July 8, 2023, 9:41pm UTC](https://discourse.nixos.org/t/way-to-profide-config-file-in-cutom-kernel-build/17219/8 "2023-07-08T21:41:27Z")

</div>

Could someone share the code to make this work on a simple configuration.nix? I’m new to nixos and have been trying to make this work for hours.

---

<div class="post-metadata">

### Author: ![nixinator](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nixinator/32/3859_2.png) [@nixinator](https://discourse.nixos.org/u/nixinator)
#### Post date: [November 8, 2023, 11:52pm UTC](https://discourse.nixos.org/t/way-to-profide-config-file-in-cutom-kernel-build/17219/9 "2023-11-08T23:52:29Z")

</div>

can you share what your to achieve, and your current code?
