gytis-ivaskevicius / flake-utils-plus

Use Nix flakes without any fluff.
MIT License
485 stars 57 forks source link

Update repl.nix implementation #62

Closed gytis-ivaskevicius closed 3 years ago

gytis-ivaskevicius commented 3 years ago

Changes required:

More or less fixes https://github.com/divnix/digga/issues/17

blaggacao commented 3 years ago

Turn it into a tiny overlay that is added by default. Maybe package name should be fup-repl, exec name repl? Any thoughts?

I'm still trying to find a good reason for why it's not best option to keep it as a lib.

I think there are two broader use cases:

For "play the flake", self.pkgs is probably fine to discover available packages.

For "play the host", I have no clear picture of what a user would want to do host-specific that only can be something with that particular config, right? I'm still repl-blind. Although, then self.nixosConfigurations would satisfy that need?

gytis-ivaskevicius commented 3 years ago

I don't think I quite get your point. Mind elaborating on "play the host"? In case you are wondering why is it host aware - the explanation is simple: It is convenient to have a system config (parsed options) exported to inspect :)

blaggacao commented 3 years ago

In case you are wondering why is it host aware - the explanation is simple: It is convenient to have a system config (parsed options) exported to inspect :)

That was it! :+1:

Would it make sense to provide a configs that holds all parsed config per host or something?

So to remain host aware, but make the repl itself only flake specific.

hazelweakly commented 3 years ago

For reference, I borrowed heavily from this repo's repl.nix when designing one for a non nixos config project

let
  flake = builtins.getFlake (builtins.toString ../.);
  nixpkgs = flake.outputs.legacyPackages."${builtins.currentSystem}";
in {
  inherit flake;
} // flake // builtins // (builtins.removeAttrs nixpkgs [ "config" ])
// nixpkgs.lib

Essentially the difference is that it references the flake by path instead of self and doesn't overlay flake.nixosConfigurations. It's been quite helpful. I use it as nix run .#repl for this project where the app is shell script that runs the command nix repl "$(git rev-parse --show-toplevel)"/nix/repl.nix, but adding that shell script as a package is another alternative I suppose.

gytis-ivaskevicius commented 3 years ago

@blaggacao I guess the other option would be to just do // flake.nixosConfigurations this way you'd access the config via <hostname>.config. Tho, I'd really rather stick with just config, it's just less bothersome.

@jared-w This implementation is quite slow, not only often wait to evaluate/build the repl app but also more often than not flake evaluation itself is not going to be cached :/ So yeah, you might want to tweak it a little.

The idea of using self is that it just grabs the last successful build of your config. And I believe that $ repl /path/to/flake.nix pretty much resolves your use case as well! :)

gytis-ivaskevicius commented 3 years ago

Oh, right @blaggacao - from my example above I did mean that in case the path is defined - repl is going to be flake specific as you just now. Otherwise it just assumes system flake

gytis-ivaskevicius commented 3 years ago

Some work was done on this. What still needs to be implemented: