Nix: Nix repl does not work with flakes

Created on 12 Jul 2020  路  2Comments  路  Source: NixOS/nix

Describe the bug

Before it was possible to use to use nix repl <nixpkgs/nixos> to get nixos in a repl.

This seems not possible anymore with flakes nix repl ".#":

Welcome to Nix version 2.4pre20200622_334e26b. Type :? for help.

Loading '.#'...
error: --- SysError ----------------------------------------------------------- nix
getting status of '/home/joerg/.homesick/repos/dotfiles/.#': No such file or directory

How do I load flakes in a nix repl?

improvement

Most helpful comment

FWIW, if a snippet like this in your flake.nix you can also do nix run .#repl:

{
  outputs = { flake-utils, ... }: {
      apps.repl = flake-utils.lib.mkApp {
        drv = pkgs.writeShellScriptBin "repl" ''
          confnix=$(mktemp)
          echo "builtins.getFlake (toString $(git rev-parse --show-toplevel))" >$confnix
          trap "rm $confnix" EXIT
          nix repl $confnix
        '';
      };
  };
}

All 2 comments

Current workaround:

cat > ./nixos-config.nix <<EOF
(builtins.getFlake (toString ./.)).nixosConfigurations.turingmachine
EOF
nix repl ./nixos-config.nix

FWIW, if a snippet like this in your flake.nix you can also do nix run .#repl:

{
  outputs = { flake-utils, ... }: {
      apps.repl = flake-utils.lib.mkApp {
        drv = pkgs.writeShellScriptBin "repl" ''
          confnix=$(mktemp)
          echo "builtins.getFlake (toString $(git rev-parse --show-toplevel))" >$confnix
          trap "rm $confnix" EXIT
          nix repl $confnix
        '';
      };
  };
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

domenkozar picture domenkozar  路  53Comments

matthewbauer picture matthewbauer  路  64Comments

lukego picture lukego  路  34Comments

taktoa picture taktoa  路  35Comments

cbarrett picture cbarrett  路  49Comments