From 81f28602aa9bda5328632660e0c8d51a18116e32 Mon Sep 17 00:00:00 2001 From: Cassie Cheung Date: Fri, 7 Feb 2025 11:48:15 +0800 Subject: [PATCH] flake: refactor packages to fit expectations --- .github/workflows/CI.yml | 20 +++++++++--------- flake.nix | 41 +++++++++++++++++++++--------------- nix/common.nix | 15 ++++++++++--- nix/pkgs/firmware-script.nix | 7 +++++- 4 files changed, 52 insertions(+), 31 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 8185f32..4950c7a 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -23,14 +23,14 @@ jobs: - name: Maximize build space uses: AdityaGarg8/remove-unwanted-software@master with: - remove-android: 'true' - remove-dotnet: 'true' - remove-haskell: 'true' - remove-codeql: 'true' - remove-docker-images: 'true' - remove-large-packages: 'true' - remove-cached-tools: 'true' - remove-swapfile: 'true' + remove-android: 'true' + remove-dotnet: 'true' + remove-haskell: 'true' + remove-codeql: 'true' + remove-docker-images: 'true' + remove-large-packages: 'true' + remove-cached-tools: 'true' + remove-swapfile: 'true' - name: Checkout uses: actions/checkout@v4 - name: "Install Nix" @@ -47,8 +47,8 @@ jobs: env: GC_DONT_GC: 1 run: | - for output in $(nix flake show --json | nix run nixpkgs#jq -- -r 'keys[]'); do - nix build .#$output --accept-flake-config + for output in $(nix flake show --json | nix run nixpkgs#jq -- -r '.packages."x86_64-linux" | keys[]'); do + nix build .#packages.x86_64-linux.${output} --accept-flake-config if [ $(du -B1M result/iso/*.iso | cut -f1) -gt 2000 ]; then split -d result/iso/*.iso -b 2000M nixos-$output.iso.part- else diff --git a/flake.nix b/flake.nix index 4861ca9..9008567 100644 --- a/flake.nix +++ b/flake.nix @@ -12,22 +12,29 @@ extra-trusted-public-keys = [ "cache.soopy.moe-1:0RZVsQeR+GOh0VQI9rvnHz55nVXkFardDqfm4+afjPo=" ]; }; - outputs = { self, nixpkgs, nixos-hardware }: - let - system = "x86_64-linux"; - inherit (nixpkgs) lib; + outputs = + { + self, + nixpkgs, + nixos-hardware, + }: + let + inherit (nixpkgs) lib; - mergeMap = fn: list: lib.lists.foldr (a: b: a // b) {} (map fn list); - in - mergeMap (config: { - ${lib.strings.removeSuffix ".nix" (builtins.baseNameOf config)} = (lib.nixosSystem { - inherit system; - - modules = [ config ]; - - specialArgs = { - inherit nixos-hardware; - }; - }).config.system.build.isoImage; - }) (builtins.filter (x: x != null) (lib.attrsets.mapAttrsToList (key: value: if value == "regular" && lib.strings.hasInfix "iso" key then ./nix/${key} else null) (builtins.readDir ./nix))); + system = "x86_64-linux"; + isos = [ + "gnome" + "minimal" + ]; + in + { + formatter.${system} = nixpkgs.legacyPackages.${system}.nixfmt-rfc-style; + packages.${system} = lib.genAttrs isos ( + iso: + (lib.nixosSystem { + modules = [ (self + "/nix/t2-iso-${iso}.nix") ]; + specialArgs = { inherit nixos-hardware; }; + }).config.system.build.isoImage + ); + }; } diff --git a/nix/common.nix b/nix/common.nix index f539b92..f2c78e1 100644 --- a/nix/common.nix +++ b/nix/common.nix @@ -1,4 +1,9 @@ -{ pkgs, modulesPath, nixos-hardware, ... }: +{ + pkgs, + modulesPath, + nixos-hardware, + ... +}: { imports = [ @@ -14,16 +19,20 @@ "t2linux.cachix.org-1:P733c5Gt1qTcxsm+Bae0renWnT8OLs0u9+yfaK2Bejw=" ]; - experimental-features = [ "nix-command" "flakes" ]; + experimental-features = [ + "nix-command" + "flakes" + ]; }; environment.systemPackages = with pkgs; [ git python3 dmg2img - (pkgs.callPackage ./pkgs/firmware-script.nix {}) + (pkgs.callPackage ./pkgs/firmware-script.nix { }) ]; # ZFS is (sometimes) broken and prevents building without this nixpkgs.config.allowBroken = true; + nixpkgs.hostPlatform = "x86_64-linux"; # t2 is x86_64-linux only } diff --git a/nix/pkgs/firmware-script.nix b/nix/pkgs/firmware-script.nix index 64a07b4..d3306eb 100644 --- a/nix/pkgs/firmware-script.nix +++ b/nix/pkgs/firmware-script.nix @@ -1,4 +1,9 @@ -{ stdenvNoCC, fetchurl, lib }: stdenvNoCC.mkDerivation (final: { +{ + stdenvNoCC, + fetchurl, + lib, +}: +stdenvNoCC.mkDerivation (final: { pname = "get-apple-firmware"; version = "fe8c338e6cf1238a390984ba06544833ab8792d3"; src = fetchurl {