numtide / devshell

Per project developer environments
https://numtide.github.io/devshell/
MIT License
1.18k stars 86 forks source link

Fully document how to use extra modules with plain flake.nix #287

Open antifuchs opened 7 months ago

antifuchs commented 7 months ago

Describe the bug

I've just spent about an hour figuring out how to properly import the language/c and language/rust "extra" modules in my flake-parts based project flake, and how to set these up such that my project compiles.

To that end, it would have been very useful to have documentation for the following:

This is similar to #283; I wish I'd guessed right the first time, instead I spent a while debugging inscrutable error messages.

To Reproduce

This flake definition works:

{
  outputs = inputs @ {
    self,
    flake-parts,
    nixpkgs,
    fenix,
    ...
  }:
    flake-parts.lib.mkFlake {inherit inputs;} {
      systems = [
        "x86_64-linux"
        "aarch64-linux"
      ];

      imports = [
        inputs.devshell.flakeModule
        inputs.flake-parts.flakeModules.easyOverlay
      ];

      perSystem = {
        config,
        pkgs,
        final,
        system,
        ...
      }: {
        formatter = pkgs.alejandra;

        devshells = {
          default = {
            imports = [
              "${inputs.devshell}/extra/language/rust.nix"
              "${inputs.devshell}/extra/language/c.nix"
            ];
            language.rust = {
              enableDefaultToolchain = false;
              packageSet = fenix.packages.${system}.stable;
            };

            language.c.includes = [pkgs.udev];
          };
        };
      };
    };

  inputs = {
    flake-parts.url = "github:hercules-ci/flake-parts";
    devshell.url = "github:numtide/devshell";
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    fenix = {
      url = "github:nix-community/fenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };
}

However, the following things do not:

Expected behavior

Some things that would have made my life easier:

System information

flake-parts 34fed993f1674c8d06d58b37ce1e0fe5eebcb9f5 devshell 44ddedcbcfc2d52a76b64fb6122f209881bd3e1e

Additional context