Search code examples
rustnix

How to incorporate an arbitray nix flake into my flake dev shell with `mkShell`?


My rust dev shell flake.nix was:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    rust-overlay.url = "github:oxalica/rust-overlay";
  };

  outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }:
    let
      systems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ];
    in
    flake-utils.lib.eachSystem systems (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [ (import rust-overlay) ];
        };
      in
      {
        devShell = pkgs.mkShell {
          packages = [
            pkgs.rust-bin.nightly."2023-04-30".default
            pkgs.rust-analyzer
            pkgs.samply
          ];

          RUST_BACKTRACE = 1;
        };
      });
}

and .envrc was also as expected:

#!/usr/bin/env bash

use flake

Now I want to use Kani rust verifier on top of this environment. Luckily there is a flake wrapper nix-kani and it works:

$ nix shell github:fd/nix-kani

Is there a way to incorporate that flake into the mkShell environment? My attempt failed miserably:

@@ -5,5 +5,6 @@
     rust-overlay.url = "github:oxalica/rust-overlay";
+    nix-kani.url = "github:fd/nix-kani";
   };

-  outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }:
+  outputs = { self, nixpkgs, flake-utils, rust-overlay, nix-kani, ... }:
     let
@@ -17,2 +18,3 @@
         };
+        kani = import nix-kani { inherit system; };
       in
@@ -24,2 +26,3 @@
             pkgs.samply
+            kani.packages
           ];

Solution

  • You cannot import flakes like that. Inputs between outputs' arguments are already instanced.

    {
      inputs = {
        nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
        flake-utils.url = "github:numtide/flake-utils";
        rust-overlay.url = "github:oxalica/rust-overlay";
        nix-kani.url = "github:fd/nix-kani";
      };
    
      outputs = { self, nixpkgs, flake-utils, rust-overlay, nix-kani, ... }:
        let
          systems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ];
        in
        flake-utils.lib.eachSystem systems (system:
          let
            pkgs = import nixpkgs {
              inherit system;
              overlays = [ (import rust-overlay) ];
            };
          in
          {
            devShell = pkgs.mkShell {
              packages = [
                pkgs.rust-bin.nightly."2023-04-30".default
                pkgs.rust-analyzer
                pkgs.samply
                nix-kani.packages.${system}.kani
              ];
    
              RUST_BACKTRACE = 1;
            };
          });
    }
    

    (haven't tried it)