{ # Customizes an existing package with `overrideAttrs` and verifies that # the override changes the package's runtime behavior. description = "Customize an existing package with overrideAttrs"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; }; outputs = { self, nixpkgs, ... }: let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; customizedHello = pkgs.hello.overrideAttrs (old: { pname = "hello-override"; nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.makeWrapper ]; postInstall = (old.postInstall or "") + '' wrapProgram $out/bin/hello \ --add-flags "--greeting=hello-from-overrideAttrs" ''; }); in { packages.${system}.default = customizedHello; apps.${system}.default = { type = "app"; program = "${self.packages.${system}.default}/bin/hello"; meta.description = "Run GNU hello with a greeting injected by overrideAttrs."; }; checks.${system}.greeting = pkgs.runCommand "hello-override-check" { } '' output="$(${self.packages.${system}.default}/bin/hello)" if [ "$output" = "hello-from-overrideAttrs" ]; then echo ok > "$out" else echo "unexpected output: $output" >&2 exit 1 fi ''; }; }