1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2024-12-14 11:47:31 +00:00

Merge pull request #16 from hercules-ci/pkgs-argument

Add pkgs parameter to perSystem
This commit is contained in:
Robert Hensing 2022-05-18 11:09:12 +02:00 committed by GitHub
commit 0f0b1633a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 5 deletions

View file

@ -9,6 +9,7 @@
./modules/legacyPackages.nix
./modules/nixosConfigurations.nix
./modules/nixosModules.nix
./modules/nixpkgs.nix
./modules/overlay.nix
./modules/packages.nix
./modules/perSystem.nix

View file

@ -6,7 +6,6 @@ flakeModuleArgs@{ config, lib, inputs, ... }:
];
systems = [ "x86_64-linux" "aarch64-darwin" ];
perSystem = system: { config, self', inputs', pkgs, ... }: {
_module.args.pkgs = inputs'.nixpkgs.legacyPackages;
devShells.default = pkgs.mkShell {
nativeBuildInputs = [
@ -17,6 +16,7 @@ flakeModuleArgs@{ config, lib, inputs, ... }:
${config.pre-commit.installationScript}
'';
};
pre-commit = {
inherit pkgs; # should make this default to the one it can get via follows
settings = {

26
modules/nixpkgs.nix Normal file
View file

@ -0,0 +1,26 @@
#
# Nixpkgs module. The only exception to the rule.
#
# Provides a `pkgs` argument in `perSystem`.
#
# Arguably, this shouldn't be in flake-modules-core, but in nixpkgs.
# Nixpkgs could define its own module that does this, which would be
# a more consistent UX, but for now this will do.
#
# The existence of this module does not mean that other flakes' logic
# will be accepted into flake-modules-core, because it's against the
# spirit of Flakes.
#
{
config = {
perSystem = _: { inputs', lib, ... }: {
config = {
_module.args.pkgs = lib.mkOptionDefault (
builtins.seq
(inputs'.nixpkgs or (throw "flake-modules-core: The flake does not have a `nixpkgs` input. Please add it, or set `perSystem._module.args.pkgs` yourself."))
inputs'.nixpkgs.legacyPackages
);
};
};
};
}

View file

@ -19,12 +19,13 @@
];
systems = [ "x86_64-linux" "aarch64-darwin" ];
perSystem = system: { config, self', inputs', ... }: {
perSystem = system: { config, self', inputs', pkgs, ... }: {
# Per-system attributes can be defined here. The self' and inputs'
# module parameters provide easy access to attributes of the same
# system.
packages.hello = inputs'.nixpkgs.legacyPackages.hello;
# Equivalent to inputs'.nixpkgs.legacyPackages.hello;
packages.hello = pkgs.hello;
};
flake = {
# The usual flake attributes can be defined here, including system-

View file

@ -1,10 +1,10 @@
# Definitions can be imported from a separate file like this one
{ self, ... }: {
perSystem = system: { config, self', inputs', ... }: {
perSystem = system: { config, self', inputs', pkgs, ... }: {
# Definitions like this are entirely equivalent to the ones
# you may have directly in flake.nix.
packages.hello = inputs'.nixpkgs.legacyPackages.hello;
packages.hello = pkgs.hello;
};
flake = {
nixosModules.hello = { pkgs, ... }: {