Skip to content

Commit 5ff0bdb

Browse files
mikeland73Lagoja
andauthored
[flakes] Fix flakes with fragments (#1069)
## Summary URLs were getting normalized without fragments which breaks flakes for for non default exports or flakes that export more than 1 package. This fixes it. ## How was it tested? PHP flake example --------- Co-authored-by: John Lago <750845+Lagoja@users.noreply.github.com>
1 parent f5c71f6 commit 5ff0bdb

File tree

8 files changed

+57
-25
lines changed

8 files changed

+57
-25
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"packages": [
3-
"path:my-php-flake#php"
3+
"path:my-php-flake"
44
],
55
"shell": {
66
"init_hook": null
77
},
88
"nixpkgs": {
99
"commit": "f80ac848e3d6f0c12c52758c0f25c10c97ca3b62"
1010
}
11-
}
11+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"lockfile_version": "1",
3+
"packages": {}
4+
}

examples/flakes/php-extension/my-php-flake/flake.nix

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@
99

1010
outputs = { self, nixpkgs, flake-utils }:
1111
flake-utils.lib.eachDefaultSystem (system:
12-
let pkgs = nixpkgs.legacyPackages.${system};
13-
in {
14-
packages = {
15-
# Customize and export the PHP package with some extra config
16-
php = pkgs.php.buildEnv {
17-
# extraConfig will add the line below to our php.ini
12+
let
13+
pkgs = nixpkgs.legacyPackages.${system};
14+
# Customize and export the PHP package with some extra configuration
15+
php-ext = pkgs.php.buildEnv {
16+
# extraConfig will add the line below to the php.ini in our Nix store.
1817
# ${self} is a variable representing the current flake
1918
extraConfig = ''
20-
extension=${self}/skeleton.so
19+
extension=${self}/skeleton.so
2120
'';
22-
};
21+
};
22+
in {
23+
packages = {
24+
# Export the PHP package with our custom extension as the default
25+
default = php-ext;
2326
};
2427
});
25-
}
28+
}

examples/flakes/php/devbox.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"path:my-php-flake#hello"
55
],
66
"shell": {
7-
"init_hook": null
7+
"init_hook": null,
8+
"scripts": {
9+
"run_test": "php -m | grep ds || exit 1"
10+
}
811
},
912
"nixpkgs": {
1013
"commit": "f80ac848e3d6f0c12c52758c0f25c10c97ca3b62"

examples/flakes/php/my-php-flake/flake.lock

Lines changed: 24 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/flakes/php/my-php-flake/flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
# If you only want to export a single package, you can name it default which allows
2222
# installation without using url fragment (.e.g. "path:my-flake")
23-
default = pkgs.php.withExtensions ({ enabled, all }: enabled ++ (with all; [ ds memcached ]));
23+
# default = pkgs.php.withExtensions ({ enabled, all }: enabled ++ (with all; [ ds memcached ]));
2424
};
2525
});
2626
}

internal/nix/input.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,18 @@ func InputsFromStrings(names []string, l lock.Locker) []*Input {
3535
return inputs
3636
}
3737

38-
func InputFromString(s string, l lock.Locker) *Input {
39-
u, _ := url.Parse(s)
38+
func InputFromString(raw string, locker lock.Locker) *Input {
39+
u, _ := url.Parse(raw)
4040
if u.Path == "" && u.Opaque != "" && u.Scheme == "path" {
4141
// This normalizes url paths to be absolute. It also ensures all
4242
// path urls have a single slash (instead of possibly 3 slashes)
43-
u, _ = url.Parse("path:" + filepath.Join(l.ProjectDir(), u.Opaque))
43+
normalizedURL := "path:" + filepath.Join(locker.ProjectDir(), u.Opaque)
44+
if u.Fragment != "" {
45+
normalizedURL += "#" + u.Fragment
46+
}
47+
u, _ = url.Parse(normalizedURL)
4448
}
45-
return &Input{*u, l, s}
49+
return &Input{*u, locker, raw}
4650
}
4751

4852
func (i *Input) IsLocal() bool {

internal/nix/input_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ func TestInput(t *testing.T) {
2929
{
3030
pkg: "path:path/to/my-flake#my-package",
3131
isFlake: true,
32-
name: "my-flake-eaedce",
32+
name: "my-flake-773986",
3333
urlWithoutFragment: "path:" + filepath.Join(projectDir, "path/to/my-flake"),
3434
urlForInput: "path:" + filepath.Join(projectDir, "path/to/my-flake"),
3535
},
3636
{
3737
pkg: "path:.#my-package",
3838
isFlake: true,
39-
name: "my-project-bbeb05",
39+
name: "my-project-20698c",
4040
urlWithoutFragment: "path:" + projectDir,
4141
urlForInput: "path:" + projectDir,
4242
},

0 commit comments

Comments
 (0)