PetarKirov / dlang.nix

Nix expressions for building D compilers
MIT License
6 stars 1 forks source link

Noted the difference of Nixpkgs fetching in flake world. #50

Closed dukc closed 4 months ago

dukc commented 4 months ago

Ping @PetarKirov . I'm learning flakes all the time but my mindset is still a bit in the pre-flake world and this is one thing that could have surprised me as an user.

Full story: I have flakes installed and I already use them when I simply want to do a build, but it felt too much to figure out at once how I can override the bootstrap compiler with the new-generation nix commands so I did that with good old nix-build -E instead - and ended wondering "oh wait, where is callPackage? It's called for me but I'm not passing <nixpkgs> to default.nix!".

PetarKirov commented 4 months ago

I think our current default.nix is quite bare-bones in the sense that it only provides a compatibility wrapper around flake.nix and flake.lock via flake-compat. We could do more, including allowing users to pass their own nixpkgs instance. That said, I'm not sure if this is desirable as we can only guarantee that our derivations work with the nixpkgs instance that we have pinned and also that's the only way for our users to benefit from our Cachix cache (https://dlang-community.cachix.org/). Anyway, about the default.nix file - feel free to propose whatever extension points you see fit.

PetarKirov commented 4 months ago

I just found a paragraph in the Nix Wiki that explains how flake-compat works: https://nixos.wiki/wiki/Flakes#Using_flakes_with_stable_Nix

@dukc can you add a link to it from the paragraph you added in this PR?

PetarKirov commented 4 months ago

One more undocumented feature that we have for classic Nix users is our overlay. It can be used like this:

# Run this from the `dlang.nix` repo root:
➤ nix repl
Welcome to Nix 2.16.2. Type :? for help.

nix-repl> pkgs = import <nixpkgs> { overlays = [ (import ./.).outputs.overlays.default ]; }

nix-repl> pkgs.dmd 
pkgs.dmd                 pkgs.dmd-2_105_2         pkgs.dmd-binary-2_086_1
pkgs.dmd-2_092_1         pkgs.dmd-binary-2_079_1  pkgs.dmd-binary-2_087_1
pkgs.dmd-2_096_1         pkgs.dmd-binary-2_080_1  pkgs.dmd-binary-2_088_1
pkgs.dmd-2_098_1         pkgs.dmd-binary-2_081_2  pkgs.dmd-binary-2_089_1
pkgs.dmd-2_100_2         pkgs.dmd-binary-2_082_1  pkgs.dmd-binary-2_090_1
pkgs.dmd-2_102_2         pkgs.dmd-binary-2_083_1  pkgs.dmd-binary-2_098_0
pkgs.dmd-2_103_1         pkgs.dmd-binary-2_084_1  pkgs.dmd-bootstrap
pkgs.dmd-2_104_2         pkgs.dmd-binary-2_085_1

Edit:

here's a complete .nix file:

let
  dlang-nix = builtins.fetchGit {
    url = "https://github.com/PetarKirov/dlang.nix";
    rev = "75a2de549014bb1219957a10da778e7b2df967e8";
  };

  pkgs = import <nixpkgs> {
    overlays = [ (import dlang-nix).overlays.default ];
  };
in
  pkgs.mkShell {
    packages = with pkgs; [
      dmd-2_104_2
      dub
    ];
  }

But of course, users should beware that in most certainty they won't be able to benefit from our binary cache and they should be prepared for a long build. E.g. 40+ mins on macOS M1.

github-actions[bot] commented 4 months ago

Thanks for your Pull Request!

Below you will find a summary of the cachix status of each package, for each supported platform.

package x86_64-linux x86_64-darwin aarch64-darwin
dmd ✅ cached ✅ cached 🚫 not supported
dmd-2_092_1 ✅ cached ✅ cached 🚫 not supported
dmd-2_096_1 ✅ cached ✅ cached 🚫 not supported
dmd-2_098_1 ✅ cached ✅ cached 🚫 not supported
dmd-2_100_2 ✅ cached ✅ cached 🚫 not supported
dmd-2_102_2 ✅ cached ✅ cached 🚫 not supported
dmd-2_103_1 ✅ cached ✅ cached 🚫 not supported
dmd-2_104_2 ✅ cached ✅ cached 🚫 not supported
dmd-2_105_2 ✅ cached ✅ cached 🚫 not supported
dmd-binary-2_079_1 ✅ cached ✅ cached 🚫 not supported
dmd-binary-2_080_1 ✅ cached ✅ cached 🚫 not supported
dmd-binary-2_081_2 ✅ cached ✅ cached 🚫 not supported
dmd-binary-2_082_1 ✅ cached ✅ cached 🚫 not supported
dmd-binary-2_083_1 ✅ cached ✅ cached 🚫 not supported
dmd-binary-2_084_1 ✅ cached ✅ cached 🚫 not supported
dmd-binary-2_085_1 ✅ cached ✅ cached 🚫 not supported
dmd-binary-2_086_1 ✅ cached ✅ cached 🚫 not supported
dmd-binary-2_087_1 ✅ cached ✅ cached 🚫 not supported
dmd-binary-2_088_1 ✅ cached ✅ cached 🚫 not supported
dmd-binary-2_089_1 ✅ cached ✅ cached 🚫 not supported
dmd-binary-2_090_1 ✅ cached ✅ cached 🚫 not supported
dmd-binary-2_098_0 ✅ cached ✅ cached 🚫 not supported
dmd-bootstrap ✅ cached ✅ cached 🚫 not supported
dub ✅ cached ✅ cached ✅ cached
dub-1_30_0 ✅ cached ✅ cached ✅ cached
ldc ✅ cached 🚧 known to fail (disabled) 🚧 known to fail (disabled)
ldc-1_30_0 ✅ cached 🚧 known to fail (disabled) 🚧 known to fail (disabled)
ldc-binary ✅ cached ✅ cached ✅ cached
ldc-binary-1_19_0 ✅ cached ✅ cached 🚫 not supported
ldc-binary-1_25_0 ✅ cached ✅ cached ✅ cached
ldc-binary-1_28_0 ✅ cached ✅ cached ✅ cached
ldc-binary-1_32_1 ✅ cached ✅ cached ✅ cached
ldc-binary-1_34_0 ✅ cached ✅ cached ✅ cached
dukc commented 4 months ago

@dukc can you add a link to it from the paragraph you added in this PR?

@PetarKirov Done, except I took the liberty to add it some way up instead. Otherwise unchanged from the version you reviewed so toggled auto-merge on.

dukc commented 4 months ago

I think our current default.nix is quite bare-bones in the sense that it only provides a compatibility wrapper around flake.nix and flake.lock via flake-compat. We could do more, including allowing users to pass their own nixpkgs instance

That would be nice to have, but I don't feel it's anything critical to have. I might or might not implement it at some point.

One more undocumented feature that we have for classic Nix users is our overlay. It can be used like this

Wow! That's a worthy add I need to do at some point. In fact I think it satisfies the need to use an own nixpkgs instance, except maybe for the fact it imports both the flake-pinned nixpkgs and users nixpkgs, even though only the latter is used for building the compilers themselves.