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

enable nix run #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

enable nix run #78

wants to merge 2 commits into from

Conversation

archite
Copy link

@archite archite commented Dec 13, 2022

Is there a reason why something like this is not done so that nix run .#nixosConfigurations.myhostname.config.system.build.diskoNoDeps could setup disks prior to nixos-install --flake .#myhostname? This saves running build and then the result script.

Great work. Thanks for your effort.

@Mic92
Copy link
Member

Mic92 commented Dec 13, 2022

Currently was mainly used by the disko cli (which might be also need to be fixed as a result of this)

@Mic92
Copy link
Member

Mic92 commented Dec 15, 2022

This line needs to be fixed as well:

disko/disko

Line 124 in 935feb7

exec "$script"

@archite
Copy link
Author

archite commented Jan 28, 2023

Looking at it, it only looks like this change would affect the nixosModule. I've been using this in my flake outputs as a workaround but not ideal.

apps = forAllSystems (system: let
  pkgs = nixpkgs.legacyPackages.${system};
  hosts = pkgs.lib.filterAttrs (_: value:
    value.pkgs.system == system &&
    builtins.hasAttr "diskoNoDeps" value.config.system.build
  ) self.nixosConfigurations;
in
  if (hosts == {}) then {} else {
  disko = pkgs.lib.genAttrs (builtins.attrNames hosts) (name:
    {
      program = "${self.nixosConfigurations.${name}.config.system.build.diskoNoDeps}";
      type = "app";
    });
  }
);

@iFreilicht
Copy link
Contributor

This change makes disko incompatible with nixos-anywhere, which calls the script directly.

That's a solvable problem, but I don't see much use in changing this now. These scripts are not supposed to be called directly by a user anyway. Unless there's a good reason to get this change merged, I'd vote for closing this PR.

@iFreilicht iFreilicht added the stale No activity for a long time, might be irrelevant. PRs with this label may be closed after a while label Sep 20, 2024
@Enzime
Copy link
Contributor

Enzime commented Sep 21, 2024

As someone who doesn't use the disko CLI, I personally would like the ability to run nix run github:Enzime/dotfiles-nix#nixosConfigurations.host.config.system.build.formatScript, this would make it super easy to execute from a NixOS live installer for example

@iFreilicht iFreilicht removed the stale No activity for a long time, might be irrelevant. PRs with this label may be closed after a while label Sep 21, 2024
@iFreilicht
Copy link
Contributor

Okay good to know, thank you. I'm concerned about backwards compatibility, what could we do so we don't break compatibility with nixos-anywhere? Maybe we should submit a PR to them that detects if formatScript is a file or folder and then executes either formatScript or formatScript/bin/format?

@Enzime
Copy link
Contributor

Enzime commented Sep 21, 2024

I think the actual root cause is that nix run should support executing executable files, rather than forcing all of them to follow the structure bin/<meta.mainProgram>

But that would probably be the easiest solution

cc @Mic92 with his nixos-anywhere maintainer hat on

@iFreilicht
Copy link
Contributor

How easy is it right now to get PRs merged in NixCpp? Haven't followed the development for a while, but this would be relatively simple to implement. Just add some additional logic here: https://github.com/NixOS/nix/blob/68ba6ff4709d936c1a714de35da08f8ed354c710/src/nix/app.cc#L118

@@ -20,23 +20,23 @@ in {
};
};
config = lib.mkIf (cfg.devices.disk != {}) {
system.build.formatScript = pkgs.writers.writeBash "disko-create" ''
system.build.formatScript = pkgs.writers.writeBashBin "disko-create" ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we switch to this, we should make new attributes and make the old "script" ones execute those with a warning using lib.warn. This would give us time to migrate tools like nixos-anywhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also diskoNoDeps is the only thing used by nixos-anywhere, we still have nixpkgs with the old disko cli around.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like:

  • diskoFormat, diskoMount, diskoRecreate, diskoRecreateNoDeps

@Enzime
Copy link
Contributor

Enzime commented Sep 21, 2024

@iFreilicht I think a simple PR for nix run could get through pretty quickly if you update docs and tests

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

Successfully merging this pull request may close these issues.

4 participants