-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Allow flakes to refer to other flakes by relative path #3978
Comments
A lock file shouldn't be necessary as long as the input is going to be committed to the same repository. It only becomes a problem when the reference points outside the repository. Doing is useful for testing a change in a dependency, but a warning seems appropriate. |
It would be good to disallow |
Can we only do one lockfile for this, like cargo workspaces does it? |
@zimbatm Disallowing @kloenk I think you get half of this behavior for free if you don't invoke |
So, I’m considering if this is something I want/need. In my case, I have a repository of nixosConfiguration flakes in subdirectories (each a project with one or more machines), and a shared
|
This can sort of be simulated with https://github.com/edolstra/flake-compat, you must make your build impure, but even though it sounds bad, it isn't that bad. If you know your build is pure, you're fine, if you aren't sure, you can temporarily disable the sub-flakes and test each one separately build oh and all the sub-flakes have their own lock-files, therefore its necessary to update them recursively, I'll write a script for that. |
perhaps something like this could work, though I have no clue how to actually implement it {
inputs = {
your-lib = {
path = ./your-lib; # different from url to distinguish it
};
machine-1 = {
path = ./machine-1;
pass-on = your-lib; # I don't really know what `your-lib` should be, it could be a string, but that could cause confusion as registry references look the same. Also, I already saw something like this somewhere, can't remember what was the option, if you know then please tell me.
};
};
} {
inputs = {
your-lib = {
follows = "your-lib"; # this is the option used for referencing flake registries, I'm sure this time
};
};
} |
I just want to add another two cents to the bandwagon – I have two use cases that keep me wanting to reach for flakes with a relative path (and possibly some kind of arguments, but that's a separate discussion). One is the already mentioned idea to factor out common code into a I'm not sure if it's the right instinct to try reaching out for things like that, as I've been using NixOS mostly for Terraform/Ansible angle of reproducible configuration and I'm not sure how that fits in the package building conventions Nix has – maybe there are other options that are better suited to those use-cases I'm not aware of. |
I'd add that sub-flakes are a useful tool to "partition" your repo, for example my dotfiles (EDIT: I moved those packages to my systems repo) themselves provide custom packages I created and I propagate those up from "half-flakes", flakes whose inputs are declared at the toplevel flake, but look like separate flakes and mostly behave the same way. Just call the |
Another semi-related thing I've bumped against just now is that after a few tries to use things like submodules or impure imports via flake-compat (dunno if that's kosher, like I'm said, I'm new at this) I bumped into enough issues that I decided to just split it out as separate flakes. Unfortunately this now incurs the change->commit->push->update-flake penalty to make a simple change which is kind of annoying, is there plans for some way to develop flakes alongside a la |
definitely not
look at my dotfiles, I had the same issue and I solved it by those half-flakes |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/possibility-for-subflakes/11589/5 |
Currently, relative paths work already with the path fetcher. However, this comment looks like the restrictions are just not implemented. flake-compat doesn't allow relative paths, because Edit: What is the problem with a lock file? |
This was still too much overhead in my edit-test-loop. Therefore, I have merged most of my repos and use a similar approach as MagicRB. I hope relative paths with ".." will remain possible for
|
Currently this already works with Perhaps a more elegant solution to this, which would also solve the above mentioned issue, would be to pass a special |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/possibility-for-subflakes/11589/1 |
This issue with |
The current |
@zhaofengli does |
Thanks for the suggestion. I tried the following and got:
|
@aviallon Does your solution require the subflake to be in its own git submodule or something to work? With both my subflake and the parent flake in the same repo, I got no luck getting it working. |
@irisjae No, it does not. However, only commited files are taken into account by the flake. |
@aviallon The |
@mikepurvis I didn't even know that... I wonder if we could get the current flakes's path while in the |
Is there documentation available for the "git+file:...?..." URL scheme? I've only been able to find examples on this on Nix Flakes documentation. |
- fix broken local flake paths - local flake paths have issues on CIs. See NixOS/nix#3978 (comment). - fix mindless copy and paste
I'm not able to get
|
@irisjae Check out |
As a workaround, instead of this: {
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
# not supported:
# foo.url = "path:./subflake/foo"; Maybe something like this? {
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
};
in rec
{
# workaround
foo-flake = import ./subflake/foo/flake.nix;
foo-outputs = foo-flake.outputs {
inherit nixpkgs;
inherit flake-utils;
};
foo = foo-outputs.packages.${system}.default;
packages = rec {
mypkg = pkgs.buildBarPackage {
buildInputs = [ foo ];
};
default = mypkg;
... It lets me use the top-level flake to explain how to package my component, while hiding the details re: how to package its dependencies in a different flake, kept in a subfolder. Of course it would be nice if this wasn't necessary and all dependencies were already packaged in a nix-friendly way, but that's not always the case. (If there's already something in nixpkgs that does this in a more succinct way, then I'd like to know about it) |
As suggested in NixOS/nix#3978 (comment)
Yeah I'm seeing the same thing. |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
Does this maybe belong here: https://github.com/NixOS/nix/milestone/27 ? |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
When using devenv I find best to do: inputs:
root:
url: git+file://.
flake: false
imports:
- root/examples/compose/projectA |
Explained on: NixOS/nix#3978
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/how-to-include-submodules-in-nix-flake-lock-update-input/50195/1 |
workaround with git+file when one has lock file in git was borked with this #10815 (it may be by design so - and solution would be git submodule) |
I'm using inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
backend.url = "github:your_user/your_repo?dir=your_dir";
}; |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/my-nix-subflake-does-not-resolve-nixpkgs/55941/1 |
E.g.
This is primarily useful when you have multiple flakes in the same repository.
However this means that we can't have a lock file entry for the
foo
input.The text was updated successfully, but these errors were encountered: