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

nixos-rebuild: add edit command #56241

Merged
merged 1 commit into from
Feb 24, 2019
Merged

nixos-rebuild: add edit command #56241

merged 1 commit into from
Feb 24, 2019

Conversation

LnL7
Copy link
Member

@LnL7 LnL7 commented Feb 23, 2019

Motivation for this change

Inspired by LnL7/nix-darwin#94.

As a user I don't want to remember where the configuration exists. This
adds a command that will point the $EDITOR to the file.

/cc @zimbatm

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@LnL7 LnL7 requested a review from infinisil as a code owner February 23, 2019 13:35
@GrahamcOfBorg GrahamcOfBorg added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Feb 23, 2019
Copy link
Member

@zimbatm zimbatm left a comment

Choose a reason for hiding this comment

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

thanks for doing this

nixos/modules/installer/tools/nixos-rebuild.sh Outdated Show resolved Hide resolved
if [ "$action" = edit ]; then
NIXOS_CONFIG=${NIXOS_CONFIG:-$(nix-instantiate --eval --strict -E '<nixos-config>')}
exec "${EDITOR:-nano}" "$NIXOS_CONFIG"
exit 1
Copy link
Member

Choose a reason for hiding this comment

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

I'm no bash guru, but I thought exec would relinquish all control, so this line won't ever be executed anyways (and won't be needed), or does it serve any purpose?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've seen this pattern in multiple languages. I'm not sure if there is some weird case that this actually handles or if it's just for clarity.

Copy link
Contributor

Choose a reason for hiding this comment

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

so this line won't ever be executed anyways

If the exec call itself fails for some reason (e.g. an EDITOR that is not available), the script would continue and the exit 1 forces an exit. So in general, this makes sense. But in this particular case it's not necessary because set -e at the beginning forces global exit-on-error anyway. But it doesn't hurt either 😄

@LnL7 LnL7 force-pushed the nixos-rebuild-edit branch from 764bbf5 to 49c4d61 Compare February 24, 2019 11:23
@xeji xeji merged commit 50fec3d into NixOS:master Feb 24, 2019
@infinisil
Copy link
Member

Oh, this should really have a release note though

@LnL7
Copy link
Member Author

LnL7 commented Feb 25, 2019

I'll make another pr for the changelog and docs.

@LnL7 LnL7 deleted the nixos-rebuild-edit branch February 25, 2019 07:38
@ElvishJerricco
Copy link
Contributor

Don't some flags (e.g. --option, -I) need to be passed to the nix-instantiate call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants