Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nix repl does not work with flakes #3803

Closed
Mic92 opened this issue Jul 12, 2020 · 16 comments · Fixed by #5027
Closed

Nix repl does not work with flakes #3803

Mic92 opened this issue Jul 12, 2020 · 16 comments · Fixed by #5027
Assignees
Labels
Milestone

Comments

@Mic92
Copy link
Member

Mic92 commented Jul 12, 2020

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?

@Mic92 Mic92 added the bug label Jul 12, 2020
@Mic92
Copy link
Member Author

Mic92 commented Jul 12, 2020

Current workaround:

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

@edolstra edolstra added improvement and removed bug labels Jul 16, 2020
@edolstra edolstra self-assigned this Jul 16, 2020
cruizh added a commit to cruizh/nix-dotfiles that referenced this issue Aug 25, 2020
@Ma27
Copy link
Member

Ma27 commented Dec 20, 2020

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
        '';
      };
  };
}

@edolstra edolstra added this to the nix-2.4 milestone Feb 12, 2021
craigem added a commit to IntersectMBO/cardano-node that referenced this issue Apr 12, 2021
jbgi pushed a commit to IntersectMBO/cardano-node that referenced this issue Apr 19, 2021
jbgi pushed a commit to IntersectMBO/cardano-node that referenced this issue Apr 20, 2021
@FlorianFranzen
Copy link
Contributor

Another issue I have in this regard is that getFlakes does not seem to ever provide self.rev or self.lastModified.

@edrex
Copy link

edrex commented Mar 10, 2022

How can :lf be used to load a particular output in a flake-based NixOS config?

> nix repl
Welcome to Nix 2.6.1. Type :? for help.

nix-repl> :lf /etc/nixos#myhost
error: unexpected fragment 'myhost' in flake reference '/etc/nixos#myhost'

@srid
Copy link

srid commented Mar 10, 2022

@edrex
image

@edrex
Copy link

edrex commented Mar 10, 2022

thanks @srid, I swear I tried that but it's working now.

@RuRo
Copy link

RuRo commented Jul 12, 2022

For anyone coming to this issue from google, I found that the most "elegant" solution is to set

nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];

in your system config, where inputs are the system flake inputs passed via specialArgs.

After that you can refer to the system version of nixpkgs as <nixpkgs> even without any channels configured. Also, legacy package stuff like the ability to do nix-shell -p netcat just works.

@anka-213
Copy link

anka-213 commented Oct 26, 2022

Could we also allow nix repl . or nix repl .#foo or something similar to work with flakes, so we don't need to manually type :lf . each time? I know it's a minor thing, but it would be nice to have.

If it's implemented it should hopefully be without removing the ability for nix repl . to work on non flake-based things with default.nix.

@thufschmitt
Copy link
Member

It is actually possible, but hidden behind the repl-flake experimental feature:

$ nix --extra-experimental-features repl-flake repl nixpkgs
Welcome to Nix 2.12.0pre20221025_899878f. Type :? for help.

Loading installable 'flake:nixpkgs#'...
Added 5 variables.
nix-repl>  legacyPackages.x86_64-linux.hello
«derivation /nix/store/c7jrxqjhdda93lhbkanqfs07x2bzazbm-hello-2.12.drv»

@andir
Copy link
Member

andir commented Nov 3, 2022

It is actually possible, but hidden behind the repl-flake experimental feature:

$ nix --extra-experimental-features repl-flake repl nixpkgs
Welcome to Nix 2.12.0pre20221025_899878f. Type :? for help.

Loading installable 'flake:nixpkgs#'...
Added 5 variables.
nix-repl>  legacyPackages.x86_64-linux.hello
«derivation /nix/store/c7jrxqjhdda93lhbkanqfs07x2bzazbm-hello-2.12.drv»

This doesn't seem to work with local flakes (nix repl .#) is that right or am I just unable to figure the syntax out?

@thufschmitt
Copy link
Member

This doesn't seem to work with local flakes (nix repl .#) is that right or am I just unable to figure the syntax out?

Strange, it seems to work for me:

$ nix repl --extra-experimental-features repl-flake .#
Welcome to Nix 2.12.0pre20221102_dd1970c. Type :? for help.

warning: Git tree '/home/thufschmitt/Repos/nixos/nix/work' is dirty
Loading installable 'git+file:///home/thufschmitt/Repos/nixos/nix/work#'...
Added 5 variables.
nix-repl> packages.x86_64-linux.nix
«derivation /nix/store/88cq60szkf0rg9a0ph6bgymqqi759rks-nix-2.12.0pre20221102_dirty.drv»

@andir
Copy link
Member

andir commented Nov 3, 2022

Yeah, I used flake-repl as feature and not repl-flake... It works now. I've grown blind to Nix throwing "warnings" at me (there are always some :/)

@charles-dyfis-net
Copy link

Absent that, one can use builtins.getFlake "git+file://${builtins.toString ./.}"

@sg-qwt
Copy link

sg-qwt commented Mar 16, 2023

I'm not sure if that's the intended behavior of repl-flake. When I run nix repl .#, only 5 variables added. I can get nixosCongirations etc. But when I run :lf .# inside repl of same repo, I get 17 variables added. Things like input are added only with :lf.

> nix repl .
Welcome to Nix 2.13.3. Type :? for help.

Loading installable 'git+file:///home/me/nixos#'...
Added 5 variables.
nix-repl> :lf .
Added 17 variables

@thufschmitt
Copy link
Member

@sg-qwt I don't think it is, indeed. Do you mind opening a specific issue for this?

@sg-qwt
Copy link

sg-qwt commented Mar 17, 2023

@sg-qwt I don't think it is, indeed. Do you mind opening a specific issue for this?

done. #8059

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.