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, nixos-install: add support for --file and --attr flags #320462

Merged
merged 5 commits into from
Jul 14, 2024

Conversation

amozeo
Copy link
Contributor

@amozeo amozeo commented Jun 17, 2024

Description of changes

Allows building NixOS and using nixos-rebuild commands with a NixOS configuration located in plain nix file. This is useful for using nixos-rebuild command with a NixOS system configuration located in a nix file that is not a flake or a NixOS configuration module.

if you want to test this feature with your own configuration (if not using flakes), you can use this

{ nixosEval ? import <nixpkgs/nixos/lib/eval-config.nix> }:

nixosEval {
  modules = [( import <path/to/nixosConfiguration.nix> )];
}

NixOS configuration in plain nix file can be created using nixos function in nixpkgs, or importing and calling nixos/lib/eval-config.nix.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
    • nixos/tests/installer.nix simple
    • nixos/tests/installer.nix switchToFlake
    • nixos/tests/installer.nix switchToByAttr (new test)
    • nixos/tests/installer.nix switchFromByAttrToFlake (new test)
    • made sure NixOS tests are linked to the relevant packages
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

maintainer mention: @Profpatsch


Add a 👍 reaction to pull requests you find important.

in "building nix" section, removes indent clutter
adds support of building system from nix file and attrPath directly

these are --file and --attr flags in nix-build respectfully
…rse meaning

to "withTestInstrumentation", which reflects what this argument does
@amozeo amozeo force-pushed the pkgs/nixos-rebuild/by-attr branch from fdc4ecf to d77469c Compare July 10, 2024 19:00
@amozeo amozeo changed the title nixos-rebuild: add support for --file and --attr flags nixos-rebuild, nixos-install: add support for --file and --attr flags Jul 11, 2024
@amozeo amozeo force-pushed the pkgs/nixos-rebuild/by-attr branch from 79a9a75 to eeb1dff Compare July 11, 2024 19:34
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/4235

Copy link
Member

@AndersonTorres AndersonTorres left a comment

Choose a reason for hiding this comment

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

Looks very nice!

@tomberek
Copy link
Contributor

Result of nixpkgs-review pr 320462 run on x86_64-linux 1

2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test
5 packages built:
  • nixos-rebuild
  • tests.testers.lycheeLinkCheck.network
  • tests.testers.nixosTest-example
  • tests.testers.runNixOSTest-example
  • tests.trivial-builders.references

Copy link
Contributor

@tomberek tomberek left a comment

Choose a reason for hiding this comment

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

Builds, runs, tests as expected.

@infinisil
Copy link
Member

This is awesome! I just opened #333788 to take this to the next step, but unfortunately I don't have the time to pull it through, so I'd appreciate if you could help out with that @amozeo 🙏

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

Successfully merging this pull request may close these issues.

None yet

5 participants