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

fix: explicitly declare flake-parts input #97

Merged

Conversation

cameronraysmith
Copy link
Contributor

@cameronraysmith cameronraysmith commented Feb 23, 2025

Signed-off-by: Cameron Smith <cameron.ray.smith@gmail.com>
Signed-off-by: Cameron Smith <cameron.ray.smith@gmail.com>
Signed-off-by: Cameron Smith <cameron.ray.smith@gmail.com>
@cameronraysmith cameronraysmith force-pushed the requires-flake-parts-input branch from 57c8075 to 56d7d5b Compare February 23, 2025 15:42
@cameronraysmith cameronraysmith marked this pull request as ready for review February 23, 2025 15:43
@Sironheart
Copy link
Contributor

I'm currently not seeing any benefit from making this import explicit. Could you please elaborate why this inpurity is a struggle for anyone that uses this repository as a starting point?

@cameronraysmith
Copy link
Contributor Author

cameronraysmith commented Feb 23, 2025

Try to update a lockfile from any of the flakes without it as described in #96 (comment). All of them just use flake-parts but there's nowhere for it to come from without someone manually managing the lockfile or happening to have flake-parts declared in the system flake-registry on their current machine or enabling access to the global flake-registry. This is the case both for the flake in the root of the repository and for all the language templates.

For example (using rust, but this is the case for all of the language templates)

❯ nix flake init -t github:ALT-F4-LLC/kickstart.nix/6b348b22de70ee045cebc9ba5259dd68fa34bcc7#rust
wrote: /home/user/projects/kickstart-nix-rust/Cargo.toml
wrote: /home/user/projects/kickstart-nix-rust/.envrc
wrote: /home/user/projects/kickstart-nix-rust/Cargo.lock
wrote: /home/user/projects/kickstart-nix-rust/.gitignore
wrote: /home/user/projects/kickstart-nix-rust/flake.nix
wrote: /home/user/projects/kickstart-nix-rust/src/main.rs
wrote: /home/user/projects/kickstart-nix-rust/src
direnv: error /home/user/projects/kickstart-nix-rust/.envrc is blocked. Run direnv allow to approve its content

❯ nix build .
error:
… while updating the lock file of flake 'path:/home/user/projects/kickstart-nix-rust?lastModified=1740326032&narHash=sha256-oSwo9OQxqKGdnx0XJy1gXX/%2BTpd4AIV75Yt5JKIELLU%3D'

   … while updating the flake input 'flake-parts'

   error: cannot find flake 'flake:flake-parts' in the flake registries

This only works if the user has flake-parts in their system flake registry or enabled access to the global flake registry, but, in general, this will rarely be the case.

In contrast to the case for the current HEAD of main on this repository described in the issue and quoted above for 6b348b2, performing the same from the source branch of this PR works as expected

❯ nix flake init -t github:cameronraysmith/kickstart.nix/requires-flake-parts-input#rust
wrote: /home/user/projects/kickstart-nix-rust-fix/Cargo.toml
wrote: /home/user/projects/kickstart-nix-rust-fix/.envrc
wrote: /home/user/projects/kickstart-nix-rust-fix/Cargo.lock
wrote: /home/user/projects/kickstart-nix-rust-fix/.gitignore
wrote: /home/user/projects/kickstart-nix-rust-fix/flake.nix
wrote: /home/user/projects/kickstart-nix-rust-fix/src/main.rs
wrote: /home/user/projects/kickstart-nix-rust-fix/src
direnv: error /home/user/projects/kickstart-nix-rust-fix/.envrc is blocked. Run `direnv allow` to approve its content                                   

❯ nix build .                                                                           
warning: creating lock file '/home/user/projects/kickstart-nix-rust-fix/flake.lock': 
• Added input 'flake-parts':
    'github:hercules-ci/flake-parts/32ea77a06711b758da0ad9bd6a844c5740a87abd?narHash=sha256-7H9XgNiGLKN1G1CgRh0vUL4AheZSYzPm%2BzmZ7vxbJdo%3D' (2025-02-01)
• Added input 'flake-parts/nixpkgs-lib':
    'https://github.com/NixOS/nixpkgs/archive/072a6db25e947df2f31aab9eccd0ab75d5b2da11.tar.gz?narHash=sha256-vJzFZGaCpnmo7I6i416HaBLpC%2BhvcURh/BQwROcGIp8%3D' (2025-02-01)
• Added input 'nixpkgs':
    'github:NixOS/nixpkgs/32fb99ba93fea2798be0e997ea331dd78167f814?narHash=sha256-ozoOtE2hGsqh4XkTJFsrTkNxkRgShxpQxDynaPZUGxk%3D' (2025-02-21)
evaluation warning: rustPlatform.fetchCargoTarball is deprecated in favor of rustPlatform.fetchCargoVendor.
                    If you are using buildRustPackage, try setting useFetchCargoVendor = true and regenerating cargoHash.
                    See the 25.05 release notes for more information.

❯ tree --du -ah result
[436K]  result
└── [436K]  bin
    └── [436K]  example

 436K used in 2 directories, 1 file

❯ ./result/bin/example                                                            
Hello, world!

@cameronraysmith
Copy link
Contributor Author

@Sironheart your https://github.com/Sironheart/nix-config contains the same issue.
Resolved in Sironheart/nix-config#3.

@cameronraysmith
Copy link
Contributor Author

cameronraysmith commented Feb 23, 2025

See also #99 for an explanation of how to fix the root cause of this and a proposal to do so in #100.

@Sironheart
Copy link
Contributor

@erikreinert I think this would need to be decided on your part... I actually don't think this is an issue that 'new' users need to know about for now.

@cameronraysmith
Copy link
Contributor Author

cameronraysmith commented Feb 23, 2025

@Sironheart can you explain why this is the case in your view with some direct reference to the evidence I have provided in response to your initial question above and the issue #96 ?

All of the templates are broken as I illustrated with the rust template unless you happen to have flake-parts in a flake registry you subscribe to (#96 (comment)). You may happen to have a system in this state if you installed nix/nixos/nix-darwin with a template in this repository, but if you installed nix separately without access to the global flake registry you wouldn't be able to use these language-specific templates without being a new user who understands they all rely on an implicit input that you need to declare manually immediately after instantiating the template. Moreover, the fix is incredibly simple.

@cameronraysmith
Copy link
Contributor Author

cameronraysmith commented Feb 23, 2025

Would you expect to be guided in learning a new language with a function

f(x, y) = x + y

that you should begin using it as

let x = 1
in
f(x, y)

which will return 7 because y is declared "somewhere else" to have a value of 6, or have evaluating this throw an error telling you that y is unbound and require binding the arguments of the function in order to evaluate it?

Moreover, is the command line workflow outlined in #96 (comment) simpler than adding one line to the flake.nix file?

@erikreinert
Copy link
Member

erikreinert commented Feb 25, 2025

This is fine to me. I was slightly worried about this when I originally did it.

The only reason why it wasn't explicitly added was because it was how they had it in their flake-parts documentation at the time. I don't mind being explicit in this case, it's worth being more informative then less.

@erikreinert erikreinert self-assigned this Feb 25, 2025
@erikreinert erikreinert merged commit 9779d62 into ALT-F4-LLC:main Feb 25, 2025
38 checks passed
@cameronraysmith
Copy link
Contributor Author

The only reason why it wasn't explicitly added was because it was how they had it in their flake-parts documentation at the time.

That makes sense. They decided to perform the same update upstream in hercules-ci/flake-parts#210, so now these are in sync again.

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

Successfully merging this pull request may close these issues.

flake-parts is an undeclared input to the top-level and all language template flakes
3 participants