snowfallorg / lib

Unified configuration for systems, packages, modules, shells, templates, and more with Nix Flakes.
https://snowfall.org
Other
391 stars 33 forks source link

Paths are not resolved properly #98

Closed PerchunPak closed 3 weeks ago

PerchunPak commented 4 months ago

After b2e636407591bfe7a1f9a4ff50e282ed51ce7b59, for some reason, paths are not resolved properly anymore. Here is minimal reproducible example:

$ cat flake.nix
{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

    snowfall-lib = {
      url = "github:snowfallorg/lib?rev=b2e636407591bfe7a1f9a4ff50e282ed51ce7b59";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    inputs:
    inputs.snowfall-lib.mkFlake {
      inherit inputs;

      src = ./.;
    };
}
$ mkdir modules # btw, for some reason this is required
$ cat systems/x86_64-linux/example/default.nix
{
  boot.isContainer = true;

  environment.variables = {
    TEST = ../../../flake.nix;
  };

  system.stateVersion = "24.11";
}
$ nix build .#nixosConfigurations.example.config.system.build.toplevel
$ grep TEST result/etc/set-environment
export TEST="/nix/store/flake.nix"
$ # change to d6b766939af0350fcfad505cf3b693dbaf297c3b (one commit before b2e636407591bfe7a1f9a4ff50e282ed51ce7b59)
$ git diff flake.nix
diff --git a/flake.nix b/flake.nix
index 065926e..f13e029 100644
--- a/flake.nix
+++ b/flake.nix
@@ -3,7 +3,7 @@
     nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

     snowfall-lib = {
-      url = "github:snowfallorg/lib?rev=b2e636407591bfe7a1f9a4ff50e282ed51ce7b59";
+      url = "github:snowfallorg/lib?rev=d6b766939af0350fcfad505cf3b693dbaf297c3b";
       inputs.nixpkgs.follows = "nixpkgs";
     };
   };
$ nix build .#nixosConfigurations.example.config.system.build.toplevel
$ grep TEST result/etc/set-environment
export TEST="/nix/store/vllvzqavhgbb63kf2463kd7f5m3sqqfw-ayfmrvxhl2m9cg4h8bg49lw6cm4s16qp-source/flake.nix"

For reference, here is my flake.lock https://gist.github.com/PerchunPak/4ee341dda628466030d0d8e2ffd8b03d

jakehamilton commented 4 months ago

I believe this is (imo) a Nix bug (it is something I ran into years ago) and can be worked around by using Snowfall Lib's fs helpers such as lib.snowfall.fs.get-file.

The issue is likely caused by the change to lib.snowfall.fs.get-snowfall-file and its non-snowfall counterpart. The change switched from using strings calculated from src to creating path types. Because of this separate entries are added to the nix store for each of the sub-directories. For this reason using the parent path directly will fail because Nix is using the context of the subdirectory that was stored as its own separate store entry.

Fixing this would mean reverting the path typing change. With the deprecation of toPath I don't think there is another option for getting actual paths.