Skip to content

Commit

Permalink
Coarse versions for constituent packages
Browse files Browse the repository at this point in the history
As discussed in our meeting, we should use a simplified version for the
libraries without the date or commit hash. This will make rebuilding a
lot faster in many cases.

Progress on NixOS#10379

Co-Authored-By: Robert Hensing <[email protected]>
  • Loading branch information
Ericson2314 and roberth committed Aug 14, 2024
1 parent 4956e7c commit 93f5815
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
19 changes: 9 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@

officialRelease = false;

version = lib.fileContents ./.version + versionSuffix;
versionSuffix =
if officialRelease
then ""
else "pre${builtins.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}_${self.shortRev or "dirty"}";

linux32BitSystems = [ "i686-linux" ];
linux64BitSystems = [ "x86_64-linux" "aarch64-linux" ];
linuxSystems = linux32BitSystems ++ linux64BitSystems;
Expand Down Expand Up @@ -130,12 +124,16 @@
# without "polluting" the top level "`pkgs`" attrset.
# This also has the benefit of providing us with a distinct set of packages
# we can iterate over.
nixComponents = lib.makeScope final.nixDependencies.newScope (import ./packaging/components.nix);
nixComponents = lib.makeScope final.nixDependencies.newScope (import ./packaging/components.nix {
inherit (final) lib;
inherit officialRelease;
src = self;
});

# The dependencies are in their own scope, so that they don't have to be
# in Nixpkgs top level `pkgs` or `nixComponents`.
nixDependencies = lib.makeScope final.newScope (import ./packaging/dependencies.nix {
inherit inputs stdenv versionSuffix;
inherit inputs stdenv;
pkgs = final;
});

Expand Down Expand Up @@ -170,6 +168,7 @@
linux64BitSystems
nixpkgsFor
self
officialRelease
;
};

Expand Down Expand Up @@ -253,10 +252,10 @@
dockerImage =
let
pkgs = nixpkgsFor.${system}.native;
image = import ./docker.nix { inherit pkgs; tag = version; };
image = import ./docker.nix { inherit pkgs; tag = pkgs.nix.version; };
in
pkgs.runCommand
"docker-image-tarball-${version}"
"docker-image-tarball-${pkgs.nix.version}"
{ meta.description = "Docker image with Nix for ${system}"; }
''
mkdir -p $out/nix-support
Expand Down
5 changes: 2 additions & 3 deletions package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@

, pname ? "nix"

, versionSuffix ? ""
, version
, versionSuffix

# Whether to build Nix. Useful to skip for tasks like testing existing pre-built versions of Nix
, doBuild ? true
Expand Down Expand Up @@ -112,8 +113,6 @@
let
inherit (lib) fileset;

version = lib.fileContents ./.version + versionSuffix;

# selected attributes with defaults, will be used to define some
# things which should instead be gotten via `finalAttrs` in order to
# work with overriding.
Expand Down
31 changes: 27 additions & 4 deletions packaging/components.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
{
lib,
src,
officialRelease,
}:

scope:

let
inherit (scope) callPackage;

baseVersion = lib.fileContents ../.version;

versionSuffix = lib.optionalString (!officialRelease) "pre";

fineVersionSuffix = lib.optionalString
(!officialRelease)
"pre${builtins.substring 0 8 (src.lastModifiedDate or src.lastModified or "19700101")}_${src.shortRev or "dirty"}";

fineVersion = baseVersion + fineVersionSuffix;
in

# This becomes the pkgs.nixComponents attribute set
{
nix = callPackage ../package.nix { };
version = baseVersion + versionSuffix;
inherit versionSuffix;

nix = callPackage ../package.nix {
version = fineVersion;
versionSuffix = fineVersionSuffix;
};

nix-util = callPackage ../src/libutil/package.nix { };
nix-util-c = callPackage ../src/libutil-c/package.nix { };
Expand Down Expand Up @@ -34,10 +57,10 @@ in
nix-cmd = callPackage ../src/libcmd/package.nix { };

# Will replace `nix` once the old build system is gone.
nix-ng = callPackage ../src/nix/package.nix { };
nix-ng = callPackage ../src/nix/package.nix { version = fineVersion; };

nix-internal-api-docs = callPackage ../src/internal-api-docs/package.nix { };
nix-external-api-docs = callPackage ../src/external-api-docs/package.nix { };
nix-internal-api-docs = callPackage ../src/internal-api-docs/package.nix { version = fineVersion; };
nix-external-api-docs = callPackage ../src/external-api-docs/package.nix { version = fineVersion; };

nix-perl-bindings = callPackage ../src/perl/package.nix { };
}
5 changes: 1 addition & 4 deletions packaging/dependencies.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
pkgs,

stdenv,
versionSuffix,
}:

let
Expand Down Expand Up @@ -73,11 +72,9 @@ let
strictDeps = prevAttrs.strictDeps or true;
enableParallelBuilding = true;
};

in
scope: {
inherit stdenv versionSuffix;
version = lib.fileContents ../.version + versionSuffix;
inherit stdenv;

aws-sdk-cpp = (pkgs.aws-sdk-cpp.override {
apis = [ "s3" "transfer" ];
Expand Down
9 changes: 8 additions & 1 deletion packaging/hydra.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
, linux64BitSystems
, nixpkgsFor
, self
, officialRelease
}:
let
inherit (inputs) nixpkgs nixpkgs-regression;
Expand All @@ -16,7 +17,7 @@ let
};

testNixVersions = pkgs: client: daemon:
pkgs.callPackage ../package.nix {
pkgs.nixComponents.callPackage ../package.nix {
pname =
"nix-tests"
+ lib.optionalString
Expand All @@ -28,6 +29,12 @@ let
test-daemon = daemon;

doBuild = false;

# This could be more accurate, but a shorter version will match the
# fine version with rev. This functionality is already covered in
# the normal test, so it's fine.
version = pkgs.nixComponents.version;
versionSuffix = pkgs.nixComponents.versionSuffix;
};

# Technically we could just return `pkgs.nixComponents`, but for Hydra it's
Expand Down

0 comments on commit 93f5815

Please sign in to comment.