-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
nixos-rebuild: Support system.nix
by default
#333788
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
base: master
Are you sure you want to change the base?
Conversation
In bash it's convention for "" to represent false, and "1" true. The `buildingAttribute` variable didn't honor that before.
Otherwise we'd run into trouble when a filename contained e.g. a space
To more accurately represent what it does
Opens the file that would be built from
Previously, `nixos-rebuild -A foo` would build the `default.nix` in the current directory, while `nixos-rebuild` without `-A` would not use file-based building at all. This difference compared to what `nix-build` would do is confusing. Furthermore, using `default.nix` is not great, because there's many of those files all around, and they're almost never for NixOS. This commit fixes those two issues by: - Removing support for using `default.nix` as a default when using `--attr` - If it exists, using the `<nixos-system>` entry in NIX_PATH as the default - Otherwise, use the `system.nix` file in the current directory or any of its parents, if it exists, as a default - Otherwise, use `/etc/nixos/system.nix` as a default While `system.nix` could be conflated with the `system` Nixpkgs argument, there's no practical way for this to cause problems, because `system` is never specified in a file. Having this finally allows using `nixos-rebuild` without any arguments and without any `NIX_PATH` entries, effectively a way to declaratively use NixOS from just /etc/nixos!
hey @infinisil, I wrote tests for configuration detection. I think you might be interested looking into it |
@amozeo Neat idea, it seems to work well with |
@infinisil how I should split it then? |
Honestly #327740 seemed fine to me. I guess it would be best to have this PR first though. I'm unfortunately a bit low on time right now, so I'd appreciate if you could help out! In particular I think this PR should get done before the release in ~2 months, because I don't think the current behavior regarding |
We should probably get this moving if we want to make it before next release right? |
# Hardcoded to /etc/nixos/system.nix | ||
if [[ -f "/etc/nixos/system.nix" ]]; then | ||
buildFile=/etc/nixos/system.nix | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this path should be hardcoded in nixos-rebuild. Setup with channels doesn't have /etc/nixos/configuration.nix hardcoded and uses nixos-config in NIX_PATH
instead to find its configuration there. If the /etc/nixos/system.nix must be hardcoded, it should be in NixOS modules instead, similar to channel setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flake path /etc/nixos/flake.nix
is hardcoded in nixos-rebuild
, I don't think the issue that I brought up has any significance anymore
@infinisil I have force-updated the branch on my fork that I linked before.
|
Doesn't hurt to open the PR right now as all of them together, and then you can split them later if required. |
Bump :P 24.11 is rapidly approaching |
We’re in feature freeze, so this would need @RossComputerGuy’s sign‐off even if it wasn’t a draft. Probably just removing the |
Yeah, let's kill the default.nix post release. This should be fine. |
bump :P |
My 2c as a big fan of "flake-less, channel-less" model: this is a great change. Would we like to default to building Are there any plans to make In other words, do we see a future where perhaps let
nixpkgs = <nixpkgs>; # keeping compat with the "channelful" model by default
in
import "${nixpkgs}/nixos/lib/eval-config.nix" {
system = null;
modules = [
./configuration.nix
];
} and this becomes a supported/recommended approach? Let me know if this issue is not a place to discuss this, I'll make a new one. I'm just curious and excited about any ways to demystify the NixOS build process and decouple it somewhat from |
I created #389487 that addresses issues pointed out in this pull request. |
Description of changes
(in addition to various minor improvements)
Previously,
nixos-rebuild -A foo
would build thedefault.nix
in the current directory, whilenixos-rebuild
without-A
would not use file-based building at all.This difference compared to what
nix-build
would do is confusing. Furthermore, usingdefault.nix
is not great, because there's many of those files all around, and they're almost never for NixOS.This PR fixes those two issues by:
default.nix
as a default when using--attr
, this is a breaking change, but support for this has not made it to a stable branch<nixos-system>
entry in NIX_PATH as the default if it existssystem.nix
file in the current directory or any of its parents, if it exists, as a default/etc/nixos/system.nix
as a defaultWhile
system.nix
could be conflated with thesystem
Nixpkgs argument, there's no practical way for this to cause problems, becausesystem
is never specified in a file.Having this finally allows using
nixos-rebuild
without any arguments and without anyNIX_PATH
entries, effectively a way to declaratively use NixOS withoutnix-channel
!I think it's important to get this for the next release, so that we don't bake in stability for the
default.nix
behavior.Unfortunately I'm a bit low on time, but if @amozeo (who pioneered the file-based building with #320462) could take this PR to its conclusion I'd be very grateful!
Things done
Add a 👍 reaction to pull requests you find important.