Fetching and importing custom modules

I have written some custom modules to make it simpler for me to maintain multiple systems at once. So they are nixos config files. So i thought about putting them into a seperate git repo so that I don’t need to keep all devices in the same repo (this is not possible for me since some of the devices are not mine and I just can have my home manager config on there, but there are other peoples home manager configs). So far I just copied the config files but, as I said, maybe importing them by fetching them over the internet would be better (?).
I am not even sure what the best way to go is. I tried to package it as a flake which threw some errors and I have tried to fetch single files, that also didn’t work.
Maybe someone who knows their stuff could give some pointer.
Many thanks :slight_smile:

Flakes are probably the best way to do this, they’re kind of designed to allow smaller projects like this to have reasonable distribution mechanisms. There’s no official documentation for this yet, but you’d want to use nixosModules. nixos-hardware is a pretty good example of such a project.

If you don’t like flakes, you can indeed use fetchurl and stuff. You’d probably want a top-level default.nix which just imports all your other modules so you don’t need to fetch and import individual files.

What does your config currently look like so I can help with the specific errors you’re getting, beyond giving you a rough high-level recommendation?

1 Like

thank you for that
I like flakes but I had problems with the nixosModules. For example it said that there was no config when it was needed (like in config = lib.mkIf config.someModule) and it didn’t allow me to use imports = [ ].

You’ll need to share your actual code; it’s probably just that you’re misunderstanding how importing nix modules works, but it’s hard to know what exactly you’re misunderstanding without seeing what you’re trying.

1 Like

I was about to send you the config (after trying to rebuild what I did (i changed it a lot for testing purposes)) but now it seems to work…i guess
still thank you

for anyone interested this is how I did it (don’t ask me how I messed it up)

outputs.nixosModules.default = ./system/systemSettings.nix;


options.someName.someOption = lib.mkEnableOption "enable this option";
config = lib.mkIf config.someName.someOption {
# some system setting
environment.systemPackages = [ pkgs.hello ];
1 Like