1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-24 18:01:16 +02:00
This commit is contained in:
Robert Hensing 2025-06-20 20:30:08 +03:00 committed by GitHub
commit 59efeaf2dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 203 additions and 22 deletions

210
flake.nix
View file

@ -131,31 +131,107 @@
} }
); );
overlayFor = /**
getStdenv: final: prev: Produce the `nixComponents` and `nixDependencies` package sets (scopes) for
a given `pkgs` and `getStdenv`.
*/
packageSetsFor =
let let
stdenv = getStdenv final; /**
Removes a prefix from the attribute names of a set of splices.
This is a completely uninteresting and exists for compatibility only.
Example:
```nix
renameSplicesFrom "pkgs" { pkgsBuildBuild = ...; ... }
=> { buildBuild = ...; ... }
```
*/
renameSplicesFrom = prefix: x: {
buildBuild = x."${prefix}BuildBuild";
buildHost = x."${prefix}BuildHost";
buildTarget = x."${prefix}BuildTarget";
hostHost = x."${prefix}HostHost";
hostTarget = x."${prefix}HostTarget";
targetTarget = x."${prefix}TargetTarget";
};
/**
Adds a prefix to the attribute names of a set of splices.
This is a completely uninteresting and exists for compatibility only.
Example:
```nix
renameSplicesTo "self" { buildBuild = ...; ... }
=> { selfBuildBuild = ...; ... }
```
*/
renameSplicesTo = prefix: x: {
"${prefix}BuildBuild" = x.buildBuild;
"${prefix}BuildHost" = x.buildHost;
"${prefix}BuildTarget" = x.buildTarget;
"${prefix}HostHost" = x.hostHost;
"${prefix}HostTarget" = x.hostTarget;
"${prefix}TargetTarget" = x.targetTarget;
};
/**
Takes a function `f` and returns a function that applies `f` pointwise to each splice.
Example:
```nix
mapSplices (x: x * 10) { buildBuild = 1; buildHost = 2; ... }
=> { buildBuild = 10; buildHost = 20; ... }
```
*/
mapSplices =
f:
{
buildBuild,
buildHost,
buildTarget,
hostHost,
hostTarget,
targetTarget,
}:
{
buildBuild = f buildBuild;
buildHost = f buildHost;
buildTarget = f buildTarget;
hostHost = f hostHost;
hostTarget = f hostTarget;
targetTarget = f targetTarget;
};
in in
{ args@{
nixStable = prev.nix; pkgs,
getStdenv ? pkgs: pkgs.stdenv,
}:
let
nixComponentsSplices = mapSplices (
pkgs': (packageSetsFor (args // { pkgs = pkgs'; })).nixComponents
) (renameSplicesFrom "pkgs" pkgs);
nixDependenciesSplices = mapSplices (
pkgs': (packageSetsFor (args // { pkgs = pkgs'; })).nixDependencies
) (renameSplicesFrom "pkgs" pkgs);
# A new scope, so that we can use `callPackage` to inject our own interdependencies # A new scope, so that we can use `callPackage` to inject our own interdependencies
# without "polluting" the top level "`pkgs`" attrset. # without "polluting" the top level "`pkgs`" attrset.
# This also has the benefit of providing us with a distinct set of packages # This also has the benefit of providing us with a distinct set of packages
# we can iterate over. # we can iterate over.
# The `2` suffix is here because otherwise it interferes with `nixVersions.latest`, which is used in daemon compat tests. nixComponents =
nixComponents2 =
lib.makeScopeWithSplicing' lib.makeScopeWithSplicing'
{ {
inherit (final) splicePackages; inherit (pkgs) splicePackages;
inherit (final.nixDependencies2) newScope; inherit (nixDependencies) newScope;
} }
{ {
otherSplices = final.generateSplicesForMkScope "nixComponents2"; otherSplices = renameSplicesTo "self" nixComponentsSplices;
f = import ./packaging/components.nix { f = import ./packaging/components.nix {
inherit (final) lib; inherit (pkgs) lib;
inherit officialRelease; inherit officialRelease;
pkgs = final; inherit pkgs;
src = self; src = self;
maintainers = [ ]; maintainers = [ ];
}; };
@ -163,29 +239,71 @@
# The dependencies are in their own scope, so that they don't have to be # The dependencies are in their own scope, so that they don't have to be
# in Nixpkgs top level `pkgs` or `nixComponents2`. # in Nixpkgs top level `pkgs` or `nixComponents2`.
# The `2` suffix is here because otherwise it interferes with `nixVersions.latest`, which is used in daemon compat tests. nixDependencies =
nixDependencies2 =
lib.makeScopeWithSplicing' lib.makeScopeWithSplicing'
{ {
inherit (final) splicePackages; inherit (pkgs) splicePackages;
inherit (final) newScope; # layered directly on pkgs, unlike nixComponents2 above inherit (pkgs) newScope; # layered directly on pkgs, unlike nixComponents2 above
} }
{ {
otherSplices = final.generateSplicesForMkScope "nixDependencies2"; otherSplices = renameSplicesTo "self" nixDependenciesSplices;
f = import ./packaging/dependencies.nix { f = import ./packaging/dependencies.nix {
inherit inputs stdenv; inherit inputs pkgs;
pkgs = final; stdenv = getStdenv pkgs;
}; };
}; };
# If the package set is largely empty, we should(?) return empty sets
# This is what most package sets in Nixpkgs do. Otherwise, we get
# an error message that indicates that some stdenv attribute is missing,
# and indeed it will be missing, as seemingly `pkgsTargetTarget` is
# very incomplete.
fixup = lib.mapAttrs (k: v: if !(pkgs ? nix) then { } else v);
in
fixup {
inherit nixDependencies;
inherit nixComponents;
};
overlayFor =
getStdenv: final: prev:
let
packageSets = packageSetsFor {
inherit getStdenv;
pkgs = final;
};
in
{
nixStable = prev.nix;
# The `2` suffix is here because otherwise it interferes with `nixVersions.latest`, which is used in daemon compat tests.
nixComponents2 = packageSets.nixComponents;
# The dependencies are in their own scope, so that they don't have to be
# in Nixpkgs top level `pkgs` or `nixComponents2`.
# The `2` suffix is here because otherwise it interferes with `nixVersions.latest`, which is used in daemon compat tests.
nixDependencies2 = packageSets.nixDependencies;
nix = final.nixComponents2.nix-cli; nix = final.nixComponents2.nix-cli;
}; };
in in
{ {
# A Nixpkgs overlay that overrides the 'nix' and overlays.internal = overlayFor (p: p.stdenv);
# 'nix-perl-bindings' packages.
overlays.default = overlayFor (p: p.stdenv); /**
A Nixpkgs overlay that sets `nix` to something like `packages.<system>.nix-everything`,
except dependencies aren't taken from (flake) `nix.inputs.nixpkgs`, but from the Nixpkgs packages
where the overlay is used.
*/
overlays.default =
final: prev:
let
packageSets = packageSetsFor { pkgs = final; };
in
{
nix = packageSets.nixComponents.nix-everything;
};
hydraJobs = import ./packaging/hydra.nix { hydraJobs = import ./packaging/hydra.nix {
inherit inherit
@ -465,5 +583,53 @@
default = self.devShells.${system}.native; default = self.devShells.${system}.native;
} }
); );
lib = {
/**
Creates a package set for a given Nixpkgs instance and stdenv.
# Inputs
- `pkgs`: The Nixpkgs instance to use.
- `getStdenv`: _Optional_ A function that takes a package set and returns the stdenv to use.
This needs to be a function in order to support cross compilation - the `pkgs` passed to `getStdenv` can be `pkgsBuildHost` or any other variation needed.
# Outputs
The return value is a fresh Nixpkgs scope containing all the packages that are defined in the Nix repository,
as well as some internals and parameters, which may be subject to change.
# Example
```console
nix repl> :lf NixOS/nix
nix-repl> ps = lib.makeComponents { pkgs = import inputs.nixpkgs { crossSystem = "riscv64-linux"; }; }
nix-repl> ps
{
appendPatches = «lambda appendPatches @ ...»;
callPackage = «lambda callPackageWith @ ...»;
overrideAllMesonComponents = «lambda overrideSource @ ...»;
overrideSource = «lambda overrideSource @ ...»;
# ...
nix-everything
# ...
nix-store
nix-store-c
# ...
}
```
*/
makeComponents =
{
pkgs,
getStdenv ? pkgs: pkgs.stdenv,
}:
let
packageSets = packageSetsFor { inherit getStdenv pkgs; };
in
packageSets.nixComponents;
};
}; };
} }

View file

@ -365,18 +365,33 @@ in
nix-cmd = callPackage ../src/libcmd/package.nix { }; nix-cmd = callPackage ../src/libcmd/package.nix { };
/**
The Nix command line interface. Note that this does not include its tests, whereas `nix-everything` does.
*/
nix-cli = callPackage ../src/nix/package.nix { version = fineVersion; }; nix-cli = callPackage ../src/nix/package.nix { version = fineVersion; };
nix-functional-tests = callPackage ../tests/functional/package.nix { nix-functional-tests = callPackage ../tests/functional/package.nix {
version = fineVersion; version = fineVersion;
}; };
/**
The manual as would be published on https://nix.dev/reference/nix-manual
*/
nix-manual = callPackage ../doc/manual/package.nix { version = fineVersion; }; nix-manual = callPackage ../doc/manual/package.nix { version = fineVersion; };
/**
Doxygen pages for C++ code
*/
nix-internal-api-docs = callPackage ../src/internal-api-docs/package.nix { version = fineVersion; }; nix-internal-api-docs = callPackage ../src/internal-api-docs/package.nix { version = fineVersion; };
/**
Doxygen pages for the public C API
*/
nix-external-api-docs = callPackage ../src/external-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 { }; nix-perl-bindings = callPackage ../src/perl/package.nix { };
/**
Combined package that has the CLI, libraries, and (assuming non-cross, no overrides) it requires that all tests succeed.
*/
nix-everything = callPackage ../packaging/everything.nix { } // { nix-everything = callPackage ../packaging/everything.nix { } // {
# Note: no `passthru.overrideAllMesonComponents` etc # Note: no `passthru.overrideAllMesonComponents` etc
# This would propagate into `nix.overrideAttrs f`, but then discard # This would propagate into `nix.overrideAttrs f`, but then discard