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

outputs: make compatible with nix run and package lists #842

Merged
merged 3 commits into from
Nov 8, 2024

Conversation

iFreilicht
Copy link
Contributor

This adds new outpus like diskoFormat and diskoFormatNoDeps which are compatible with nix run so you can do something like

nix run .#nixosConfigurations.myhostname.config.system.build.diskoFormatNoDeps

as originally intended in #78, or add disko to your configuration like

environment.systemPackages = [
    config.system.build.diskoFormat
    config.system.build.diskoMount
    config.system.build.diskoDisko
];

as mentioned in #454.

The old outputs are marked as deprecated and a warning like this is shown to the user:

# nix run .#nixosConfigurations.testmachine.config.system.build.mountScript
trace: evaluation warning: 
The output .mountScript is deprecated in favor of .diskoMount and will be removed in
version 2.0.0! To fix this issue, you need to do the following:
  - If you're currently calling "$‍{system.build.mountScript}" as a script,
    use "$‍{system.build.diskoMount}/bin/disko-mount" instead!
  - If you added "system.build.mountScript" to your systemPackages, users.<name>.packages
    or home.packages, or used it with buildEnv or mkShell, this has never worked
    and using "system.build.diskoMount" will fix it.

error: unable to execute '/nix/store/c48m5ffrfzhgsri19b4mlzlbv31ba8yg-disko-mount/bin/disko-mount': Not a directory

Fixes part of #454 (which then only requires proper documentation)
Supersedes #78

@Mic92 I know you suggested in #78 (comment) to use diskoRecreate, but I think as long as we still have --mode disko, we should keep it consistent, so I went for diskoDisko instead. This also helps differentiate this output from the regular disko, which is the CLI.

@Mic92
Copy link
Member

Mic92 commented Oct 19, 2024

Well we can also call it recreate in the cli, while still allowing user the old name. diskoDisko looks weird and the mode disko was never really descriptive to begin with.

@Mic92
Copy link
Member

Mic92 commented Oct 19, 2024

I also would prefer to not have the warning in the beginning until we have also migrated the nixos-anywhere executable to it. We can add the warning later when also nixos-stable no longer has the old nixos-anywhere version to avoid showing users warnings they cannot silence.

@Enzime
Copy link
Member

Enzime commented Oct 19, 2024

Would love to see a new mode or maybe a flag for the disko/recreate script that doesn’t wipe the partition table as create is kinda idempotent now, I think this mode would be quite useful with nixos-anywhere as a create/update + mount

@Mic92
Copy link
Member

Mic92 commented Oct 19, 2024

@Enzime that mode already exists afaik and it's called format. We just don't advertise it widely as we suspect unsolved edge cases.

@Enzime
Copy link
Member

Enzime commented Oct 19, 2024

I thought format doesn't mount the filesystems afterwards

@iFreilicht
Copy link
Contributor Author

I also would prefer to not have the warning in the beginning until we have also migrated the nixos-anywhere executable to it. We can add the warning later when also nixos-stable no longer has the old nixos-anywhere version to avoid showing users warnings they cannot silence.

That's a good point, I'll split those into a separate PR.

Well we can also call it recreate in the cli, while still allowing user the old name. diskoDisko looks weird and the mode disko was never really descriptive to begin with.

That's a good point, and I agree, we should do that. I think I would like to take this opportunity to integrate a solution for #725, which is to simply display a warning when running the "recreate" mode that all disks will be wiped, and asking for confirmation. This dialogue can be skipped with the new flag --force-wipe-disks, and will only appear for --mode recreate, not --mode disko.

Would you agree with that change?

Would love to see a new mode or maybe a flag for the disko/recreate script that doesn’t wipe the partition table as create is kinda idempotent now, I think this mode would be quite useful with nixos-anywhere as a create/update + mount

Hmm, this makes me feel like we might want to make the names of our modes more direct. Instead of inventing new names for joint modes, why don't we just leave the base modes named destroy, format and mount, and allow passing the following values to --mode:

  • destroy,format,mount - what disko currently does
  • format,mount - the new mode @Enzime suggested
  • format - unchanged
  • mount - unchanged

The outputs would then be:

  • diskoDestroyFormatMountScript
  • diskoFormatMountScript
  • diskoFormatScript
  • diskoMountScript
  • diskoDestroyFormatMountScriptNoDeps
  • diskoFormatMountScriptNoDeps
  • diskoFormatScriptNoDeps
  • diskoMountScriptNoDeps

This isn't pretty, but it sure as hell is clear.

lib/default.nix Outdated
export PATH=${lib.makeBinPath (cfg.config._packages pkgs)}:$PATH
${cfg.config._mount}
'';
diskoDisko = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "/bin/disko-disko" ''
Copy link
Member

@Mic92 Mic92 Oct 22, 2024

Choose a reason for hiding this comment

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

Suggested change
diskoDisko = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "/bin/disko-disko" ''
disko = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "/bin/disko-destroy-format-mount" ''

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that's a good idea. We can call the output destroyFormatMount, but just calling it disko makes it too confusing what it's supposed to be, and goes against your other idea of making the outputs a generic interface that has nothing to do with disko directly.

The only output I would expect to be called disko is the CLI.

@iFreilicht iFreilicht mentioned this pull request Oct 22, 2024
@iFreilicht iFreilicht force-pushed the write-scripts-to-bin-dir branch 2 times, most recently from e194cdf to 2d52a42 Compare October 22, 2024 21:13
@iFreilicht
Copy link
Contributor Author

As I hinted at yesterday, I now used the opportunity to integrate a confirmation dialogue into the modes destroy and destroy,format,mount, which fixes #725.

The existing disko mode is not affected.

I can also split this into a separate PR, but I wanted to avoid having a state on master that is forwards-incompatible with this.

@iFreilicht
Copy link
Contributor Author

I'll fix the build errors soon, gotta go to bed now, but would appreciate feedback on the changes.

@Mic92
Copy link
Member

Mic92 commented Oct 23, 2024

Sorry, currently busy with NixCon preparation. I would like to get back to this later.

@iFreilicht iFreilicht force-pushed the write-scripts-to-bin-dir branch 4 times, most recently from 438f83a to 08d39ae Compare October 25, 2024 08:28
@Lassulus
Copy link
Collaborator

Lassulus commented Nov 5, 2024

changes look good to me, I haven't tested everything though, but it seems like there are no breaking changes and CI is happy.
What would be interesting (in the future in a new PR) would be a real unmount mode, where we don't destroy disks but just umount -Rl and deactivate the LVM/mdadm stuff for affected devices, something similiar to disk-deactivate but less destructive :)

This adds new outpus like `format` and `formatNoDeps` which
are compatible with `nix run` so you can do something like

    nix run .#nixosConfigurations.myhostname.config.system.build.formatNoDeps

as originally intended in #78, or add disko to your configuration like

    environment.systemPackages = [
        config.system.build.format
        config.system.build.mount
        config.system.build.destroyFormatMount
    ];

as mentioned in #454.

Fixes part of #454
Supersedes #78

It also deprecates mode `disko` in favor of the clearer
`destroy,format,mount` and adds `format,mount` to allow easier in-place
updates.
The new confirmation dialogue is only shown for the new outputs
introduced in the previous commits. The existing outputs do not change
behavior to keep backwards compatibility.

Fixes #725
I believe that people are either using disko through the flake or via
nixpkgs. In both cases, the `default.nix` file contains a lot of outputs
that are not needed.

Adding scary error messages with a call to action like this should help
confirm or deny this theory.
@iFreilicht iFreilicht force-pushed the write-scripts-to-bin-dir branch from 08d39ae to 3fc91a7 Compare November 6, 2024 20:16
@iFreilicht iFreilicht mentioned this pull request Nov 6, 2024
@iFreilicht
Copy link
Contributor Author

iFreilicht commented Nov 6, 2024

Alright I addressed the last few comments and rebased on master. Once this is merged, I'll open a new issue regarding how we handle the deprecation etc. to make sure an updated version of nixos-anywhere is released before then.

@Mic92 Mic92 merged commit 60d4914 into master Nov 8, 2024
3 checks passed
@Mic92 Mic92 deleted the write-scripts-to-bin-dir branch November 8, 2024 05:57
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