-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
Flake support #68897
Flake support #68897
Conversation
flake.nix
Outdated
|
||
outputs = { self }: | ||
let | ||
pkgs = import ./. { system = "x86_64-linux"; }; |
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.
does this mean we currently can't use the nixpkgs flake from any non-x86 system?
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.
Not from the nix
command line. You can call it from other flakes with a non-x86_64-linux system argument though.
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.
Can't we use builtins.currentSystem?
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.
Nope, not in pure evaluation mode.
$ nix eval "(builtins.currentSystem)"
error: attribute 'currentSystem' missing, at (string):1:2
$ nix eval --impure "(builtins.currentSystem)"
"x86_64-linux"
I myself had a slightly different take on The idea is that you ou can do:
or in two steps:
E.g. a nixos flake returns a Would such a thing be more ergonomic? It would also mean you don't need Of course this is a bit of a backwards incompatible change, but we could also keep the old What do you think? |
@arianvp Well, you already don't need
which is just what Edit: or indeed
as you suggested. |
Update: added flake support to |
Well and you have to |
flake.nix
Outdated
legacyPackages = pkgs; | ||
|
||
nixosModules = { | ||
notDetected = ./nixos/modules/installer/scan/not-detected.nix; |
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.
Why include this?
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.
Note: NIX_PATH is unavailable in flake-based builds.
Should we add other modules as well? For example, I use the following imports on my server:
<nixpkgs/nixos/modules/profiles/minimal.nix>
<nixpkgs/nixos/modules/virtualisation/container-config.nix>
<nixpkgs/nixos/modules/installer/cd-dvd/channel.nix>
1028bb3
to
4a4e146
Compare
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/building-nixos-system-with-nix-build-and-a-channel-specifier/4747/2 |
And also --refresh and --no-net.
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.
Would be happy to see this merged. However, I'm afraid that the FIXME's in here will never get fixed once this is merged. We depend on the nixos-rebuild re'execing currently, so that fixme would be a blocker for moving to flakes for us, personally.
# Re-execute nixos-rebuild from the Nixpkgs tree. | ||
if [ -z "$_NIXOS_REBUILD_REEXEC" -a -n "$canRun" -a -z "$fast" ]; then | ||
# FIXME: get nixos-rebuild from $flake. |
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.
This is important for my workflow
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.
The re-exec is fundamentally broken anyway, since it tries to build nixos-rebuild
with the old Nix. (The code to upgrade Nix happens later.) We could do nix build $flake#nixosConfigurations.$flakeAttr.config.system.build.nixos-rebuild
but I don't think it's useful currently.
@@ -296,7 +347,8 @@ prebuiltNix() { | |||
|
|||
remotePATH= | |||
|
|||
if [ -n "$buildNix" ]; then | |||
# FIXME: get nix from the flake. |
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.
FIXME: get nix from the flake.
(defined $configFile && $configFile ne "")) { | ||
writeNixOSConfig $nixosConfigFile; | ||
# Unless overriden on the command line, rebuild the flake recorded | ||
# in the container config file. FIXME: read the container config |
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.
fixme: read the container config in a more sensible way
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.
^
if [[ -z $flake ]]; then | ||
pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A vm -k "${extraBuildFlags[@]}")" | ||
else | ||
echo "TODO: not implemented" >&2 |
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.
todo: not implemented
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.
Not supporting nixos vm builds will ensure limited flake adoption.
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 haven't used build-vm in years.
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 use it almost all the time, to do integration tests of modules. It's fairly prominent in the documentation and one of nixos's selling points.
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.
Sure, but nixos-rebuild build-vm
is just a wrapper around nix build
. It doesn't do anything you couldn't otherwise do.
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've used build-vm to test the many many PRs that I've reviewed, merged, and tested. It's a very very useful tool for me.
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.
Do you mean people can just do?
nix run vm -f '<nixpkgs/nixos>' --arg configuration "$PWD/configuration.nix" -c run-nixos-vm
if [[ -z $flake ]]; then | ||
pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A vmWithBootLoader -k "${extraBuildFlags[@]}")" | ||
else | ||
echo "TODO: not implemented" >&2 |
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.
todo: not implemented
I feel very conflicted about making this change now, when not only have we still not decided on the format for flake.nix, but the RFC seems to have been stalled for months… |
"master" is not a valid SHA-1 commit hash, and it's not even necessarily the branch used. 'nixos-version --revision' now returns an error if the commit hash is not known.
Yes, you can do |
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 would like to know how we deal on the stable with changes to e.g. the Flake format. Can it be relied on being stable during the lifetime of 20.03, or is it consider experimental? Probably needs a release note either way, clarifying this.
This doesn't work in pure mode.
I've added a note that it's experimental (so it shouldn't be relied on). |
Nixpkgs.lib.nixosSystem already exists as pkgs.nixos Iirc nixpkgs.nixos is explicitly mentioned in our documentation too I already noted this in November. But no reply. Could we still address this? |
Ideally we would remove |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/pinning-configuration-nix-with-niv/49031/4 |
Motivation for this change
This PR:
flake.nix
file to Nixpkgs, making Nixpkgs usable from other flakes.nixos-rebuild
, enabling hermetic NixOS builds.nixos-container
.A typical NixOS system configuration flake looks like this:
which can be installed by doing
(
--config
defaults to the host name so it can usually be omitted).The option
system.configurationRevision
tracks the revision of the top-level flake. This allows the entire configuration to be reproduced reliably. In a running system, it can be queried usingnixos-version
:$ nixos-version --json | jq -r .configurationRevision 2c475bc41c13e7a9ae5c16b6c10d8d328cd07ee7
Note:
NIX_PATH
is unavailable in flake-based builds. In particular this means thatin
hardware-configuration.nix
no longer works. Instead you have to usenixos-container
also supports flakes. For example, the following command creates a container that serves the NixOS homepage:TODO: add flake support to
nixos-install
, add tests.Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)Notify maintainers
cc @