Lint files

This commit is contained in:
Michael Smith 2024-09-08 22:47:16 +02:00
parent d9c430135f
commit 10dc188e83
3 changed files with 77 additions and 63 deletions

View File

@ -203,9 +203,9 @@
services.flatpak.enable = true; services.flatpak.enable = true;
systemd.services.ensure-flathub-remote = { systemd.services.ensure-flathub-remote = {
description = "Ensure Flathub is added as a flatpak remote repository"; description = "Ensure Flathub is added as a flatpak remote repository";
wantedBy = [ "multi-user.target" ]; wantedBy = ["multi-user.target"];
wants = [ "network-online.target" ]; wants = ["network-online.target"];
after = [ "network-online.target" ]; after = ["network-online.target"];
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
User = "root"; User = "root";

View File

@ -42,8 +42,8 @@ in {
# See https://nixos.org/manual/nixos/stable/#sec-building-image-drivers # See https://nixos.org/manual/nixos/stable/#sec-building-image-drivers
# FIXME(m): See if this can be cleaned up and go somewhere else and # FIXME(m): See if this can be cleaned up and go somewhere else and
# ensure this doesn't break non-Apple hardware. # ensure this doesn't break non-Apple hardware.
initrd.kernelModules = [ "wl" ]; initrd.kernelModules = ["wl"];
kernelModules = [ "kvm-intel" "wl" ]; kernelModules = ["kvm-intel" "wl"];
extraModulePackages = [config.boot.kernelPackages.broadcom_sta]; extraModulePackages = [config.boot.kernelPackages.broadcom_sta];
}; };

View File

@ -1,8 +1,10 @@
{ config, lib, pkgs, ... }: {
config,
with lib; lib,
pkgs,
let ...
}:
with lib; let
cfg = config.boot.loader.systemd-boot; cfg = config.boot.loader.systemd-boot;
efi = config.boot.loader.efi; efi = config.boot.loader.efi;
@ -10,16 +12,17 @@ let
# We check the source code in a derivation that does not depend on the # We check the source code in a derivation that does not depend on the
# system configuration so that most users don't have to redo the check and require # system configuration so that most users don't have to redo the check and require
# the necessary dependencies. # the necessary dependencies.
checkedSource = pkgs.runCommand "systemd-boot" { checkedSource =
preferLocalBuild = true; pkgs.runCommand "systemd-boot" {
} '' preferLocalBuild = true;
install -m755 -D ${./systemd-boot-builder.py} $out } ''
${lib.getExe pkgs.buildPackages.mypy} \ install -m755 -D ${./systemd-boot-builder.py} $out
--no-implicit-optional \ ${lib.getExe pkgs.buildPackages.mypy} \
--disallow-untyped-calls \ --no-implicit-optional \
--disallow-untyped-defs \ --disallow-untyped-calls \
$out --disallow-untyped-defs \
''; $out
'';
systemdBootBuilder = pkgs.substituteAll rec { systemdBootBuilder = pkgs.substituteAll rec {
name = "systemd-boot"; name = "systemd-boot";
@ -36,15 +39,22 @@ let
nix = config.nix.package.out; nix = config.nix.package.out;
timeout = if config.boot.loader.timeout == null then "menu-force" else config.boot.loader.timeout; timeout =
if config.boot.loader.timeout == null
then "menu-force"
else config.boot.loader.timeout;
configurationLimit = if cfg.configurationLimit == null then 0 else cfg.configurationLimit; configurationLimit =
if cfg.configurationLimit == null
then 0
else cfg.configurationLimit;
inherit (cfg) consoleMode graceful editor rebootForBitlocker; inherit (cfg) consoleMode graceful editor rebootForBitlocker;
inherit (efi) efiSysMountPoint canTouchEfiVariables; inherit (efi) efiSysMountPoint canTouchEfiVariables;
bootMountPoint = if cfg.xbootldrMountPoint != null bootMountPoint =
if cfg.xbootldrMountPoint != null
then cfg.xbootldrMountPoint then cfg.xbootldrMountPoint
else efi.efiSysMountPoint; else efi.efiSysMountPoint;
@ -71,14 +81,16 @@ let
empty_file=$(${pkgs.coreutils}/bin/mktemp) empty_file=$(${pkgs.coreutils}/bin/mktemp)
${concatStrings (mapAttrsToList (n: v: '' ${concatStrings (mapAttrsToList (n: v: ''
${pkgs.coreutils}/bin/install -Dp "${v}" "${bootMountPoint}/"${escapeShellArg n} ${pkgs.coreutils}/bin/install -Dp "${v}" "${bootMountPoint}/"${escapeShellArg n}
${pkgs.coreutils}/bin/install -D $empty_file "${bootMountPoint}/${nixosDir}/.extra-files/"${escapeShellArg n} ${pkgs.coreutils}/bin/install -D $empty_file "${bootMountPoint}/${nixosDir}/.extra-files/"${escapeShellArg n}
'') cfg.extraFiles)} '')
cfg.extraFiles)}
${concatStrings (mapAttrsToList (n: v: '' ${concatStrings (mapAttrsToList (n: v: ''
${pkgs.coreutils}/bin/install -Dp "${pkgs.writeText n v}" "${bootMountPoint}/loader/entries/"${escapeShellArg n} ${pkgs.coreutils}/bin/install -Dp "${pkgs.writeText n v}" "${bootMountPoint}/loader/entries/"${escapeShellArg n}
${pkgs.coreutils}/bin/install -D $empty_file "${bootMountPoint}/${nixosDir}/.extra-files/loader/entries/"${escapeShellArg n} ${pkgs.coreutils}/bin/install -D $empty_file "${bootMountPoint}/${nixosDir}/.extra-files/loader/entries/"${escapeShellArg n}
'') cfg.extraEntries)} '')
cfg.extraEntries)}
''; '';
}; };
@ -90,8 +102,8 @@ let
in { in {
# NOTE(m): This module overrides the default NixOS systemd-boot module to include # NOTE(m): This module overrides the default NixOS systemd-boot module to include
# a custom systemd-boot-builder.py script that generates more user friendly bootloader entries # a custom systemd-boot-builder.py script that generates more user friendly bootloader entries
disabledModules = [ "system/boot/loader/systemd-boot/systemd-boot.nix" ]; disabledModules = ["system/boot/loader/systemd-boot/systemd-boot.nix"];
meta.maintainers = with lib.maintainers; [ michaelshmitty ]; meta.maintainers = with lib.maintainers; [michaelshmitty];
options.boot.loader.systemd-boot = { options.boot.loader.systemd-boot = {
enable = mkOption { enable = mkOption {
@ -202,7 +214,7 @@ in {
consoleMode = mkOption { consoleMode = mkOption {
default = "keep"; default = "keep";
type = types.enum [ "0" "1" "2" "auto" "max" "keep" ]; type = types.enum ["0" "1" "2" "auto" "max" "keep"];
description = '' description = ''
The resolution of the console. The following values are valid: The resolution of the console. The following values are valid:
@ -335,37 +347,39 @@ in {
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
assertions = [ assertions =
{ [
assertion = (hasPrefix "/" efi.efiSysMountPoint); {
message = "The ESP mount point '${toString efi.efiSysMountPoint}' must be an absolute path"; assertion = hasPrefix "/" efi.efiSysMountPoint;
} message = "The ESP mount point '${toString efi.efiSysMountPoint}' must be an absolute path";
{ }
assertion = cfg.xbootldrMountPoint == null || (hasPrefix "/" cfg.xbootldrMountPoint); {
message = "The XBOOTLDR mount point '${toString cfg.xbootldrMountPoint}' must be an absolute path"; assertion = cfg.xbootldrMountPoint == null || (hasPrefix "/" cfg.xbootldrMountPoint);
} message = "The XBOOTLDR mount point '${toString cfg.xbootldrMountPoint}' must be an absolute path";
{ }
assertion = cfg.xbootldrMountPoint != efi.efiSysMountPoint; {
message = "The XBOOTLDR mount point '${toString cfg.xbootldrMountPoint}' cannot be the same as the ESP mount point '${toString efi.efiSysMountPoint}'"; assertion = cfg.xbootldrMountPoint != efi.efiSysMountPoint;
} message = "The XBOOTLDR mount point '${toString cfg.xbootldrMountPoint}' cannot be the same as the ESP mount point '${toString efi.efiSysMountPoint}'";
{ }
assertion = (config.boot.kernelPackages.kernel.features or { efiBootStub = true; }) ? efiBootStub; {
message = "This kernel does not support the EFI boot stub"; assertion = (config.boot.kernelPackages.kernel.features or {efiBootStub = true;}) ? efiBootStub;
} message = "This kernel does not support the EFI boot stub";
{ }
assertion = cfg.installDeviceTree -> config.hardware.deviceTree.enable -> config.hardware.deviceTree.name != null; {
message = "Cannot install devicetree without 'config.hardware.deviceTree.enable' enabled and 'config.hardware.deviceTree.name' set"; assertion = cfg.installDeviceTree -> config.hardware.deviceTree.enable -> config.hardware.deviceTree.name != null;
} message = "Cannot install devicetree without 'config.hardware.deviceTree.enable' enabled and 'config.hardware.deviceTree.name' set";
] ++ concatMap (filename: [ }
{ ]
assertion = !(hasInfix "/" filename); ++ concatMap (filename: [
message = "boot.loader.systemd-boot.extraEntries.${lib.strings.escapeNixIdentifier filename} is invalid: entries within folders are not supported"; {
} assertion = !(hasInfix "/" filename);
{ message = "boot.loader.systemd-boot.extraEntries.${lib.strings.escapeNixIdentifier filename} is invalid: entries within folders are not supported";
assertion = hasSuffix ".conf" filename; }
message = "boot.loader.systemd-boot.extraEntries.${lib.strings.escapeNixIdentifier filename} is invalid: entries must have a .conf file extension"; {
} assertion = hasSuffix ".conf" filename;
]) (builtins.attrNames cfg.extraEntries) message = "boot.loader.systemd-boot.extraEntries.${lib.strings.escapeNixIdentifier filename} is invalid: entries must have a .conf file extension";
}
]) (builtins.attrNames cfg.extraEntries)
++ concatMap (filename: [ ++ concatMap (filename: [
{ {
assertion = !(hasPrefix "/" filename); assertion = !(hasPrefix "/" filename);