Skip to content
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 usage of multiple flake files inside a monorepo without updating lock files for relative dependencies #12320

Open
2 tasks
onnimonni opened this issue Jan 20, 2025 · 7 comments
Labels
feature Feature request or proposal

Comments

@onnimonni
Copy link
Contributor

Is your feature request related to a problem?

I would want to use flakes inside single git monorepo to define my server and develop services too.

One can learn how to develop and deploy a simple go service following this great blog:
http://mtlynch.io/notes/simple-go-web-service-nixos/

I followed this and then moved the separate go service into: ./services/basic-go-web-app/ inside the git repo which contained the server configs and it's flake.nix

It's easy to have multiple flakes in single repository and use them with relative paths:

basic-go-web-app.url = "path:./services/basic-go-web-app/";

But then what happens automatically is that flake.lock will get the initial version of the local project and will not be updated automatically.

One needs to rely on hacks like --override-input basic-go-web-app ./services/basic-go-web-app/ to update the service into the servers.

Would there be an easy way to skip relative project from the lock files completely so that the service would always be built and deployed without the --override-input flag?

Proposed solution

Similarly as we have the special flag follows:

inputs = {
    # Reusable packages for nixos configs
    # Use the version of nixpkgs that has been tested to work with SrvOS
    srvos.url = "github:nix-community/srvos";
    nixpkgs.follows = "srvos/nixpkgs";
}

we could have an option disable-lock = true or even default to this when using relative paths.

This is a major headache and confusion for a new users like me.

Alternative solutions

One can use the:
1. --override-input basic-go-web-app ./services/basic-go-web-app/ as argument to the nixes-rebuild
2. Update the input in flake.lock with: nix flake lock --update-input basic-go-web-app

Additional context

Some discussions regarding this:

https://discourse.nixos.org/t/any-examples-for-a-monorepo-to-develop-app-and-deploy-it-to-servers/54798/2

https://discourse.nixos.org/t/relative-path-support-for-nix-flakes/18795/5

Checklist


Add 👍 to issues you find important.

@onnimonni onnimonni added the feature Feature request or proposal label Jan 20, 2025
@tomberek
Copy link
Contributor

Relative inputs should no longer do locking. Can you check with 2.26?

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2024-01-22-nix-team-meeting-minutes-210/59239/1

@onnimonni
Copy link
Contributor Author

Thanks for the answer and sorry I'm stupid and don't know how to use the 2.26 version yet 😓.

I'm on version 2.24.11 currently.

Can you point me to the steps of how to use newer version of nix eg directly from git master or a tag?

@cole-h
Copy link
Member

cole-h commented Jan 23, 2025

nix shell github:nixos/nix/2.26.0 should do it.

@onnimonni
Copy link
Contributor Author

Alright I was able to try that:

$ nix run nixpkgs#nixos-rebuild -- switch --fast --flake .#rusty --target-host rusty --build-host rusty --use-remote-sudo
building the system configuration...
error:
       … while updating the lock file of flake 'git+file:///Users/onnimonni/Projects/my-hetzner-example'

       error: lock file contains unlocked input '{"path":"services/basic-go-web-app/","type":"path"}'

It will still output this same error even if I remove the lock file and even if I use nix flake update first.

It doesn't work even when I'm using the earlier --override-input basic-go-web-app ./services/basic-go-web-app/ flag anymore when I'm using 2.26.

Is there something else I should do after using version 2.26?

@onnimonni
Copy link
Contributor Author

Okay it started to work after I completely removed the flake.lock and started fresh:

$ rm flake.lock
$ nix run nixpkgs#nixos-rebuild -- switch --fast --flake .#rusty --target-host rusty --build-host rusty --use-remote-sudo

It imports the inner flake properly into the main flake and can use it.

But when I modified the services/basic-go-web-app/main.go in between by commenting out few lines of the code the service from the "subflake" did not update automatically.

I still need to run either:

$ nix flake update basic-go-web-app
$ nix run nixpkgs#nixos-rebuild -- switch --fast --flake .#rusty --target-host rusty --build-host rusty --use-remote-sudo

or override the input with the local path so that it will always read whatever is in the current state:

$ nix run nixpkgs#nixos-rebuild -- switch --fast --flake .#rusty --target-host rusty --build-host rusty --use-remote-sudo --override-input basic-go-web-app ./services/basic-go-web-app/

So even version 2.26 doesn't solve this issue. I can continue using the override-input flag but I imagine that using multiple flakes inside one monorepo is a pattern that others would also want to use and it would be great to have an option to always override the lock file for the "subflake".

@onnimonni
Copy link
Contributor Author

And it seems that I would need to always remove the flake.nix to get my code deployed.

Otherwise it complains all the time about the unlocked input issue:

 error: lock file contains unlocked input '{"path":"./services/basic-go-web-app/","type":"path"}'

I documented my problems better here in the 2.26 announcement thread in NixOS forums: https://discourse.nixos.org/t/nix-2-26-released/59211/6?u=onnimonni

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal
Projects
None yet
Development

No branches or pull requests

4 participants