!SgYlXivkogarTVcnZO:nixos.org

Nix Flakes

880 Members
175 Servers

Load older messages


SenderMessageTime
31 Oct 2023
@virtu:matrix.im@virtu:matrix.im

Hey everyone. Flake novice here. I used a flake to create a reproducible development shell for one of my python applications. So far, so good.

Then I wanted to integrate my application into my configuration.nix and run it as a recurring service via systemd. To this end, (after browsing github for inspiration), in my nix config repo I created a pkgs/app/default.nix, which points to the github repo of my application, and a modules/app/default.nix, which defines settings and applies those appropriately. My configuration.nix imports the app's module and enables it. Although it took me a while cause I'm new to Nix, I got that setup working after a while.

Now I'd like to turn the second part (module, pkg definitions) into a flake, and have some questions about that. Because there's so many open questions, I'll just post them in the order that makes sense to me. Any help/pointers would be greatly appreciated:

  • When searching for flakes on github, I only found repos that turn other repos into flakes. Is there a reason to separate the flake part from the code part? Or is this mainly due to people turning other people's applications into flakes?
  • What if I want to turn code I maintain into a flake? Should I also use dedicated repos for the application and the flake? Since I already have a flake.nix file for the development shell in my application's repo, at first glance it doesn't make sense to me to have a dedicated repo for the module/pkg functionality because there's a chance the lock files are not in sync so you might be running different code/deps than you're using during development.
  • If it's therefore considered a best practice to put the functionality for the devshell and packaging into the same repo, is there some other set of best practices about the layout? On one hand, I don't want to stuff the code repo with nix-specific directories and files; on the other, putting everything into flake.nix might make the code cluttered.
  • Last but not least, how do I port the functionality from the {pkgs,module}/app/default.nix files so it can be used as a flake in my configuration.nix? If anyone has a (preferably simple) example repo on github, that would be great.
    Sorry for the lengthy list, but I felt putting all questions out there so people can immediately shoot down stupid questions and point me into the right direction. Thanks!
08:28:51
@mewp:nurupo.plmewpthe main difference between having a flake in the same repo vs a separate one is that if it's in the same repo, the whole repository ends up in the closure—which is fine most of the time, but sometimes you e.g. want to filter something out, because it isn't necessary for your builds08:53:53
@mewp:nurupo.plmewpI'd say that when possible, it makes sense to have the flake in the same repo08:54:09
@mewp:nurupo.plmewpI wouldn't want to have a devshell in a repository separate from the app—but I don't know if there is a general practice08:54:53
@mewp:nurupo.plmewpfor what it's worth, my encounters with flakes so far are mostly in repos that package themselves, in the same repo08:55:20
@mewp:nurupo.plmewp I don't entirely get the last point. pkgs.callPackage ./pkgs/app/default.nix {} will probably do what you want for packages, import ./modules/app/default.nix will do that for modules 08:56:36
@mewp:nurupo.plmewp as in, outputs.nixosModules.app = import ./modules/app/default.nix; 08:57:07
@virtu:matrix.im@virtu:matrix.im thanks mewp. can I bother you to share one or two of those repos with flakes that package themselves in the same repo? that would really help a lot. 09:12:52
@mewp:nurupo.plmewphttps://gitlab.com/eobuwie-foss/imaginator/ ← that's one of mine09:14:07
@mewp:nurupo.plmewpmost of my other repos are unfortunately private, but I'll try to find a public example09:14:51
@mewp:nurupo.plmewpoh, right, https://github.com/helix-editor/helix09:15:43
@mewp:nurupo.plmewpbut also see https://github.com/NixOS/flake-registry/blob/master/flake-registry.json09:15:50
@virtu:matrix.im@virtu:matrix.im I'll try to figure out a theme from those that I can apply to my problem. thanks, mewp! 09:18:29
@mewp:nurupo.plmewpdon't hesitate to ask more09:18:44
@fractivore:cyberia.club@fractivore:cyberia.club joined the room.14:29:10
1 Nov 2023
@kjeremy:matrix.orgkjeremy joined the room.14:06:45
2 Nov 2023
@redviking:matrix.orgredviking 🐧 joined the room.01:28:42
@npc_projection:matrix.orgnpc_projection joined the room.05:22:21
@virtu:matrix.im@virtu:matrix.im

I finally got around to adding the nixosModules target to my flake. Now I wonder how to correctly enable the service defined in the module in my configuration.nix. Before, I did import modules/app and services.app.enable = true;.

To use the flake for my app, I added it as input to the flake for my host configuration, and passed it as input to my configuration.nix. That got me the error error: The option services.p2p-crawler' does not exist.. After going through some examples, I tried adding my_app.nixosModules.my_appto the modules in my nixosConfigurations (similar to what I have for home manager), but that landed me aerror: attribute 'p2p-crawler' missing`. Did I do something wrong in my app's flake, or am I using the flake wrong?

10:01:53
@virtu:matrix.im@virtu:matrix.im *

I finally got around to adding the nixosModules target to my flake. Now I wonder how to correctly enable the service defined in the module in my configuration.nix. Before, I did import modules/app and services.app.enable = true;.

To use the flake for my app, I added it as input to the flake for my host configuration, and passed it as input to my configuration.nix. That got me the error error: The option services.p2p-crawler' does not exist.. After going through some examples, I tried adding my-app.nixosModules.my-appto the modules in mynixosConfigurations (similar to what I have for home manager), but that landed me aerror: attribute 'p2p-crawler' missing`. Did I do something wrong in my app's flake, or am I using the flake wrong?

10:02:47
@virtu:matrix.im@virtu:matrix.im *

I finally got around to adding the nixosModules target to my flake. Now I wonder how to correctly enable the service defined in the module in my configuration.nix. Before, I did import modules/app and services.app.enable = true;.

To use the flake for my app, I added it as input to the flake for my host configuration, and passed it as input to my configuration.nix. That got me the error error: The option services.p2p-crawler' does not exist.. After going through some examples, I tried adding my-app.nixosModules.my-app to the modules in mynixosConfigurations (similar to what I have for home manager), but that landed me aerror: attribute 'p2p-crawler' missing`. Did I do something wrong in my app's flake, or am I using the flake wrong?

10:03:10
@virtu:matrix.im@virtu:matrix.im *

I finally got around to adding the nixosModules target to my flake. Now I wonder how to correctly enable the service defined in the module in my configuration.nix. Before, I did import modules/app and services.app.enable = true;.

To use the flake for my app, I added it as input to the flake for my host configuration, and passed it as input to my configuration.nix. That got me the error error: The option services.p2p-crawler' does not exist.. After going through some examples, I tried adding my-app.nixosModules.my-app to the modules in mynixosConfigurations (similar to what I have for home manager), but that landed me aerror: attribute 'p2p-crawler' missing\. Did I do something wrong in my app's flake, or am I using the flake wrong?

10:03:30
@virtu:matrix.im@virtu:matrix.imRedacted or Malformed Event11:02:33
@crtified:crtified.meCRTified virtu: There is no application attribute, and what you're seeing is the correct output. The systems are generated by flake-utils 11:04:37
@crtified:crtified.meCRTified * virtu: There is no application attribute, and what you're seeing is the correct (well, more like expected) output. The systems are generated by flake-utils 11:05:04
@crtified:crtified.meCRTifiedBut nixosModules shouldn't be architecture-specific11:05:54
@crtified:crtified.meCRTified Maybe have a look at https://ayats.org/blog/no-flake-utils/#when-things-go-wrong for why you might not need flake-utils (especially if you want to define a nixosModule) 11:07:01
@virtu:matrix.im@virtu:matrix.im CRTified: yeah, I just realized I had the nixosModules in the wrong place. I figured out a way to fix it in the mean time, but thanks for clarifying and providing some background information. I didn't use flake-utils in my most recent version, but I updated my flake's inputs this morning, switched to out-of-tree poetry2nix because it is no longer in unstable, and started from scratch with a flake template from poetry2nix (which uses flake-utils). I'll do some reading and try to figure out the best approach. thanks! 11:14:03
@eva:blahaj.nyceva changed their profile picture.20:09:29
@adelta:matrix.org@adelta:matrix.org joined the room.22:43:56

Show newer messages


Back to Room ListRoom Version: 6