From c304d018202d84b91f2b0a838e40c117bd0030e6 Mon Sep 17 00:00:00 2001 From: tross Date: Fri, 13 Jan 2023 11:10:55 -0800 Subject: [PATCH 1/4] pkgs: make lib overridable --- pkgs/top-level/default.nix | 5 +++-- pkgs/top-level/impure.nix | 1 + pkgs/top-level/release-lib.nix | 7 ++----- pkgs/top-level/release-small.nix | 5 +++-- pkgs/top-level/release.nix | 5 +++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix index b32aabc3a1fdf..fd427809eb4af 100644 --- a/pkgs/top-level/default.nix +++ b/pkgs/top-level/default.nix @@ -38,6 +38,9 @@ # list it returns. stdenvStages ? import ../stdenv +, # Library functions for Nixpkgs + lib ? import ../../lib + , # Ignore unexpected args. ... } @ args: @@ -47,8 +50,6 @@ let # Rename the function arguments crossSystem0 = crossSystem; in let - lib = import ../../lib; - inherit (lib) throwIfNot; checked = diff --git a/pkgs/top-level/impure.nix b/pkgs/top-level/impure.nix index 4d847e280f4b9..065d785b3f7c8 100644 --- a/pkgs/top-level/impure.nix +++ b/pkgs/top-level/impure.nix @@ -75,6 +75,7 @@ in else [] , crossOverlays ? [] +, lib ? import ../../lib , ... } @ args: diff --git a/pkgs/top-level/release-lib.nix b/pkgs/top-level/release-lib.nix index 38e6f8072776c..e6f1a7912f413 100644 --- a/pkgs/top-level/release-lib.nix +++ b/pkgs/top-level/release-lib.nix @@ -1,14 +1,11 @@ { supportedSystems +, lib ? import ../../lib , packageSet ? (import ../..) , scrubJobs ? true , # Attributes passed to nixpkgs. Don't build packages marked as unfree. nixpkgsArgs ? { config = { allowUnfree = false; inHydra = true; }; } }: - -let - lib = import ../../lib; -in with lib; - +with lib; rec { pkgs = packageSet (lib.recursiveUpdate { system = "x86_64-linux"; config.allowUnsupportedSystem = true; } nixpkgsArgs); diff --git a/pkgs/top-level/release-small.nix b/pkgs/top-level/release-small.nix index 7bf4a234bb657..a2c401044c2d6 100644 --- a/pkgs/top-level/release-small.nix +++ b/pkgs/top-level/release-small.nix @@ -1,13 +1,14 @@ /* A small release file, with few packages to be built. The aim is to reduce the load on Hydra when testing the `stdenv-updates' branch. */ -{ nixpkgs ? { outPath = (import ../../lib).cleanSource ../..; revCount = 1234; shortRev = "abcdef"; } +{ lib ? import ../../lib +, nixpkgs ? { outPath = lib.cleanSource ../..; revCount = 1234; shortRev = "abcdef"; } , supportedSystems ? [ "x86_64-linux" "x86_64-darwin" ] , # Attributes passed to nixpkgs. Don't build packages marked as unfree. nixpkgsArgs ? { config = { allowUnfree = false; inHydra = true; }; } }: -with import ./release-lib.nix { inherit supportedSystems nixpkgsArgs; }; +with import ./release-lib.nix { inherit supportedSystems nixpkgsArgs lib; }; { diff --git a/pkgs/top-level/release.nix b/pkgs/top-level/release.nix index 374a308ac1417..aaa7afe55c443 100644 --- a/pkgs/top-level/release.nix +++ b/pkgs/top-level/release.nix @@ -8,7 +8,8 @@ $ nix-build pkgs/top-level/release.nix -A coreutils.x86_64-linux */ -{ nixpkgs ? { outPath = (import ../../lib).cleanSource ../..; revCount = 1234; shortRev = "abcdef"; revision = "0000000000000000000000000000000000000000"; } +{ lib ? import ../../lib +, nixpkgs ? { outPath = lib.cleanSource ../..; revCount = 1234; shortRev = "abcdef"; revision = "0000000000000000000000000000000000000000"; } , officialRelease ? false # The platforms for which we build Nixpkgs. , supportedSystems ? [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" ] @@ -19,7 +20,7 @@ , nixpkgsArgs ? { config = { allowUnfree = false; inHydra = true; }; } }: -with import ./release-lib.nix { inherit supportedSystems scrubJobs nixpkgsArgs; }; +with import ./release-lib.nix { inherit supportedSystems scrubJobs nixpkgsArgs lib; }; let From 46e9c62c5f2c170266897999d7605e8a22e8ad4d Mon Sep 17 00:00:00 2001 From: tross Date: Fri, 13 Jan 2023 11:11:07 -0800 Subject: [PATCH 2/4] nixos: make lib overridable --- nixos/release-small.nix | 2 +- nixos/release.nix | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nixos/release-small.nix b/nixos/release-small.nix index deb428d1bec05..edd8a94b22214 100644 --- a/nixos/release-small.nix +++ b/nixos/release-small.nix @@ -21,7 +21,7 @@ let }; nixpkgs' = builtins.removeAttrs (import ../pkgs/top-level/release.nix { - inherit supportedSystems; + inherit supportedSystems lib; nixpkgs = nixpkgsSrc; }) [ "unstable" ]; diff --git a/nixos/release.nix b/nixos/release.nix index 946379bcd6611..175e756895a52 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -1,12 +1,12 @@ -with import ../lib; - -{ nixpkgs ? { outPath = cleanSource ./..; revCount = 130979; shortRev = "gfedcba"; } +{ lib ? import ../lib +, nixpkgs ? { outPath = lib.cleanSource ./..; revCount = 130979; shortRev = "gfedcba"; } , stableBranch ? false , supportedSystems ? [ "x86_64-linux" "aarch64-linux" ] , configuration ? {} }: -with import ../pkgs/top-level/release-lib.nix { inherit supportedSystems; }; +with lib; +with import ../pkgs/top-level/release-lib.nix { inherit supportedSystems lib; }; let From 4e4f9e66cfd6b0983152fce9fe2aedf55b322129 Mon Sep 17 00:00:00 2001 From: tross Date: Fri, 13 Jan 2023 11:11:19 -0800 Subject: [PATCH 3/4] flake: pass lib --- flake.nix | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/flake.nix b/flake.nix index f9442d8ea2d2c..ba57c9c62e55c 100644 --- a/flake.nix +++ b/flake.nix @@ -5,17 +5,7 @@ outputs = { self }: let - jobs = import ./pkgs/top-level/release.nix { - nixpkgs = self; - }; - - lib = import ./lib; - - forAllSystems = lib.genAttrs lib.systems.flakeExposed; - in - { - lib = lib.extend (final: prev: { - + lib = (import ./lib).extend (final: prev: { nixos = import ./nixos/lib { lib = final; }; nixosSystem = args: @@ -35,6 +25,16 @@ ); }); + jobs = import ./pkgs/top-level/release.nix { + inherit lib; + nixpkgs = self; + }; + + forAllSystems = lib.genAttrs lib.systems.flakeExposed; + in + { + inherit lib; + checks.x86_64-linux.tarball = jobs.tarball; htmlDocs = { From 0bfcf8510192974ea0a3ff2a6b34ff4ceb0342cf Mon Sep 17 00:00:00 2001 From: tross Date: Fri, 13 Jan 2023 11:44:20 -0800 Subject: [PATCH 4/4] nixos: pass lib from args --- flake.nix | 1 + nixos/lib/testing-python.nix | 3 ++- nixos/release-combined.nix | 11 +++++++---- nixos/release-small.nix | 12 +++++++----- nixos/release.nix | 4 ++-- nixos/tests/all-tests.nix | 1 + 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/flake.nix b/flake.nix index ba57c9c62e55c..5afd333c92fec 100644 --- a/flake.nix +++ b/flake.nix @@ -11,6 +11,7 @@ nixosSystem = args: import ./nixos/lib/eval-config.nix ( args // { + lib = args.lib or final; modules = args.modules ++ [{ system.nixos.versionSuffix = ".${final.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}.${self.shortRev or "dirty"}"; diff --git a/nixos/lib/testing-python.nix b/nixos/lib/testing-python.nix index 4904ad6e35913..2ea57c203edbf 100644 --- a/nixos/lib/testing-python.nix +++ b/nixos/lib/testing-python.nix @@ -1,6 +1,7 @@ args@ { system -, pkgs ? import ../.. { inherit system config; } +, lib ? import ../../lib +, pkgs ? import ../.. { inherit system config lib; } # Use a minimal kernel? , minimal ? false # Ignored diff --git a/nixos/release-combined.nix b/nixos/release-combined.nix index 337b5192776f8..6374dd2c1d995 100644 --- a/nixos/release-combined.nix +++ b/nixos/release-combined.nix @@ -2,7 +2,8 @@ # and nixos-14.04). The channel is updated every time the ‘tested’ job # succeeds, and all other jobs have finished (they may fail). -{ nixpkgs ? { outPath = (import ../lib).cleanSource ./..; revCount = 56789; shortRev = "gfedcba"; } +{ lib ? import ../lib +, nixpkgs ? { outPath = lib.cleanSource ./..; revCount = 56789; shortRev = "gfedcba"; } , stableBranch ? false , supportedSystems ? [ "aarch64-linux" "x86_64-linux" ] , limitedSupportedSystems ? [ "i686-linux" ] @@ -12,7 +13,9 @@ let nixpkgsSrc = nixpkgs; # urgh - pkgs = import ./.. {}; + pkgs = import ./.. { + inherit lib; + }; removeMaintainers = set: if builtins.isAttrs set then if (set.type or "") == "derivation" @@ -23,13 +26,13 @@ let in rec { nixos = removeMaintainers (import ./release.nix { - inherit stableBranch; + inherit stableBranch lib; supportedSystems = supportedSystems ++ limitedSupportedSystems; nixpkgs = nixpkgsSrc; }); nixpkgs = builtins.removeAttrs (removeMaintainers (import ../pkgs/top-level/release.nix { - inherit supportedSystems; + inherit supportedSystems lib; nixpkgs = nixpkgsSrc; })) [ "unstable" ]; diff --git a/nixos/release-small.nix b/nixos/release-small.nix index edd8a94b22214..3e9100e57a6d0 100644 --- a/nixos/release-small.nix +++ b/nixos/release-small.nix @@ -2,7 +2,8 @@ # small subset of Nixpkgs, mostly useful for servers that need fast # security updates. -{ nixpkgs ? { outPath = (import ../lib).cleanSource ./..; revCount = 56789; shortRev = "gfedcba"; } +{ lib ? import ../lib +, nixpkgs ? { outPath = lib.cleanSource ./..; revCount = 56789; shortRev = "gfedcba"; } , stableBranch ? false , supportedSystems ? [ "aarch64-linux" "x86_64-linux" ] # no i686-linux }: @@ -11,12 +12,13 @@ let nixpkgsSrc = nixpkgs; # urgh - pkgs = import ./.. { system = "x86_64-linux"; }; - - lib = pkgs.lib; + pkgs = import ./.. { + inherit lib; + system = "x86_64-linux"; + }; nixos' = import ./release.nix { - inherit stableBranch supportedSystems; + inherit stableBranch supportedSystems lib; nixpkgs = nixpkgsSrc; }; diff --git a/nixos/release.nix b/nixos/release.nix index 175e756895a52..bbfffc8199d69 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -21,7 +21,7 @@ let allTestsForSystem = system: import ./tests/all-tests.nix { inherit system; - pkgs = import ./.. { inherit system; }; + pkgs = import ./.. { inherit system lib; }; callTest = config: { ${system} = hydraJob config.test; }; @@ -31,7 +31,7 @@ let allDrivers = import ./tests/all-tests.nix { inherit system; - pkgs = import ./.. { inherit system; }; + pkgs = import ./.. { inherit system lib; }; callTest = config: { ${system} = hydraJob config.driver; }; diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 070c19eed92b2..69f0d5a81b58a 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -36,6 +36,7 @@ let if elem system systems then handleTest path args else {}; + # TODO: make this overridable? nixosLib = import ../lib { # Experimental features need testing too, but there's no point in warning # about it, so we enable the feature flag.