Nixpkgs/Reviewing changes: Difference between revisions

From NixOS Wiki
imported>Artturin
No edit summary
Artturin (talk | contribs)
Add comments
 
(14 intermediate revisions by one other user not shown)
Line 1: Line 1:
1
Guides and examples for reviewing nixpkgs pull requests


== Packages ==
== Packages ==




=== Pre-flakes ===
<syntaxhighlight lang="nix">
nixpkgs.overlays = let
  owner = "Artturin";
  branchname = "cups-filters-update"; # branchname or rev
  pkgsReview = pkgs.fetchzip {
    url = "https://github.com/${owner}/nixpkgs/archive/${branchname}.tar.gz";
    # Change to 52 zeroes when the archive needs to be redownloaded
    sha256 = "sha256-/OR/uEqCy4QlManW9LcySsDXoTXFJ8G/xjhIsEpM4zM=";
  };
  # local checkout
  #pkgsReview = /home/artturin/nixgits/my-nixpkgs;
in [
  (self: super: {
    review = import pkgsReview { overlays = []; config = super.config; };
    cups-filters = self.review.cups-filters;
  })
];
</syntaxhighlight>
===mesa updates/changes===
i(Artturin) tested https://github.com/NixOS/nixpkgs/pull/160267 this way
this can also be used to test other changes for which overlaying would rebuild too many packages.
<syntaxhighlight lang="nix">
hardware.opengl = let
  patched-pkgs = import (pkgs.applyPatches {
    src = pkgs.path;
    patches = [
      (pkgs.fetchpatch {
      url = "https://github.com/NixOS/nixpkgs/commit/4e199a91dc49659ea3ecd7f8e174d6ade2a1d717.patch";
      sha256 = "sha256-xgZXntLx7U120RJ78RTw3+oSmlQ2qdwfVaLM+/H6ReA=";
      })
    ];
  }) { config = pkgs.config; };
in {
  package = patched-pkgs.mesa.drivers;
  package32 = patched-pkgs.pkgsi686Linux.mesa.drivers;
};
</syntaxhighlight>




== Modules ==
== Modules ==


=== Pre-flakes ===
You may use the rev instead of the branchname, the rev will get redownloaded when changed but the branch wont be redownloaded
You may use the rev instead of the branchname, the rev will get redownloaded when changed but the branch wont be redownloaded


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# if it is not a new module
disabledModules = [ "module.nix" ];
disabledModules = [ "module.nix" ];


imports = let
imports = let
  # If you need to use it for long term then use a fetcher which takes a hash
   pkgsReview = builtins.fetchTarball {
   pkgsReview = builtins.fetchTarball {
     url = "https://github.com/USERNAME/nixpkgs/archive/BRANCHNAME.tar.gz";
     url = "https://github.com/USERNAME/nixpkgs/archive/BRANCHNAME.tar.gz";
  #pkgsReview = ../nixpkgs;
   };
   };
in [
in [
Line 29: Line 73:


imports = let
imports = let
  # If you need to use it for long term then use a fetcher which takes a hash
   pkgsReview = builtins.fetchTarball {
   pkgsReview = builtins.fetchTarball {
     url = "https://github.com/Artturin/nixpkgs/archive/add-swap-options.tar.gz";
     url = "https://github.com/Artturin/nixpkgs/archive/add-swap-options.tar.gz";
  #pkgsReview = ../nixpkgs
   };
   };
in [
in [
Line 41: Line 87:
   ];
   ];


</syntaxhighlight>
=== Flakes ===
====Vm example====
run with
<syntaxHighlight lang=console>
$ nix run
</syntaxHighlight>
When the pull request is updated or forcepushed, run
<syntaxHighlight lang=console>
$ nix run --update-input pkgsReview
</syntaxHighlight>
To update the commit hash
<syntaxhighlight lang="nix">
{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.pkgsReview.url = "github:Artturin/nixpkgs/pipewirejackldpath";
  #inputs.pkgsReview.url = "/home/artturin/nixgits/my-nixpkgs";
  outputs = inputs@{ self, nixpkgs, pkgsReview }: {
    nixosConfigurations.vm = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs = { inherit inputs; };
      modules = [
        ({ pkgs, ... }: {
          disabledModules = [ "services/desktops/pipewire/pipewire.nix" ];
          imports = [
            "${inputs.pkgsReview}/nixos/modules/services/desktops/pipewire/pipewire.nix"
            # For virtualisation settings
            "${inputs.nixpkgs}/nixos/modules/virtualisation/qemu-vm.nix"
          ];
          services.pipewire.enable = true;
          # Documentation for these is in nixos/modules/virtualisation/qemu-vm.nix
          virtualisation = {
            memorySize = 1024 * 3;
            diskSize = 1024 * 3;
            cores = 4;
            msize = 104857600;
          };
          users.mutableUsers = false;
          users.users.root = {
            password = "root";
          };
          users.users.user = {
            password = "user";
            isNormalUser = true;
            extraGroups = [ "wheel" ];
          };
        })
      ];
    };
    # So that we can just run 'nix run' instead of
    # 'nix build ".#nixosConfigurations.vm.config.system.build.vm" && ./result/bin/run-nixos-vm'
    defaultPackage.x86_64-linux = self.nixosConfigurations.vm.config.system.build.vm;
    defaultApp.x86_64-linux = {
      type = "app";
      program = "${self.defaultPackage.x86_64-linux}/bin/run-nixos-vm";
    };
  };
}
</syntaxhighlight>
==== Testing the cross-compilation of modules ====
For example
an improved version can be found at https://github.com/NixOS/nixpkgs/pull/142273#issuecomment-948225922
<syntaxHighlight lang=console>
$ nix build .#nixosConfigurations.nixos.config.services.xserver.displayManager.sessionData.desktops
</syntaxHighlight>
<syntaxhighlight lang="nix">
{
  inputs = {
    nixpkgs.url = "github:ju1m/nixpkgs/display-managers";
  };
  outputs = inputs@{ self, nixpkgs }: {
    nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ({ pkgs, lib, config, ... }: {
          nixpkgs.crossSystem = lib.systems.examples.aarch64-multiplatform;
          services.xserver = {
            enable = true;
            desktopManager.session = [
              { name = "home-manager";
                start = ''
                  ${pkgs.runtimeShell} $HOME/.hm-xsession &
                  waitPID=$!
                '';
                bgSupport = true;
              }
            ];
          };
        })
      ];
    };
  };
}
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 17:01, 2 October 2024

Guides and examples for reviewing nixpkgs pull requests

Packages

Pre-flakes

nixpkgs.overlays = let
  owner = "Artturin";
  branchname = "cups-filters-update"; # branchname or rev
  pkgsReview = pkgs.fetchzip {
    url = "https://github.com/${owner}/nixpkgs/archive/${branchname}.tar.gz";
    # Change to 52 zeroes when the archive needs to be redownloaded
    sha256 = "sha256-/OR/uEqCy4QlManW9LcySsDXoTXFJ8G/xjhIsEpM4zM=";
  };
  # local checkout
  #pkgsReview = /home/artturin/nixgits/my-nixpkgs;
in [
  (self: super: {
    review = import pkgsReview { overlays = []; config = super.config; };
    cups-filters = self.review.cups-filters;
  })
];

mesa updates/changes

i(Artturin) tested https://github.com/NixOS/nixpkgs/pull/160267 this way this can also be used to test other changes for which overlaying would rebuild too many packages.

hardware.opengl = let
  patched-pkgs = import (pkgs.applyPatches {
    src = pkgs.path;
    patches = [
      (pkgs.fetchpatch {
      url = "https://github.com/NixOS/nixpkgs/commit/4e199a91dc49659ea3ecd7f8e174d6ade2a1d717.patch";
      sha256 = "sha256-xgZXntLx7U120RJ78RTw3+oSmlQ2qdwfVaLM+/H6ReA=";
      })
    ];
  }) { config = pkgs.config; };
in {
  package = patched-pkgs.mesa.drivers;
  package32 = patched-pkgs.pkgsi686Linux.mesa.drivers;
};


Modules

Pre-flakes

You may use the rev instead of the branchname, the rev will get redownloaded when changed but the branch wont be redownloaded

# if it is not a new module
disabledModules = [ "module.nix" ];

imports = let
  # If you need to use it for long term then use a fetcher which takes a hash
  pkgsReview = builtins.fetchTarball {
    url = "https://github.com/USERNAME/nixpkgs/archive/BRANCHNAME.tar.gz";
  #pkgsReview = ../nixpkgs;
  };
in [
  (import "${pkgsReview}/nixos/modules/module.nix")
];


for example

disabledModules = [ "config/swap.nix" "tasks/filesystems.nix" ];

imports = let
  # If you need to use it for long term then use a fetcher which takes a hash
  pkgsReview = builtins.fetchTarball {
    url = "https://github.com/Artturin/nixpkgs/archive/add-swap-options.tar.gz";
  #pkgsReview = ../nixpkgs
  };
in [
  (import "${pkgsReview}/nixos/modules/config/swap.nix")
  (import "${pkgsReview}/nixos/modules/tasks/filesystems.nix")
];

  swapDevices = [
    { "device" = "/swapfile"; "options" = [ "nofail" "noatime" ]; "priority" =  0; "discardPolicy" = "once"; }
  ];

Flakes

Vm example

run with

$ nix run

When the pull request is updated or forcepushed, run

$ nix run --update-input pkgsReview

To update the commit hash

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.pkgsReview.url = "github:Artturin/nixpkgs/pipewirejackldpath";
  #inputs.pkgsReview.url = "/home/artturin/nixgits/my-nixpkgs";

  outputs = inputs@{ self, nixpkgs, pkgsReview }: {

    nixosConfigurations.vm = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs = { inherit inputs; };
      modules = [
        ({ pkgs, ... }: {
          disabledModules = [ "services/desktops/pipewire/pipewire.nix" ];
          imports = [
            "${inputs.pkgsReview}/nixos/modules/services/desktops/pipewire/pipewire.nix"

            # For virtualisation settings
            "${inputs.nixpkgs}/nixos/modules/virtualisation/qemu-vm.nix"
          ];

          services.pipewire.enable = true;

          # Documentation for these is in nixos/modules/virtualisation/qemu-vm.nix
          virtualisation = {
            memorySize = 1024 * 3;
            diskSize = 1024 * 3;
            cores = 4;
            msize = 104857600;
          };

          users.mutableUsers = false;
          users.users.root = {
            password = "root";
          };
          users.users.user = {
            password = "user";
            isNormalUser = true;
            extraGroups = [ "wheel" ];
          };
        })
      ];
    };
    # So that we can just run 'nix run' instead of
    # 'nix build ".#nixosConfigurations.vm.config.system.build.vm" && ./result/bin/run-nixos-vm'
    defaultPackage.x86_64-linux = self.nixosConfigurations.vm.config.system.build.vm;
    defaultApp.x86_64-linux = {
      type = "app";
      program = "${self.defaultPackage.x86_64-linux}/bin/run-nixos-vm";
    };
  };
}

Testing the cross-compilation of modules

For example

an improved version can be found at https://github.com/NixOS/nixpkgs/pull/142273#issuecomment-948225922

$ nix build .#nixosConfigurations.nixos.config.services.xserver.displayManager.sessionData.desktops
{
  inputs = {
    nixpkgs.url = "github:ju1m/nixpkgs/display-managers";
  };

  outputs = inputs@{ self, nixpkgs }: {

    nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ({ pkgs, lib, config, ... }: {
          nixpkgs.crossSystem = lib.systems.examples.aarch64-multiplatform;
          services.xserver = {
            enable = true;
            desktopManager.session = [
              { name = "home-manager";
                start = ''
                  ${pkgs.runtimeShell} $HOME/.hm-xsession &
                  waitPID=$!
                '';
                bgSupport = true;
              }
            ];
          };
        })
      ];
    };
  };
}