Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update nixos ucm install #141

Closed
wants to merge 13 commits into from
350 changes: 299 additions & 51 deletions src/docs/installing/distros.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,64 @@

## NixOS

- Enable and configure keyd (Example is cros-standard. Adjust as you need!)
::: tip
Note that the configurations are applied to `configuration.nix` located in `/etc/nixos`.
:::

::: tip
Running the command `sudo nixos-rebuild switch` will rebuild your installation and apply the changes made.
:::

- For Chromebook-related configuration, we will create `chrome-device.nix`.
```bash
sudo touch /etc/nixos/chrome-device.nix
```

- Then at the top of `configuration.nix` we import `chrome-device.nix`.
```nix
# configuration.nix
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).

{ config, pkgs, ... }:

{
imports =
[
# Include the results of the hardware scan.
./hardware-configuration.nix
./chrome-device.nix
];

# the rest of your configuration...
}

```

- First, enable and configure keyd (Example is cros-standard. Adjust as you need!)
```nix
# chrome-device.nix
{ config, pkgs, lib, ... }:

services.keyd = {
enable = true;
keyboards.internal = {
ids = [ "0001:0001" ];
ids = [
"k:0001:0001"
"k:18d1:5044"
"k:18d1:5052"
"k:0000:0000"
"k:18d1:5050"
"k:18d1:504c"
"k:18d1:503c"
"k:18d1:5030"
"k:18d1:503d"
"k:18d1:505b"
"k:18d1:5057"
"k:18d1:502b"
"k:18d1:5061"
];
settings = {
main = {
f1 = "back";
Expand Down Expand Up @@ -77,72 +128,269 @@ services.keyd = {
```

- Audio setup (Does the same as the audio script)
**Change the `GENERATION` to your board generation!**
Possible options: `adl` | `jsl` | `tgl` | `cml` | `glk` | `apl` | `avs` | `bsw` | `byt` | `mendocino` | `cezanne` | `picasso` | `stoney`

If your generation isn't listed above, you can skip this section
- Build the package in `chrome-device.nix`

```nix
# configuration.nix
nixpkgs.overlays = with pkgs; [ (final: prev:
{
alsa-ucm-conf = prev.alsa-ucm-conf.overrideAttrs (old: {
wttsrc = (fetchFromGitHub {
owner = "WeirdTreeThing";
repo = "chromebook-ucm-conf";
rev = "484f5c581ac45c4ee6cfaf62bdecedfa44353424";
hash = "sha256-Jal+VfxrPSAPg9ZR+e3QCy4jgSWT4sSShxICKTGJvAI=";
});
installPhase = ''
runHook preInstall

mkdir -p $out/share/alsa
cp -r ucm ucm2 $out/share/alsa

mkdir -p $out/share/alsa/ucm2/conf.d
cp -r $wttsrc/{hdmi,dmic}-common $wttsrc/GENERATION/* $out/share/alsa/ucm2/conf.d

runHook postInstall
'';
});
})
# chrome-device.nix
{ config, pkgs, lib, ... }:

services.keyd {
# rest of keyd configuration...
};

let
cb-ucm-conf = with pkgs; alsa-ucm-conf.overrideAttrs {
wttsrc = fetchFromGitHub {
owner = "WeirdTreeThing";
repo = "alsa-ucm-conf-cros";
rev = "6b395ae73ac63407d8a9892fe1290f191eb0315b";
hash = "sha256-GHrK85DmiYF6FhEJlYJWy6aP9wtHFKkTohqt114TluI=";
};
unpackPhase = ''
runHook preUnpack
tar xf "$src"
runHook postUnpack
'';

installPhase = ''
runHook preInstall
mkdir -p $out/share/alsa
cp -r alsa-ucm*/ucm2 $out/share/alsa
runHook postInstall
'';
};
in
{
# add your audio setup modprobes here

environment = {
systemPackages = with pkgs; [
maliit-keyboard # optional
sof-firmware
];
sessionVariables.ALSA_CONFIG_UCM2 = "${cb-ucm-conf}/share/alsa/ucm2";
# AUDIO
};

system = {
replaceRuntimeDependencies = [
({
original = pkgs.alsa-ucm-conf;
replacement = cb-ucm-conf;
})
];
};
}

```

- This process varies between AVS and SOF configuration. Replace `# AUDIO` with the following:

- For SOF:
```nix
# chrome-device.nix
# for 23.11 and unstable
etc = {
"wireplumber/main.lua.d/51-increase-headroom.lua".text = ''
rule = {
matches = {
{
{ "node.name", "matches", "alsa_output.*" },
},
},
apply_properties = {
["api.alsa.headroom"] = 4096,
},
}

table.insert(alsa_monitor.rules,rule)
'';
};

```

- For AVS:
```nix
# chrome-device.nix
# for 23.11 and unstable
etc = {
"wireplumber/main.lua.d/51-avs-dmic.lua".text = ''
rule = {
matches = {
{
{ "node.nick", "equals", "Internal Microphone" },
},
},
apply_properties = {
["audio.format"] = "S16LE",
},
}

table.insert(alsa_monitor.rules, rule)
'';
};

```

- However, if you're on NixOS 24.05, remove this set of lines in `chrome-device.nix`
```nix
# chrome-device.nix

# additonal configuration...

# for 23.11 and unstable
etc = {
"wireplumber/main.lua.d/51-increase-headroom.lua".text = ''
rule = {
matches = {
{
{ "node.name", "matches", "alsa_output.*" },
},
},
apply_properties = {
["api.alsa.headroom"] = 4096,
},
}

table.insert(alsa_monitor.rules,rule)
'';
};

# additonal configuration...

```

- Or if you're using AVS:
```nix
# chrome-device.nix

# additonal configuration...

# for 23.11 and unstable
etc = {
"wireplumber/main.lua.d/51-avs-dmic.lua".text = ''
rule = {
matches = {
{
{ "node.nick", "equals", "Internal Microphone" },
},
},
apply_properties = {
["audio.format"] = "S16LE",
},
}

table.insert(alsa_monitor.rules, rule)
'';
};

# additonal configuration...

```

- And from here replace it with this at the bottom of the `let...in` expression
```nix
# chrome-device.nix
in
{
# additonal configuration...

# for 24.05
services.pipewire.wireplumber.configPackages = [
(pkgs.writeTextDir "share/wireplumber/main.lua.d/51-increase-headroom.lua" ''
rule = {
matches = {
{
{ "node.name", "matches", "alsa_output.*" },
},
},
apply_properties = {
["api.alsa.headroom"] = 4096,
},
}

table.insert(alsa_monitor.rules,rule)
'')
];

# additonal configuration...
}
```

- Install and export the ucm config as a session variable
- Or if you're using AVS:
```nix
# configuration.nix
environment = {
systemPackages = with pkgs; [\
alsa-ucm-conf
# chrome-device.nix
in
{
# additonal configuration...

# for 24.05
services.pipewire.wireplumber.configPackages = [
(pkgs.writeTextDir "share/wireplumber/main.lua.d/51-avs-dmic.lua" ''
rule = {
matches = {
{
{ "node.nick", "equals", "Internal Microphone" },
},
},
apply_properties = {
["audio.format"] = "S16LE",
},
}

table.insert(alsa_monitor.rules, rule)
'')
];
sessionVariables = {
ALSA_CONFIG_UCM2 = "${pkgs.alsa-ucm-conf}/share/alsa/ucm2";
};
};

# additonal configuration...
}
```

- Audio setup modprobes
- Audio setup modprobes
- SOF modprobe config for Alderlake, Jasperlake, Tigerlake, Cometlake, and Geminilake
```nix
# configuration.nix
boot.extraModprobeConfig = ''
options snd-intel-dspcfg dsp_driver=3
'';
# chrome-device.nix
in
{
boot = {
extraModprobeConfig = ''
options snd-intel-dspcfg dsp_driver=3
'';
};

# additonal configuration...
}

```

- SOF modprobe config for Braswell and Baytrail
```nix
# configuration.nix
boot.extraModprobeConfig = ''
options snd-intel-dspcfg dsp_driver=3
options snd-sof sof_debug=1
'';
# chrome-device.nix
in
{
boot = {
extraModprobeConfig = ''
options snd-intel-dspcfg dsp_driver=3
options snd-sof sof_debug=1
'';
};

# additonal configuration...
}
```

- AVS modprobe config for Skylake, Kabylake, and Apollolake
```nix
# configuration.nix
boot.extraModprobeConfig = ''
options snd-intel-dspcfg dsp_driver=4
'';
# chrome-device.nix
in
{
boot = {
extraModprobeConfig = ''
options snd-intel-dspcfg dsp_driver=4
'';
};

# additonal configuration...
}
```
Loading