From d574e02f72e54da0e243176fb9d3984aad7cc0a5 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 4 Nov 2024 09:46:51 -0500 Subject: [PATCH] Clean up packaging a bit - Multiple choices of stdenv are handled more consistently, especially for the dev shells which were previously not done correctly. - Some stray nix code was moving into the `packaging` directory --- flake.nix | 72 ++++++++----------- {scripts => packaging}/binary-tarball.nix | 10 +-- packaging/hydra.nix | 19 ++--- .../installer/default.nix | 0 {scripts => packaging/installer}/install.in | 0 tests/nixos/default.nix | 4 +- 6 files changed, 48 insertions(+), 57 deletions(-) rename {scripts => packaging}/binary-tarball.nix (85%) rename scripts/installer.nix => packaging/installer/default.nix (100%) rename {scripts => packaging/installer}/install.in (100%) diff --git a/flake.nix b/flake.nix index 8edc2266f08..64391efa40b 100644 --- a/flake.nix +++ b/flake.nix @@ -66,14 +66,7 @@ forAllCrossSystems = lib.genAttrs crossSystems; - forAllStdenvs = f: - lib.listToAttrs - (map - (stdenvName: { - name = "${stdenvName}Packages"; - value = f stdenvName; - }) - stdenvs); + forAllStdenvs = lib.genAttrs stdenvs; # We don't apply flake-parts to the whole flake so that non-development attributes @@ -89,32 +82,29 @@ # Memoize nixpkgs for different platforms for efficiency. nixpkgsFor = forAllSystems (system: let - make-pkgs = crossSystem: stdenv: import nixpkgs { - localSystem = { - inherit system; - }; - crossSystem = if crossSystem == null then null else { - config = crossSystem; - } // lib.optionalAttrs (crossSystem == "x86_64-unknown-freebsd13") { - useLLVM = true; - }; - overlays = [ - (overlayFor (p: p.${stdenv})) - ]; - }; - stdenvs = forAllStdenvs (make-pkgs null); - native = stdenvs.stdenvPackages; - in { - inherit stdenvs native; - static = native.pkgsStatic; - llvm = native.pkgsLLVM; - cross = forAllCrossSystems (crossSystem: make-pkgs crossSystem "stdenv"); + make-pkgs = crossSystem: + forAllStdenvs (stdenv: import nixpkgs { + localSystem = { + inherit system; + }; + crossSystem = if crossSystem == null then null else { + config = crossSystem; + } // lib.optionalAttrs (crossSystem == "x86_64-unknown-freebsd13") { + useLLVM = true; + }; + overlays = [ + (overlayFor (pkgs: pkgs.${stdenv})) + ]; + }); + in rec { + nativeForStdenv = make-pkgs null; + crossForStdenv = forAllCrossSystems make-pkgs; + # Alias for convenience + native = nativeForStdenv.stdenv; + cross = forAllCrossSystems (crossSystem: + crossForStdenv.${crossSystem}.stdenv); }); - binaryTarball = nix: pkgs: pkgs.callPackage ./scripts/binary-tarball.nix { - inherit nix; - }; - overlayFor = getStdenv: final: prev: let stdenv = getStdenv final; @@ -175,7 +165,6 @@ hydraJobs = import ./packaging/hydra.nix { inherit inputs - binaryTarball forAllCrossSystems forAllSystems lib @@ -211,7 +200,7 @@ # TODO: enable static builds for darwin, blocked on: # https://github.com/NixOS/nixpkgs/issues/320448 # TODO: disabled to speed up GHA CI. - #"static-" = nixpkgsFor.${system}.static; + #"static-" = nixpkgsFor.${system}.native.pkgsStatic; }) (nixpkgsPrefix: nixpkgs: flatMapAttrs nixpkgs.nixComponents @@ -282,8 +271,8 @@ (pkgName: { supportsCross ? true }: { # These attributes go right into `packages.`. "${pkgName}" = nixpkgsFor.${system}.native.nixComponents.${pkgName}; - "${pkgName}-static" = nixpkgsFor.${system}.static.nixComponents.${pkgName}; - "${pkgName}-llvm" = nixpkgsFor.${system}.llvm.nixComponents.${pkgName}; + "${pkgName}-static" = nixpkgsFor.${system}.native.pkgsStatic.nixComponents.${pkgName}; + "${pkgName}-llvm" = nixpkgsFor.${system}.native.pkgsLLVM.nixComponents.${pkgName}; } // lib.optionalAttrs supportsCross (flatMapAttrs (lib.genAttrs crossSystems (_: { })) (crossSystem: {}: { # These attributes go right into `packages.`. @@ -291,7 +280,7 @@ })) // flatMapAttrs (lib.genAttrs stdenvs (_: { })) (stdenvName: {}: { # These attributes go right into `packages.`. - "${pkgName}-${stdenvName}" = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages".nixComponents.${pkgName}; + "${pkgName}-${stdenvName}" = nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.nixComponents.${pkgName}; }) ) // lib.optionalAttrs (builtins.elem system linux64BitSystems) { @@ -317,21 +306,22 @@ in forAllSystems (system: prefixAttrs "native" (forAllStdenvs (stdenvName: makeShell { - pkgs = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages"; + pkgs = nixpkgsFor.${system}.nativeForStdenv.${stdenvName}; })) // lib.optionalAttrs (!nixpkgsFor.${system}.native.stdenv.isDarwin) ( prefixAttrs "static" (forAllStdenvs (stdenvName: makeShell { - pkgs = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages".pkgsStatic; + pkgs = nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.pkgsStatic; })) // prefixAttrs "llvm" (forAllStdenvs (stdenvName: makeShell { - pkgs = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages".pkgsLLVM; + pkgs = nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.pkgsLLVM; })) // prefixAttrs "cross" (forAllCrossSystems (crossSystem: makeShell { pkgs = nixpkgsFor.${system}.cross.${crossSystem}; })) ) // { - default = self.devShells.${system}.native-stdenvPackages; + native = self.devShells.${system}.native-stdenv; + default = self.devShells.${system}.native; } ); }; diff --git a/scripts/binary-tarball.nix b/packaging/binary-tarball.nix similarity index 85% rename from scripts/binary-tarball.nix rename to packaging/binary-tarball.nix index 9de90b7fb56..59e11c77dfd 100644 --- a/scripts/binary-tarball.nix +++ b/packaging/binary-tarball.nix @@ -22,18 +22,18 @@ in runCommand "nix-binary-tarball-${version}" env '' cp ${installerClosureInfo}/registration $TMPDIR/reginfo - cp ${./create-darwin-volume.sh} $TMPDIR/create-darwin-volume.sh - substitute ${./install-nix-from-tarball.sh} $TMPDIR/install \ + cp ${../scripts/create-darwin-volume.sh} $TMPDIR/create-darwin-volume.sh + substitute ${../scripts/install-nix-from-tarball.sh} $TMPDIR/install \ --subst-var-by nix ${nix} \ --subst-var-by cacert ${cacert} - substitute ${./install-darwin-multi-user.sh} $TMPDIR/install-darwin-multi-user.sh \ + substitute ${../scripts/install-darwin-multi-user.sh} $TMPDIR/install-darwin-multi-user.sh \ --subst-var-by nix ${nix} \ --subst-var-by cacert ${cacert} - substitute ${./install-systemd-multi-user.sh} $TMPDIR/install-systemd-multi-user.sh \ + substitute ${../scripts/install-systemd-multi-user.sh} $TMPDIR/install-systemd-multi-user.sh \ --subst-var-by nix ${nix} \ --subst-var-by cacert ${cacert} - substitute ${./install-multi-user.sh} $TMPDIR/install-multi-user \ + substitute ${../scripts/install-multi-user.sh} $TMPDIR/install-multi-user \ --subst-var-by nix ${nix} \ --subst-var-by cacert ${cacert} diff --git a/packaging/hydra.nix b/packaging/hydra.nix index 5b1e4755948..77fe93dc330 100644 --- a/packaging/hydra.nix +++ b/packaging/hydra.nix @@ -1,5 +1,4 @@ { inputs -, binaryTarball , forAllCrossSystems , forAllSystems , lib @@ -12,7 +11,7 @@ let inherit (inputs) nixpkgs nixpkgs-regression; installScriptFor = tarballs: - nixpkgsFor.x86_64-linux.native.callPackage ../scripts/installer.nix { + nixpkgsFor.x86_64-linux.native.callPackage ./installer { inherit tarballs; }; @@ -62,7 +61,7 @@ in [ "i686-linux" ]; buildStatic = forAllPackages (pkgName: - lib.genAttrs linux64BitSystems (system: nixpkgsFor.${system}.static.nixComponents.${pkgName})); + lib.genAttrs linux64BitSystems (system: nixpkgsFor.${system}.native.pkgsStatic.nixComponents.${pkgName})); buildCross = forAllPackages (pkgName: # Hack to avoid non-evaling package @@ -99,13 +98,12 @@ in # Binary tarball for various platforms, containing a Nix store # with the closure of 'nix' package, and the second half of # the installation script. - binaryTarball = forAllSystems (system: binaryTarball nixpkgsFor.${system}.native.nix nixpkgsFor.${system}.native); + binaryTarball = forAllSystems (system: + nixpkgsFor.${system}.native.callPackage ./binary-tarball.nix {}); binaryTarballCross = lib.genAttrs [ "x86_64-linux" ] (system: forAllCrossSystems (crossSystem: - binaryTarball - nixpkgsFor.${system}.cross.${crossSystem}.nix - nixpkgsFor.${system}.cross.${crossSystem})); + nixpkgsFor.${system}.cross.${crossSystem}.callPackage ./binary-tarball.nix {})); # The first half of the installation script. This is uploaded # to https://nixos.org/nix/install. It downloads the binary @@ -124,7 +122,7 @@ in self.hydraJobs.binaryTarballCross."x86_64-linux"."riscv64-unknown-linux-gnu" ]; - installerScriptForGHA = forAllSystems (system: nixpkgsFor.${system}.native.callPackage ../scripts/installer.nix { + installerScriptForGHA = forAllSystems (system: nixpkgsFor.${system}.native.callPackage ./installer { tarballs = [ self.hydraJobs.binaryTarball.${system} ]; }); @@ -147,7 +145,10 @@ in external-api-docs = nixpkgsFor.x86_64-linux.native.nixComponents.nix-external-api-docs; # System tests. - tests = import ../tests/nixos { inherit lib nixpkgs nixpkgsFor self; } // { + tests = import ../tests/nixos { + inherit lib nixpkgs nixpkgsFor; + inherit (self.inputs) nixpkgs-23-11; + } // { # Make sure that nix-env still produces the exact same result # on a particular version of Nixpkgs. diff --git a/scripts/installer.nix b/packaging/installer/default.nix similarity index 100% rename from scripts/installer.nix rename to packaging/installer/default.nix diff --git a/scripts/install.in b/packaging/installer/install.in similarity index 100% rename from scripts/install.in rename to packaging/installer/install.in diff --git a/tests/nixos/default.nix b/tests/nixos/default.nix index 8e0cb1b225b..1c207fba55b 100644 --- a/tests/nixos/default.nix +++ b/tests/nixos/default.nix @@ -1,4 +1,4 @@ -{ lib, nixpkgs, nixpkgsFor, self }: +{ lib, nixpkgs, nixpkgsFor, nixpkgs-23-11 }: let @@ -64,7 +64,7 @@ let otherNixes.nix_2_13.setNixPackage = { lib, pkgs, ... }: { imports = [ checkOverrideNixVersion ]; nix.package = lib.mkForce ( - self.inputs.nixpkgs-23-11.legacyPackages.${pkgs.stdenv.hostPlatform.system}.nixVersions.nix_2_13.overrideAttrs (o: { + nixpkgs-23-11.legacyPackages.${pkgs.stdenv.hostPlatform.system}.nixVersions.nix_2_13.overrideAttrs (o: { meta = o.meta // { knownVulnerabilities = []; }; }) );