Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nixpkgs module #74

Open
roberth opened this issue Nov 15, 2022 · 7 comments
Open

Nixpkgs module #74

roberth opened this issue Nov 15, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@roberth
Copy link
Member

roberth commented Nov 15, 2022

Prototype a more extensive Nixpkgs module in flake-parts before perhaps eventually doing #41

https://twitter.com/ldesgoui/status/1592576468789628928

@srid
Copy link
Contributor

srid commented Nov 15, 2022

Could we have more than one pkgs as a result? For, eg., native pkgs and a rosetta pkgs (on aarch64-darwin).

@roberth
Copy link
Member Author

roberth commented Nov 15, 2022

Good idea. The root nixpkgs.* options could be permanent aliases for nixpkgsSets.pkgs or something.

@roberth
Copy link
Member Author

roberth commented Nov 16, 2022

For Rosetta, you can already get a pkgs via getSystem and/or withSystem. Those will also give you access to your own packages for that system.
The feature still makes a lot of sense for having different versions of Nixpkgs, but for mixed-system and cross, it'd be better to use and improve the perSystem infrastructure.

@Atry
Copy link
Contributor

Atry commented Apr 18, 2023

I would just use https://github.com/NixOS/nixpkgs/blob/3b4e70e987a42792196294560a233d285b1c1d10/nixos/modules/misc/nixpkgs.nix

    ml-ops.inputs.flake-parts.lib.mkFlake { inherit inputs; } {
      perSystem = { pkgs, system, ... }:
        {
          imports = [
            "${inputs.nixpkgs}/nixos/modules/misc/nixpkgs.nix"
          ];
          nixpkgs = {
            hostPlatform = system;
            
            
            # other options, e.g. 
            # config.allowUnfree = true;
          };
       };
    }

@roberth
Copy link
Member Author

roberth commented May 29, 2024

I'd previously opened NixOS/nixpkgs#231940 with the idea to import from that, but I've since realized that Nixpkgs needs an exception, because imports will fetch it eagerly, and that's a problem for such a large dependency, when it might not even be used (e.g. easyOverlay use case; see #147 (comment))

I'm sorry to have gone back and forth on this, but at least we didn't commit to a mistake in the meanwhile.

Aforementioned Nixpkgs makes a number of improvements which we should adopt in the flake-parts Nixpkgs module.

It could look as follows:

  • flake-parts.modules.flake.pkgs is a new module
  • it declares in perSystem.nixpkgs.<name>:
    • hostPlatform (default: system)
    • buildPlatform (build elsewhere for cross)
    • pkgs (alias for _module.args.pkgs)
    • overlays
    • config
    • source (default: inputs.nixpkgs)
  • <name> causes _module.args.<name> to be set
    • if enabled?
  • it does not have the legacy options system, localSystem or crossSystem
  • the perSystem.pkgs option is an alias for perSystem.nixpkgs.pkgs
    • or should this be the other way around? That way it's more NixOS compatible.
      e.g. perSystem.nixpkgs.config.allowUnfree = true;
      or pkgs.pkgs-unstable.source = inputs.nixpkgs-unstable;

@tie
Copy link

tie commented May 30, 2024

It’d also be nice to have readOnlyPkgs module, similar to what we have for NixOS.

@roberth
Copy link
Member Author

roberth commented Oct 5, 2024

overlays must be disallowed by default, because they are simply too risky, especially as otherwise any module could define any attribute in it, affecting all callPackage, without the flake author being aware of this happening.

Even an attribute as innocent as sources (convenient, not a package name) will cause some packages to fail to evaluate with an obscure error. Very hard to troubleshoot, and not worth the "convenience" at all.

We have better ways to convey values, such as flake-parts-lib.importApply, withSystem, etc, which do not create this risk of obscure silent name collisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants