lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

devshell.nix (1786B)


      1 {
      2   lib,
      3   pkgs,
      4 }:
      5 {
      6   serviceName,
      7   toolchain,
      8   nativeInputs,
      9 }:
     10 assert lib.assertMsg (
     11   builtins.isString serviceName && builtins.match "^[a-z][a-z0-9_]*$" serviceName != null
     12 ) "serviceName must be a lowercase snake-case identifier";
     13 assert lib.assertMsg (lib.isDerivation toolchain) "toolchain must be a derivation";
     14 assert lib.assertMsg (
     15   builtins.isAttrs nativeInputs
     16   && (nativeInputs.schema or null) == "radroots.service.native-inputs.v1"
     17   && builtins.isList (nativeInputs.nativeBuildInputs or null)
     18   && builtins.isList (nativeInputs.buildInputs or null)
     19   && builtins.isAttrs (nativeInputs.environment or null)
     20 ) "nativeInputs must come from mkNativeInputs";
     21 assert lib.assertMsg (lib.all lib.isDerivation (
     22   nativeInputs.nativeBuildInputs ++ nativeInputs.buildInputs
     23 )) "nativeInputs must contain only derivations";
     24 assert lib.assertMsg (lib.all builtins.isString (
     25   builtins.attrValues nativeInputs.environment
     26 )) "nativeInputs.environment values must be strings";
     27 assert lib.assertMsg (lib.all (name: builtins.match "^[A-Za-z_][A-Za-z0-9_]*$" name != null) (
     28   builtins.attrNames nativeInputs.environment
     29 )) "nativeInputs.environment names must be shell identifiers";
     30 assert lib.assertMsg (lib.all (name: !(builtins.hasAttr name nativeInputs.environment)) [
     31   "CARGO"
     32   "PATH"
     33   "RUSTC"
     34   "RUSTC_WRAPPER"
     35   "RUSTC_WORKSPACE_WRAPPER"
     36   "RUSTUP_TOOLCHAIN"
     37 ]) "nativeInputs.environment must not replace the selected toolchain";
     38 pkgs.mkShell {
     39   name = "${serviceName}-dev-shell";
     40   packages = lib.unique ([ toolchain ] ++ nativeInputs.nativeBuildInputs);
     41   buildInputs = nativeInputs.buildInputs;
     42   shellHook = lib.concatStringsSep "\n" (
     43     lib.mapAttrsToList (
     44       name: value: "export ${name}=${lib.escapeShellArg value}"
     45     ) nativeInputs.environment
     46   );
     47 }