first commit

This commit is contained in:
dump_stack() 2024-07-28 23:28:50 +00:00
commit c3a0fdac00
Signed by: dump_stack
GPG Key ID: C9905BA72B5E02BB
8 changed files with 325 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.img
*.img.xz

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Mikhail Klementev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

15
Makefile Normal file
View File

@ -0,0 +1,15 @@
COMMIT := $(shell git rev-parse --short HEAD)
IMAGE := nixos-thinkpad-t14s-gen6-$(COMMIT).img
TARGET := /dev/sdX
$(IMAGE).xz: $(IMAGE)
xz -k $(IMAGE)
$(IMAGE):
sudo ./scripts/make-image.sh $(IMAGE)
flash: $(IMAGE) $(TARGET)
sudo dd if=$(IMAGE) of=$(TARGET)
sudo parted -sf $(TARGET) p

56
configuration.nix Normal file
View File

@ -0,0 +1,56 @@
{ config, lib, options, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
./kernel.nix
];
hardware.firmware = [
pkgs.linux-firmware (pkgs.callPackage ./pkgs/t14s-firmware.nix { })
];
boot.loader.systemd-boot = {
enable = true;
extraFiles = {
"EFI/edk2-shell/shellx64.efi" = pkgs.edk2-uefi-shell.efi;
};
extraEntries = {
"edk2-shell.conf" = ''
title edk2-shell
efi /EFI/edk2-shell/shellx64.efi
'';
};
};
networking.networkmanager = {
enable = true;
plugins = lib.mkForce [];
};
environment.systemPackages = with pkgs; [
parted
cryptsetup
nixos-install-tools
git
vim
tmux
htop
usbutils
pciutils
acpi
openssl
];
services.getty.autologinUser = lib.mkDefault "root";
nixpkgs.config.allowUnfree = true;
nix.settings = {
experimental-features = "nix-command flakes";
};
}

View File

@ -0,0 +1,38 @@
# 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, ... }:
{
imports =
[ (modulesPath + "/installer/scan/not-detected.nix")
];
boot.initrd.availableKernelModules = [ "nvme" "usb_storage" ];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ ];
boot.extraModulePackages = [ ];
fileSystems."/" =
{ device = "/dev/disk/by-partlabel/i_t14sg6_nix";
fsType = "ext3";
autoResize = true;
};
fileSystems."/boot" =
{ device = "/dev/disk/by-partlabel/i_t14sg6_efi";
fsType = "vfat";
options = [ "fmask=0022" "dmask=0022" ];
};
swapDevices = [ ];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# (the default) this is the recommended approach. When using systemd-networkd it's
# still possible to use this option, but it's recommended to use it in conjunction
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
networking.useDHCP = lib.mkDefault true;
# networking.interfaces.wlP4p1s0.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "aarch64-linux";
}

131
kernel.nix Normal file
View File

@ -0,0 +1,131 @@
{ config, lib, pkgs, ... }:
let
inherit (config.boot.loader) efi;
linux_x1e_pkg = { buildLinux, ... } @ args:
buildLinux (args // rec {
version = "6.10.0";
modDirVersion = "6.10.0-next-20240725";
src = pkgs.fetchFromGitLab {
domain = "git.codelinaro.org";
owner = "abel.vesa";
repo = "linux";
rev = "x1e80100-20240725"; # "x1e80100-next";
hash = "sha256-0DFmPJEFl+cQT3Li4vuptBwavRc9CQOatd8TIYht+54=";
};
kernelPatches = (args.kernelPatches or [ ]);
extraMeta.branch = "6.10";
} // (args.argsOverride or { }));
linux_x1e = pkgs.callPackage linux_x1e_pkg { defconfig = "x1e_defconfig"; };
linuxPackages_x1e = pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor linux_x1e);
dtb = "${linuxPackages_x1e.kernel}/dtbs/qcom/x1e78100-lenovo-thinkpad-t14s.dtb";
dtbHash = builtins.hashFile "md5" dtb;
dtbName = "x1e80100-${dtbHash}.dtb";
in {
boot = {
kernelPackages = linuxPackages_x1e;
kernelParams = [
"dtb=${dtbName}"
#"initcall_debug"
#"earlycon=efifb"
"console=tty0"
#"ignore_loglevel"
#"keep_bootcon"
"regulator_ignore_unused"
"clk_ignore_unused"
"pd_ignore_unused"
"arm64.nopauth"
#"acpi=no"
"efi=novamap"
#"efi=noruntime"
"pcie_aspm.policy=powersupersave"
"iommu.strict=0"
"iommu.passthrough=0"
#"earlyprintk=xdbc"
#"usbcore.autosuspend=-1"
"module_blacklist=edac_core,qcom_q6v5_pas"
];
supportedFilesystems.zfs = false;
initrd = {
includeDefaultModules = false;
availableKernelModules = [
"nvme"
"uas"
"usb-storage"
"gpio-sbu-mux"
"leds-qcom-lpg"
"msm"
"panel-edp"
"pmic-glink-altmode"
"pwm-bl"
"qrtr"
"i2c-core"
"i2c-hid"
"i2c-hid-of"
"i2c-qcom-geni"
"phy-qcom-edp"
"phy-qcom-eusb2-repeater"
"phy-qcom-qmp-combo"
"phy-qcom-qmp-pcie"
"phy-qcom-qmp-usb"
"phy-qcom-snps-eusb2"
"phy-qcom-snps-femto-v2"
"phy-qcom-usb-hs"
"dispcc-x1e80100"
"gpucc-x1e80100"
"tcsrcc-x1e80100"
# fat32
"vfat" "nls-cp437" "nls-iso8859-1"
];
systemd = {
enable = true;
enableTpm2 = false;
};
};
loader = {
systemd-boot.enable = lib.mkForce true;
efi.canTouchEfiVariables = false;
systemd-boot.extraFiles = {
"${dtbName}" = dtb;
};
};
};
system.activationScripts.t14s-gen6-dtb = ''
in_package="${dtb}"
esp_tool_folder="${efi.efiSysMountPoint}/"
in_esp="''${esp_tool_folder}${dtbName}"
in_esp_backup="''${esp_tool_folder}/dtb/${dtbName}"
in_esp_backup_dir="''${esp_tool_folder}/dtb/"
mkdir -p "$in_esp_backup_dir"
cp "$in_package" "$in_esp_backup"
>&2 echo "Ensuring $in_esp in EFI System Partition"
if ! ${pkgs.diffutils}/bin/cmp --silent "$in_package" "$in_esp"; then
>&2 echo "Copying $in_package -> $in_esp"
mkdir -p "$esp_tool_folder"
cp "$in_package" "$in_esp"
sync
fi
'';
}

33
pkgs/t14s-firmware.nix Normal file
View File

@ -0,0 +1,33 @@
{ stdenvNoCC
, lib
, rdfind
, which
, fetchFromGitHub
}:
stdenvNoCC.mkDerivation rec {
pname = "linux-firmware";
version = "20240726";
src = fetchFromGitHub {
owner = "jollheef";
repo = "linux-firmware-x1e78100-lenovo-thinkpad-t14s";
rev = "4ba0b781ffc27cb48736942822192b548a316838";
hash = "sha256-ZeV6JRxU1gMwtWZH8sePCrZXFa27GxoKpLK4sg3Ljyo=";
};
installPhase = ''
runHook preInstall
mkdir -p $out/lib/firmware
cp -r * $out/lib/firmware/
runHook postInstall
'';
dontStrip = true;
meta = with lib; {
description = "Firmware files for ThinkPad T14s Gen 6";
license = licenses.unfreeRedistributableFirmware;
platforms = platforms.linux;
};
}

29
scripts/make-image.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh -eux
file=$1
efi_part_label=i_t14sg6_efi
nix_part_label=i_t14sg6_nix
boot_size=256M
fallocate -l4G ${file}
parted ${file} mklabel gpt
parted ${file} mkpart ${efi_part_label} fat32 0% ${boot_size}
parted ${file} set 1 esp on
parted ${file} mkpart ${nix_part_label} ext3 ${boot_size} 100%
drive=$(losetup -P -f --show ${file})
mkfs.vfat -F32 ${drive}p1
mkfs.ext3 ${drive}p2
mount ${drive}p2 /mnt
mkdir /mnt/boot
mount ${drive}p1 /mnt/boot
mkdir -p /mnt/etc/nixos
cp -r pkgs *.nix /mnt/etc/nixos/
nixos-install --root /mnt --no-root-password
umount -R /mnt
losetup -D