hercules-ci / flake-parts

❄️ Simplify Nix Flakes with the module system
https://flake.parts
MIT License
766 stars 41 forks source link

Nixpkgs module #74

Open roberth opened 1 year ago

roberth commented 1 year ago

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

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

srid commented 1 year ago

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

roberth commented 1 year ago

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

roberth commented 1 year ago

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 commented 1 year ago

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 commented 5 months ago

I'd previously opened https://github.com/NixOS/nixpkgs/pull/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 https://github.com/hercules-ci/flake-parts/pull/147#issuecomment-2138376065)

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:

tie commented 5 months ago

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

roberth commented 1 month ago

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.