From 350fd669eb1b1dd5033d79d9ea29f22c0ead0bac Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Sat, 6 Sep 2025 06:27:36 -0700 Subject: [PATCH] Add hydra jobs & flake packages --- default.nix | 6 +- flake.lock | 21 +++++- flake.nix | 19 +++++- jobs.nix | 6 ++ microsoft/surface/common/default.nix | 79 +-------------------- microsoft/surface/pkgs/all.nix | 12 ++++ microsoft/surface/pkgs/default.nix | 10 +++ microsoft/surface/pkgs/jobs.nix | 8 +++ microsoft/surface/pkgs/kernel/default.nix | 83 +++++++++++++++++++++++ toplevel.nix | 20 ++++++ 10 files changed, 184 insertions(+), 80 deletions(-) create mode 100644 jobs.nix create mode 100644 microsoft/surface/pkgs/all.nix create mode 100644 microsoft/surface/pkgs/default.nix create mode 100644 microsoft/surface/pkgs/jobs.nix create mode 100644 microsoft/surface/pkgs/kernel/default.nix create mode 100644 toplevel.nix diff --git a/default.nix b/default.nix index c73bd5ad2..b653300fd 100644 --- a/default.nix +++ b/default.nix @@ -1,3 +1,7 @@ # This file is necessary so nix-env -qa does not break, # when nixos-hardware is used as a channel -{ } +{ pkgs }: +import ./toplevel.nix { + fn = p: pkgs.callPackages "${builtins.toString p}/all.nix"; + inherit (pkgs) lib; +} diff --git a/flake.lock b/flake.lock index 5999137c9..2fbb720a7 100644 --- a/flake.lock +++ b/flake.lock @@ -1,6 +1,25 @@ { "nodes": { - "root": {} + "nixpkgs": { + "locked": { + "lastModified": 1757163567, + "narHash": "sha256-uKMQbZmAr6R2tQ/4YpON6ZR00Z0alKeJdAyMHR8n47U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "413fda74348e993e19c01f9bb23f933abcb071bf", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } }, "root": "root", "version": 7 diff --git a/flake.nix b/flake.nix index 7cfe53df3..f505204ed 100644 --- a/flake.nix +++ b/flake.nix @@ -1,10 +1,27 @@ { description = "nixos-hardware"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs"; + outputs = - { ... }: + { nixpkgs, ... }: + let + inherit (nixpkgs.lib) + genAttrs + ; + + eachSystem = genAttrs [ + "aarch64-linux" + "x86_64-linux" + "riscv64-linux" + ]; + in { + hydraJobs = import ./jobs.nix nixpkgs; + + packages = eachSystem (system: import ./. { pkgs = nixpkgs.legacyPackages.${system}; }); + nixosModules = let deprecated = diff --git a/jobs.nix b/jobs.nix new file mode 100644 index 000000000..7517f48ac --- /dev/null +++ b/jobs.nix @@ -0,0 +1,6 @@ +nixpkgs: +import ./toplevel.nix { + fn = p: import "${builtins.toString p}/jobs.nix"; + args = nixpkgs; + inherit (nixpkgs) lib; +} diff --git a/microsoft/surface/common/default.nix b/microsoft/surface/common/default.nix index 1fe46fee5..4f18dcc06 100644 --- a/microsoft/surface/common/default.nix +++ b/microsoft/surface/common/default.nix @@ -10,85 +10,10 @@ let mkDefault mkOption types - versions ; - # Set the version and hash for the kernel sources - srcVersion = - with config.hardware.microsoft-surface; - if kernelVersion == "longterm" then - "6.12.19" - else if kernelVersion == "stable" then - "6.15.9" - else - abort "Invalid kernel version: ${kernelVersion}"; - - srcHash = - with config.hardware.microsoft-surface; - if kernelVersion == "longterm" then - "sha256-1zvwV77ARDSxadG2FkGTb30Ml865I6KB8y413U3MZTE=" - else if kernelVersion == "stable" then - "sha256-6U86+FSSMC96gZRBRY+AvKCtmRLlpMg8aZ/zxjxSlX0=" - else - abort "Invalid kernel version: ${kernelVersion}"; - - # Set the version and hash for the linux-surface releases - pkgVersion = - with config.hardware.microsoft-surface; - if kernelVersion == "longterm" then - "6.12.7" - else if kernelVersion == "stable" then - "6.15.3" - else - abort "Invalid kernel version: ${kernelVersion}"; - - pkgHash = - with config.hardware.microsoft-surface; - if kernelVersion == "longterm" then - "sha256-Pv7O8D8ma+MPLhYP3HSGQki+Yczp8b7d63qMb6l4+mY=" - else if kernelVersion == "stable" then - "sha256-ozvYrZDiVtMkdCcVnNEdlF2Kdw4jivW0aMJrDynN3Hk=" - else - abort "Invalid kernel version: ${kernelVersion}"; - - # Fetch the linux-surface package - repos = - pkgs.callPackage - ( - { - fetchFromGitHub, - rev, - hash, - }: - { - linux-surface = fetchFromGitHub { - owner = "linux-surface"; - repo = "linux-surface"; - rev = rev; - hash = hash; - }; - } - ) - { - hash = pkgHash; - rev = "arch-${pkgVersion}-1"; - }; - - # Fetch and build the kernel package - inherit (pkgs.callPackage ./kernel/linux-package.nix { inherit repos; }) - linuxPackage - surfacePatches - ; - kernelPatches = surfacePatches { - version = pkgVersion; - patchFn = ./kernel/${versions.majorMinor pkgVersion}/patches.nix; - patchSrc = (repos.linux-surface + "/patches/${versions.majorMinor pkgVersion}"); - }; - kernelPackages = linuxPackage { - inherit kernelPatches; - version = srcVersion; - sha256 = srcHash; - ignoreConfigErrors = true; + kernelPackages = pkgs.callPackage ../pkgs/kernel { + inherit (config.hardware.microsoft-surface) kernelVersion; }; in diff --git a/microsoft/surface/pkgs/all.nix b/microsoft/surface/pkgs/all.nix new file mode 100644 index 000000000..b436c1460 --- /dev/null +++ b/microsoft/surface/pkgs/all.nix @@ -0,0 +1,12 @@ +{ + lib, + stdenv, + callPackages, +}: +let + pkgs = callPackages ./. { }; +in +lib.optionalAttrs (stdenv.hostPlatform.isx86_64) { + kernel-stable = pkgs.kernel-stable.kernel; + kernel-longterm = pkgs.kernel-longterm.kernel; +} diff --git a/microsoft/surface/pkgs/default.nix b/microsoft/surface/pkgs/default.nix new file mode 100644 index 000000000..cf60f2778 --- /dev/null +++ b/microsoft/surface/pkgs/default.nix @@ -0,0 +1,10 @@ +{ callPackage }: +{ + kernel-stable = callPackage ./kernel { + kernelVersion = "stable"; + }; + + kernel-longterm = callPackage ./kernel { + kernelVersion = "longterm"; + }; +} diff --git a/microsoft/surface/pkgs/jobs.nix b/microsoft/surface/pkgs/jobs.nix new file mode 100644 index 000000000..e9bd77c5d --- /dev/null +++ b/microsoft/surface/pkgs/jobs.nix @@ -0,0 +1,8 @@ +nixpkgs: +let + pkgs = nixpkgs.legacyPackages.x86_64-linux.callPackages ./. { }; +in +{ + kernel-stable.x86_64-linux = nixpkgs.lib.hydraJob pkgs.kernel-stable.kernel; + kernel-longterm.x86_64-linux = nixpkgs.lib.hydraJob pkgs.kernel-longterm.kernel; +} diff --git a/microsoft/surface/pkgs/kernel/default.nix b/microsoft/surface/pkgs/kernel/default.nix new file mode 100644 index 000000000..3f189b232 --- /dev/null +++ b/microsoft/surface/pkgs/kernel/default.nix @@ -0,0 +1,83 @@ +{ + lib, + kernelVersion, + callPackage, +}: +let + inherit (lib) versions; + + # Set the version and hash for the kernel sources + srcVersion = + if kernelVersion == "longterm" then + "6.12.19" + else if kernelVersion == "stable" then + "6.15.9" + else + abort "Invalid kernel version: ${kernelVersion}"; + + srcHash = + if kernelVersion == "longterm" then + "sha256-1zvwV77ARDSxadG2FkGTb30Ml865I6KB8y413U3MZTE=" + else if kernelVersion == "stable" then + "sha256-6U86+FSSMC96gZRBRY+AvKCtmRLlpMg8aZ/zxjxSlX0=" + else + abort "Invalid kernel version: ${kernelVersion}"; + + # Set the version and hash for the linux-surface releases + pkgVersion = + if kernelVersion == "longterm" then + "6.12.7" + else if kernelVersion == "stable" then + "6.15.3" + else + abort "Invalid kernel version: ${kernelVersion}"; + + pkgHash = + if kernelVersion == "longterm" then + "sha256-Pv7O8D8ma+MPLhYP3HSGQki+Yczp8b7d63qMb6l4+mY=" + else if kernelVersion == "stable" then + "sha256-ozvYrZDiVtMkdCcVnNEdlF2Kdw4jivW0aMJrDynN3Hk=" + else + abort "Invalid kernel version: ${kernelVersion}"; + + # Fetch the linux-surface package + repos = + callPackage + ( + { + fetchFromGitHub, + rev, + hash, + }: + { + linux-surface = fetchFromGitHub { + owner = "linux-surface"; + repo = "linux-surface"; + rev = rev; + hash = hash; + }; + } + ) + { + hash = pkgHash; + rev = "arch-${pkgVersion}-1"; + }; + + # Fetch and build the kernel package + inherit (callPackage ../../common/kernel/linux-package.nix { inherit repos; }) + linuxPackage + surfacePatches + ; + + kernelPatches = surfacePatches { + version = pkgVersion; + patchFn = ../../common/kernel/${versions.majorMinor pkgVersion}/patches.nix; + patchSrc = (repos.linux-surface + "/patches/${versions.majorMinor pkgVersion}"); + }; +in +linuxPackage { + inherit kernelPatches; + version = srcVersion; + sha256 = srcHash; + ignoreConfigErrors = true; +} diff --git a/toplevel.nix b/toplevel.nix new file mode 100644 index 000000000..f2f2bc105 --- /dev/null +++ b/toplevel.nix @@ -0,0 +1,20 @@ +{ + lib, + fn ? p: import p, + args ? { }, +}: +let + pkgs = builtins.mapAttrs (_name: p: fn p args) { + microsoft-surface = ./microsoft/surface/pkgs; + }; +in +lib.foldAttrs (item: acc: item // acc) { } ( + lib.flatten ( + lib.attrValues ( + lib.mapAttrs ( + toplevelName: jobs: + lib.listToAttrs (lib.mapAttrsToList (name: lib.nameValuePair "${toplevelName}/${name}") jobs) + ) pkgs + ) + ) +)