-
Notifications
You must be signed in to change notification settings - Fork 249
[per-OS Packages] Add platforms and excluded_platforms functionality #1358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
37eafa8
to
215050c
Compare
9a6c804
to
485ec44
Compare
6f3367e
to
94a01fa
Compare
987c28c
to
cacc711
Compare
94a01fa
to
8045218
Compare
819e76f
to
63a4ad1
Compare
8045218
to
58a9902
Compare
58a9902
to
ee51c13
Compare
On second thought, this needs a fix: we should add package to the lockfile, even if not installing on the user's platform. |
3eb9a45
to
81606cd
Compare
// Check if the platform is already present | ||
alreadyPresent := false | ||
for _, existing := range pkg.Platforms { | ||
if existing == platform { | ||
alreadyPresent = true | ||
break | ||
} | ||
} | ||
|
||
// Add the platform if it's not already present | ||
if !alreadyPresent { | ||
pkg.Platforms = append(pkg.Platforms, platform) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is verbose I realize. In the next PR, it gets simplified to:
if !lo.SomeBy(pkg.Platforms, func(p string) bool { return p == platform }) {
pkg.Platforms = append(pkg.Platforms, platform)
}
platform string | ||
excludePlatform string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be slice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, done in next PR
for _, pkg := range addedPackageNames { | ||
if platform != "" { | ||
if err := d.cfg.Packages.AddPlatform(pkg, platform); err != nil { | ||
return err | ||
} | ||
} | ||
if excludePlatform != "" { | ||
if err := d.cfg.Packages.ExcludePlatform(pkg, excludePlatform); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be part of d.cfg.Packages.Add(packageNameForConfig)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good idea. I'll do it in a stack PR (#1363) to minimize conflicts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, moving this won't work.
We need this here to enable the following scenario:
devbox add hello --platform x86_64-linux
devbox add hello --platform x86-64-darwin
The second time it runs, it willl not be within the loop above where .Add() is called.
internal/devconfig/packages.go
Outdated
// If the package has a list of platforms, it is enabled only on those platforms. | ||
// If the package has a list of excluded platforms, it is enabled on all platforms | ||
// except those. | ||
func (p *Package) enabledOnPlatform(platform string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this just be part of IsEnabledOnPlatform
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol, yes
// EnsureValidPlatform returns an error if the platform is not supported by nix. | ||
// https://nixos.org/manual/nix/stable/installation/supported-platforms.html | ||
func EnsureValidPlatform(platform string) error { | ||
for _, p := range nixPlatforms { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lo.Contains
? or just use a map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find current version simpler to write and read
internal/impl/packages.go
Outdated
cfgPkgs, err := d.ConfigPackages() | ||
if err != nil { | ||
return err | ||
} | ||
for _, pkg := range cfgPkgs { | ||
if err := pkg.EnsureUninstallableIsInLockfile(); err != nil { | ||
return err | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EnsureUninstallableIsInLockfile is a bit awkward, you could simply loop on d.ConfigPackages()
and resolve all.
If they are already resolved, it's a no-op.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it has some more checks inside the function....
7442274
to
6e0b77c
Compare
81606cd
to
0dbee1d
Compare
6e0b77c
to
ff1c36e
Compare
0dbee1d
to
25122b6
Compare
ff1c36e
to
7e4cebf
Compare
25122b6
to
7f2bc7a
Compare
## Summary This PR lays some groundwork for introducing platform-specific packages in a later PR (#1358) This PR makes the following changes to `devbox` struct: 1. Replace `devbox.Packages` with `ConfigPackageNames()` and `InstallablePackageNames()`. 2. Replace `devbox.PackagesAsInputs` with `ConfigPackages()` and `InstallablePackages()`. Updates callers to call the appropriate one. **devpkg.Package changes** I also introduce a new method `devpkg.PackagesFromConfig`, which enables us to add an `isInstallable bool` field on the `devpkg.Package`. I needed this because it affects the implementation of certain methods (such as `IsLegacy` changed in #1358). One can still construct via `PackagesFromStrings` which default to `isInstallable = true` (as before). I audited the callers. ## How was it tested? Did adhoc testing. Testscript unit tests should pass.
7e4cebf
to
ea87c15
Compare
7f2bc7a
to
fbba263
Compare
…ge.IsLegacy change
fbba263
to
8bf71ad
Compare
…her direct devbox library callers)
test failure is spurious. Tests pass in subsequent PRs. |
Suspect IssuesThis pull request has been deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
Summary
Motivation
Some users have a need to install platform-specific packages. For example,
glibcLocales
cannot be installed on macOS but may be needed on Linux.Approach
We enable two flags in
devbox add
:Follow up PRs:
--platform
flag usesdevbox add
fails due to platform-mismatch and suggest--exclude-platform
flagHow was it tested?
Added testscript unit test
Adhoc testing:
Install for a different platform than the one i am currently running on
Install on all platforms except my current platform
Ensure basic adding still works