From e7826e06485939b7cadc1daf1ae4636287c18589 Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 11 Dec 2023 22:12:42 +0000 Subject: [PATCH] flake: add host outputs for nixpkgs-staging and nixpkgs-staging-next --- flake.lock | 34 ++++++++++++++++++++++++++++++++++ flake.nix | 31 ++++++++++++++++++++++++------- nixpatches/flake.nix | 7 ++++--- nixpatches/list.nix | 8 +++++--- 4 files changed, 67 insertions(+), 13 deletions(-) diff --git a/flake.lock b/flake.lock index 6c3f0f75..0647fcaf 100644 --- a/flake.lock +++ b/flake.lock @@ -51,6 +51,38 @@ "type": "github" } }, + "nixpkgs-staging-next-unpatched": { + "locked": { + "lastModified": 1702317658, + "narHash": "sha256-jYzBIMW18oQG+uQ9TVZwiYFHVafYIqllW+zFLROtwcE=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "f81605387c494a302c16901ac6459e877c45f913", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "staging-next", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-staging-unpatched": { + "locked": { + "lastModified": 1702311933, + "narHash": "sha256-bARcUNREf0wVSYzWhcK+mKCUgzeHbiKKDbpHBH92Mdk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "14b1b887952e70c12c6b8fc4ee9c1e22ec32faa6", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "staging", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs-unpatched": { "locked": { "lastModified": 1702272962, @@ -70,6 +102,8 @@ "root": { "inputs": { "mobile-nixos": "mobile-nixos", + "nixpkgs-staging-next-unpatched": "nixpkgs-staging-next-unpatched", + "nixpkgs-staging-unpatched": "nixpkgs-staging-unpatched", "nixpkgs-unpatched": "nixpkgs-unpatched", "sops-nix": "sops-nix", "uninsane-dot-org": "uninsane-dot-org" diff --git a/flake.nix b/flake.nix index 235896e5..3c457f7f 100644 --- a/flake.nix +++ b/flake.nix @@ -44,8 +44,8 @@ # # nixpkgs-unpatched.url = "github:nixos/nixpkgs?ref=nixos-unstable"; nixpkgs-unpatched.url = "github:nixos/nixpkgs?ref=master"; - # nixpkgs-unpatched.url = "github:nixos/nixpkgs?ref=staging-next"; - # nixpkgs-unpatched.url = "github:nixos/nixpkgs?ref=staging"; + nixpkgs-staging-next-unpatched.url = "github:nixos/nixpkgs?ref=staging-next"; + nixpkgs-staging-unpatched.url = "github:nixos/nixpkgs?ref=staging"; mobile-nixos = { # @@ -74,6 +74,8 @@ outputs = { self, nixpkgs-unpatched, + nixpkgs-staging-unpatched ? null, + nixpkgs-staging-next-unpatched ? null, mobile-nixos, sops-nix, uninsane-dot-org, @@ -83,6 +85,8 @@ inherit (builtins) attrNames elem listToAttrs map mapAttrs; # redefine some nixpkgs `lib` functions to avoid the infinite recursion # of if we tried to use patched `nixpkgs.lib` as part of the patching process. + mapAttrs' = f: set: + listToAttrs (map (attr: f attr set.${attr}) (attrNames set)); optionalAttrs = cond: attrs: if cond then attrs else {}; # mapAttrs but without the `name` argument mapAttrValues = f: mapAttrs (_: f); @@ -90,9 +94,9 @@ # rather than apply our nixpkgs patches as a flake input, do that here instead. # this (temporarily?) resolves the bad UX wherein a subflake residing in the same git # repo as the main flake causes the main flake to have an unstable hash. - nixpkgs = (import ./nixpatches/flake.nix).outputs { - self = nixpkgs; - nixpkgs = nixpkgs-unpatched; + patchNixpkgs = variant: nixpkgs: (import ./nixpatches/flake.nix).outputs { + inherit variant nixpkgs; + self = patchNixpkgs variant nixpkgs; } // { # provide values that nixpkgs ordinarily sources from the flake.lock file, # inaccessible to it here because of the import-from-derivation. @@ -108,9 +112,10 @@ inherit (self) shortRev; }; + nixpkgs = patchNixpkgs "master" nixpkgs-unpatched; nixpkgsCompiledBy = system: nixpkgs.legacyPackages."${system}"; - evalHost = { name, local, target, light ? false }: nixpkgs.lib.nixosSystem { + evalHost = { name, local, target, light ? false, nixpkgs ? nixpkgs }: nixpkgs.lib.nixosSystem { system = target; modules = [ { @@ -148,7 +153,19 @@ moby-light = { name = "moby"; local = "x86_64-linux"; target = "aarch64-linux"; light = true; }; rescue = { name = "rescue"; local = "x86_64-linux"; target = "x86_64-linux"; }; }; - in mapAttrValues evalHost hosts; + stagingHosts = mapAttrs' (h: v: { + name = "${h}-staging"; + value = v // { nixpkgs = patchNixpkgs "staging" nixpkgs-staging-unpatched; }; + }) hosts; + stagingNextHosts = mapAttrs' (h: v: { + name = "${h}-staging-next"; + value = v // { nixpkgs = patchNixpkgs "staging-next" nixpkgs-staging-next-unpatched; }; + }) hosts; + in mapAttrValues evalHost ( + hosts // + (optionalAttrs (nixpkgs-staging-unpatched != null) stagingHosts) // + (optionalAttrs (nixpkgs-staging-next-unpatched != null) stagingNextHosts) + ); # unofficial output # this produces a EFI-bootable .img file (GPT with a /boot partition and a system (/ or /nix) partition). diff --git a/nixpatches/flake.nix b/nixpatches/flake.nix index 12a117de..7d9270bf 100644 --- a/nixpatches/flake.nix +++ b/nixpatches/flake.nix @@ -3,15 +3,16 @@ # user is expected to define this from their flake via `inputs.nixpkgs.follows = ...` nixpkgs = {}; }; - outputs = { self, nixpkgs }@inputs: + outputs = { self, nixpkgs, variant ? "master" }@inputs: let patchedPkgsFor = system: nixpkgs.legacyPackages.${system}.applyPatches { name = "nixpkgs-patched-uninsane"; version = self.lastModifiedDate; src = nixpkgs; - patches = import ./list.nix { + patches = builtins.filter (p: p != null) (import ./list.nix { inherit (nixpkgs.legacyPackages.${system}) fetchpatch2 fetchurl; - }; + inherit variant; + }); }; patchedFlakeFor = system: import "${patchedPkgsFor system}/flake.nix"; patchedFlakeOutputsFor = system: diff --git a/nixpatches/list.nix b/nixpatches/list.nix index 1027e862..53fbc37f 100644 --- a/nixpatches/list.nix +++ b/nixpatches/list.nix @@ -1,4 +1,4 @@ -{ fetchpatch2, fetchurl }: +{ fetchpatch2, fetchurl, variant }: let fetchpatch' = { saneCommit ? null, @@ -7,6 +7,7 @@ let hash ? null, title ? null, revert ? false, + applies ? [ "unstable" "master" "staging" "staging-next" ], }: let url = if prUrl != null then @@ -17,11 +18,11 @@ let else "https://github.com/NixOS/nixpkgs/commit/${nixpkgsCommit}.patch" ; - in fetchpatch2 ( + in if (builtins.elem variant applies) then fetchpatch2 ( { inherit revert url; } // (if hash != null then { inherit hash; } else {}) // (if title != null then { name = title; } else {}) - ); + ) else null; in [ (fetchpatch' { title = "ripgrep: fix shell completions when cross compiling"; @@ -32,6 +33,7 @@ in [ title = "python3Packages.numpy: fix cross compilation"; prUrl = "https://github.com/NixOS/nixpkgs/pull/268587"; hash = "sha256-GRRLXwUw2JXEV6Ov0QiVTFwoi/ACManG2Qk7D3fzS8E="; + applies = [ "unstable" "master" ]; }) # (fetchpatch' { # title = "nixos/slskd: allow omitting username from yaml config";