Skip to content

Instantly share code, notes, and snippets.

@mti
Last active August 4, 2025 10:11
Show Gist options
  • Save mti/f6572f34aefbcb1aba1d33c888a5b298 to your computer and use it in GitHub Desktop.
Save mti/f6572f34aefbcb1aba1d33c888a5b298 to your computer and use it in GitHub Desktop.
Minimal NixOS flake for Kodi on Raspberry Pi 4B

NixOS flake for Kodi on RaspberryPi 4B

This contains a flake based on the nixos-raspberrypi repository to build a NixOS system sufficient to run Kodi.

If this is not the case for you already, you may want to make sure that the firmware partition /dev/disk/by-label/FIRMWARE is properly mounted to /boot/firmware:

sudo mount /dev/disk/by-label/FIRMWARE /boot/firmware

This wasn't the case for me (as it isn't done by default in NixOS disk images for the Raspberry Pi), which made me wonder for a while why everything wasn't working properly.

{ config, pkgs, lib, nixos-raspberrypi, ... }:
let rpi-pkgs = nixos-raspberrypi.packages.aarch64-linux; in
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
./kodi.nix
];
networking.hostName = "rpi4kodi";
hardware.enableRedistributableFirmware = true;
system.stateVersion = "25.05";
environment.systemPackages = with rpi-pkgs; [
raspberrypi-utils
ffmpeg_7
vlc
];
nixpkgs.config.allowUnfree = true;
time.timeZone = "Asia/Tokyo";
systemd.globalEnvironment = {
TZ = "Asia/Tokyo";
};
i18n.defaultLocale = "en_US.UTF-8";
i18n.extraLocaleSettings = {
LC_ADDRESS = "C.UTF-8";
LC_IDENTIFICATION = "C.UTF-8";
LC_MEASUREMENT = "C.UTF-8";
LC_MONETARY = "C.UTF-8";
LC_NAME = "C.UTF-8";
LC_NUMERIC = "C.UTF-8";
LC_PAPER = "C.UTF-8";
LC_TELEPHONE = "C.UTF-8";
LC_TIME = "C.UTF-8";
};
programs.zsh.enable = true;
programs.vim = {
enable = true;
defaultEditor = true;
};
users = {
groups = {
rpi4kodi.gid = 1000;
};
users.rpi4kodi = {
isNormalUser = true;
uid = 1000;
description = "RPi4 User";
extraGroups = [ "networkmanager" "wheel" "i2c" "video" ];
shell = pkgs.zsh;
password = "pleaseChangeMe";
};
};
nix.settings.experimental-features = [ "nix-command" "flakes" ];
nix.settings.trusted-users = [ "@wheel" ];
}
{
"nodes": {
"argononed": {
"flake": false,
"locked": {
"lastModified": 1729566243,
"narHash": "sha256-DPNI0Dpk5aym3Baf5UbEe5GENDrSmmXVdriRSWE+rgk=",
"owner": "nvmd",
"repo": "argononed",
"rev": "16dbee54d49b66d5654d228d1061246b440ef7cf",
"type": "github"
},
"original": {
"owner": "nvmd",
"repo": "argononed",
"type": "github"
}
},
"nixos-images": {
"inputs": {
"nixos-stable": [
"nixos-raspberrypi",
"nixpkgs"
],
"nixos-unstable": [
"nixos-raspberrypi",
"nixpkgs"
]
},
"locked": {
"lastModified": 1746225872,
"narHash": "sha256-ySSk4r9Mq6dO2MYaik4vTU18sA17aHTSb2LsAFXdw3E=",
"owner": "nvmd",
"repo": "nixos-images",
"rev": "33343fd9a237ed98df52e3611f833fdab729c358",
"type": "github"
},
"original": {
"owner": "nvmd",
"ref": "sdimage-installer",
"repo": "nixos-images",
"type": "github"
}
},
"nixos-raspberrypi": {
"inputs": {
"argononed": "argononed",
"nixos-images": "nixos-images",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1747754643,
"narHash": "sha256-tbnDv8E8Vv7avlLz/rL3e1ghq2/MDNqdgpmzlHTIl9Y=",
"owner": "nvmd",
"repo": "nixos-raspberrypi",
"rev": "8e7791287af030ce83784b98da788875fc4be97e",
"type": "github"
},
"original": {
"owner": "nvmd",
"ref": "main",
"repo": "nixos-raspberrypi",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1746408827,
"narHash": "sha256-tqjFTkIm8xhHk36KSk3mCieEvWmFl7SWCVESGlcUFew=",
"owner": "nvmd",
"repo": "nixpkgs",
"rev": "1473ad1795a4a4ea14fe636c464649b9b27d8cc8",
"type": "github"
},
"original": {
"owner": "nvmd",
"ref": "modules-with-keys-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1748460289,
"narHash": "sha256-7doLyJBzCllvqX4gszYtmZUToxKvMUrg45EUWaUYmBg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "96ec055edbe5ee227f28cdbc3f1ddf1df5965102",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixos-raspberrypi": "nixos-raspberrypi",
"nixpkgs": "nixpkgs_2"
}
}
},
"root": "root",
"version": 7
}
{
description = ''
Examples of NixOS systems' configuration for Raspberry Pi boards
using nixos-raspberrypi
'';
nixConfig = {
extra-substituters = [
"https://nixos-raspberrypi.cachix.org"
];
extra-trusted-public-keys = [
"nixos-raspberrypi.cachix.org-1:4iMO9LXa8BqhU+Rpg6LQKiGa2lsNh/j2oiYLNOQ5sPI="
];
connect-timeout = 5;
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixos-raspberrypi.url = "github:nvmd/nixos-raspberrypi/main";
};
outputs = { self, nixpkgs, nixos-raspberrypi, ... }@inputs:
{
nixosConfigurations.sakubi = nixos-raspberrypi.lib.nixosSystem {
specialArgs = inputs;
modules = [
./nixos-rpi4.nix
./configuration.nix
];
};
};
}
# Do not modify this file! It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, inputs, ... }:
{
imports =
[ (modulesPath + "/installer/scan/not-detected.nix")
];
fileSystems."/" = {
device = "/dev/disk/by-label/NIXOS_SD ";
fsType = "ext4";
options = [ "noatime" ];
};
fileSystems."/boot/firmware" = {
device = "/dev/disk/by-uuid/FIRMWARE";
fsType = "vfat";
options = [
"noatime"
"noauto"
"x-systemd.automount"
"x-systemd.idle-timeout=1min"
];
};
swapDevices = [ ];
networking.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "aarch64-linux";
}
{ config, pkgs, nixos-raspberrypi, ... }:
let rpi-pkgs = nixos-raspberrypi.packages.aarch64-linux; in
{
# TODO: avoid duplication with the config on redthunder
users = {
groups = {
kodi.gid = 1588;
};
users.kodi = {
isNormalUser = true;
uid = 1588;
description = "Kodi";
group = "kodi";
extraGroups = [ "data" "video" "audio" "input" ];
};
};
systemd.services.kodi = let
package = rpi-pkgs.kodi-gbm.withPackages (kodiPkgs: [
kodiPkgs.inputstream-adaptive
kodiPkgs.sendtokodi
kodiPkgs.youtube
]);
in {
description = "Kodi media center";
wantedBy = ["multi-user.target"];
after = [
"network-online.target"
"sound.target"
"systemd-user-sessions.service"
];
wants = [
"network-online.target"
];
serviceConfig = {
Type = "simple";
User = "kodi";
ExecStart = "${package}/bin/kodi-standalone";
Restart = "always";
TimeoutStopSec = "15s";
TimeoutStopFailureMode = "kill";
};
};
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
};
hardware.graphics.enable = true;
}
{ config, pkgs, lib, nixos-raspberrypi, ... }:
{
imports = with nixos-raspberrypi.nixosModules; [
# Hardware configuration
raspberry-pi-4.base
raspberry-pi-4.display-vc4
raspberry-pi-4.bluetooth
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment