overlay: make finalNix depend on the nix version being used by a package #37

Closed
fabianhjr wants to merge 0 commits from fabianhjr/nixos-module:dynamic-nix-choice into main
Contributor

This should address both of the following (where 35 is more general and 36 a specific case)

This should address both of the following (where 35 is more general and 36 a specific case) - https://git.lix.systems/lix-project/nixos-module/issues/35 - https://git.lix.systems/lix-project/nixos-module/issues/36
fabianhjr added 1 commit 2024-09-26 03:24:32 +00:00
This should address both of the following (were 35 is more general and
36 a specific case)

- #35
- #36
Author
Contributor

Please let me know if there is a contributing guide (didn't find one on this repo unu) or if there is anything I should do/change.

Please let me know if there is a contributing guide (didn't find one on this repo unu) or if there is anything I should do/change.
jade reviewed 2024-09-26 20:42:23 +00:00
overlay.nix Outdated
@ -68,0 +68,4 @@
# Get the two common inputs of a derivation/package.
inputs = prev.${name}.buildInputs ++ prev.${name}.nativeBuildInputs;
nixDependency = lib.findFirst
(drv: lib.hasPrefix "nix-2." drv.name)
Owner

i think we can just look at pname/version (in a safely-fallible manner; drv.pname ? "" should be fine for this purpose), since these are nixpkgs derivations. that should make it a little safer for stuff like the prefixes added by cross compilation.

i think we can just look at pname/version (in a safely-fallible manner; `drv.pname ? ""` should be fine for this purpose), since these are nixpkgs derivations. that should make it a little safer for stuff like the prefixes added by cross compilation.
Author
Contributor

tried pname first but isn't available :C

Lix 2.92.0-dev-pre20240917-8ab5743
Type :? for help.
nix-repl> :lf ./                                                                                                                                                                              Added 18 variables.

nix-repl> lib.findFirst (drv: drv.pname == "nix") {} (legacyPackages.x86_64-linux.nixos-option.nativeBuildInputs ++ legacyPackages.x86_64-linux.nixos-option.buildInputs)                     error:
       … while evaluating a branch condition
         at /nix/store/sb1wp19dpf3phgqw57mnk99v12j6c67w-source/lib/lists.nix:645:5:
          644|     in
          645|     if index == null then
             |     ^
          646|       default

       … while evaluating a branch condition
         at /nix/store/sb1wp19dpf3phgqw57mnk99v12j6c67w-source/lib/lists.nix:596:5:
          595|     in
          596|     if resultIndex < 0 then
             |     ^
          597|       default

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'pname' missing
       at «string»:1:21:
            1| lib.findFirst (drv: drv.pname == "nix") {} (legacyPackages.x86_64-linux.nixos-option.nativeBuildInputs ++ legacyPackages.x86_64-linux.nixos-option.buildInputs)
             |                     ^
       Did you mean name?

nix-repl> 
tried pname first but isn't available :C ``` Lix 2.92.0-dev-pre20240917-8ab5743 Type :? for help. nix-repl> :lf ./ Added 18 variables. nix-repl> lib.findFirst (drv: drv.pname == "nix") {} (legacyPackages.x86_64-linux.nixos-option.nativeBuildInputs ++ legacyPackages.x86_64-linux.nixos-option.buildInputs) error: … while evaluating a branch condition at /nix/store/sb1wp19dpf3phgqw57mnk99v12j6c67w-source/lib/lists.nix:645:5: 644| in 645| if index == null then | ^ 646| default … while evaluating a branch condition at /nix/store/sb1wp19dpf3phgqw57mnk99v12j6c67w-source/lib/lists.nix:596:5: 595| in 596| if resultIndex < 0 then | ^ 597| default (stack trace truncated; use '--show-trace' to show the full trace) error: attribute 'pname' missing at «string»:1:21: 1| lib.findFirst (drv: drv.pname == "nix") {} (legacyPackages.x86_64-linux.nixos-option.nativeBuildInputs ++ legacyPackages.x86_64-linux.nixos-option.buildInputs) | ^ Did you mean name? nix-repl> ```
Author
Contributor

Was thinking on opening a PR to nixpkgs to expose the pname (along with name and version) which would uncurse this a bit

nix-repl> lib.findFirst (drv: lib.hasPrefix "nix" drv.name) {} (legacyPackages.x86_64-linux.nixos-option.nativeBuildInputs ++ legacyPackages.x86_64-linux.nixos-option.buildInputs)
«derivation /nix/store/imwvysd8xx24sswccfav0jr8ny83y2f3-nix-2.18.7.drv»
Was thinking on opening a PR to nixpkgs to expose the pname (along with name and version) which would uncurse this a bit ``` nix-repl> lib.findFirst (drv: lib.hasPrefix "nix" drv.name) {} (legacyPackages.x86_64-linux.nixos-option.nativeBuildInputs ++ legacyPackages.x86_64-linux.nixos-option.buildInputs) «derivation /nix/store/imwvysd8xx24sswccfav0jr8ny83y2f3-nix-2.18.7.drv» ```
Author
Contributor
--- a/pkgs/stdenv/generic/make-derivation.nix
+++ b/pkgs/stdenv/generic/make-derivation.nix
@@ -333,6 +333,7 @@ else let
   derivationArg =
     removeAttrs attrs removedOrReplacedAttrNames
     // (optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) {
+      pname = attrs.pname or null;
       name =
         let
           # Indicate the host platform of the derivation if cross compiling.

With this change on nixpkgs lix/nixos-module could use pname for this overlay.

``` --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -333,6 +333,7 @@ else let derivationArg = removeAttrs attrs removedOrReplacedAttrNames // (optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) { + pname = attrs.pname or null; name = let # Indicate the host platform of the derivation if cross compiling. ``` With this change on nixpkgs lix/nixos-module could use pname for this overlay.
Author
Contributor
https://github.com/NixOS/nixpkgs/pull/344735
fabianhjr marked this conversation as resolved
fabianhjr force-pushed dynamic-nix-choice from f1277e616d to 6def4cc69a 2024-09-26 22:19:05 +00:00 Compare
fabianhjr force-pushed dynamic-nix-choice from 6def4cc69a to 2669bc78a6 2024-09-26 22:20:33 +00:00 Compare
jade reviewed 2024-09-26 23:23:46 +00:00
overlay.nix Outdated
@ -68,0 +68,4 @@
# Get the two common inputs of a derivation/package.
inputs = prev.${name}.buildInputs ++ prev.${name}.nativeBuildInputs;
nixDependency = lib.findFirst
(drv: drv.pname == "nix")
Owner

it may be the case that stuff like runCommand outputs have no pname or version, which could cause this to explode at eval time if someone puts a runCommand derivation into an input that we are scanning like this:

nix-repl> x = runCommand "nya" {} "echo ya"

nix-repl> x
«derivation /nix/store/1k2vgampxi5hvz08ns8z7phzd3g2gdpj-nya.drv»

nix-repl> x.pname
error: attribute 'pname' missing
       at «string»:1:1:
            1| x.pname
             | ^
       Did you mean name?

nix-repl> x.version
error: attribute 'version' missing
       at «string»:1:1:
            1| x.version
             | ^

We would want to do something like (drv.pname or "") == "nix" or similar

it may be the case that stuff like runCommand outputs have no pname or version, which could cause this to explode at eval time if someone puts a runCommand derivation into an input that we are scanning like this: ``` nix-repl> x = runCommand "nya" {} "echo ya" nix-repl> x «derivation /nix/store/1k2vgampxi5hvz08ns8z7phzd3g2gdpj-nya.drv» nix-repl> x.pname error: attribute 'pname' missing at «string»:1:1: 1| x.pname | ^ Did you mean name? nix-repl> x.version error: attribute 'version' missing at «string»:1:1: 1| x.version | ^ ``` We would want to do something like `(drv.pname or "") == "nix"` or similar
Author
Contributor

amended the commit to use suggested guarding, thanks for the help

amended the commit to use suggested guarding, thanks for the help
fabianhjr marked this conversation as resolved
fabianhjr force-pushed dynamic-nix-choice from 2669bc78a6 to b3457b78ac 2024-09-26 23:55:06 +00:00 Compare
jade referenced this pull request from a commit 2024-09-30 20:36:11 +00:00
Owner

merged manually since i apparently borked it oops

merged manually since i apparently borked it oops
jade closed this pull request 2024-09-30 20:37:22 +00:00
jade referenced this pull request from a commit 2024-10-19 01:55:58 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/nixos-module#37
No description provided.