this post was submitted on 02 Jan 2024
91 points (87.0% liked)

Linux

48697 readers
1388 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 11 months ago (1 children)

I dunno, I don’t trust a guides still recommending flake-utils. You can make the same four loop in like 4 lines of Nix which is a smaller diff & doesn’t pollute your downstream consumers with a useless dependency. Flakes also don’t eliminate pointless builds, fileset or filtering the src can & the only tool with file tracking on by default is the Git VCS specifically (which also involves the intent to add flags which is the other side of annoying).

[–] [email protected] 1 points 11 months ago (1 children)

I sometimes write a flake with those 4 lines of Nix code, and it comes out just messy enough that tbh I'm happier adding an input to handle that. But I recently learned that the nixpkgs flake exports the lib.* helpers through nixpkgs.lib (as opposed to nixpkgs.legacyPackages.${system}.lib) so you can call helpers before specifying a system. And nixpkgs.lib.genAttrs is kinda close enough to flake-utils.lib.eachSystem that it might make a better solution.

Like where with flake-utils you would write,

flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-darwin" ] (system:
let
  pkgs = nixpkgs.legacyPackages.${system};
in
{
  devShells.default = pkgs.mkShell {
    nativeBuildInputs = with pkgs; [
      hello
    ];
  };
})

Instead you can use genAttrs,

let
  forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-darwin" ];
  pkgs = forAllSystems (system:
    nixpkgs.legacyPackages.${system}
  );
in
{
  devShells = forAllSystems (system: {
    default = pkgs.${system}.mkShell {
      nativeBuildInputs = with pkgs.${system}; [
        hello
      ];
    };
  });
}

It's more verbose, but it makes the structure of outputs more transparent.

[–] [email protected] 2 points 11 months ago

Saving the dependency is pretty big since each flake you import will bring along its jungle of dependencies now in your downstream project. I can’t think of a use case where < 10 lines is worth a dependency—especially since as you noted, lib has the glue right there for you to put it all together.