Best way to execute imported nix modules?

New to Nix OS :smiley: only bashed my keyboard twice today, so thats good.

I’m looking to import two .nix files, one of which starts a number of docker containers and has the line services.docker.enable = true; I’m importing the the file but I don’t believe its being executed. it builds but I cant do docker it says command not found.

how I can get it so all the .nix files in myModules and ./containers/containers.nix are actually run and executed? Id rather not list all of these twice in the code. Also any general comments on my design would be greatly appreciated. I dont have nixos or linux friends so im approaching all of this stuff on my own (well with chat gpt but they freaking suck at nix os :rage: ).

flake.nix

{
  description = "Nixos config flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, ... }@inputs: {

    # modules
    myModules = {
      vscodeServer = import ./modules/vscode-server.nix;
    };

    # docker containers
    myContainers = import ./containers/containers.nix;
  
    # NixOS configuration entrypoint
    nixosConfigurations.hostname = nixpkgs.lib.nixosSystem {
      specialArgs = {inherit inputs;};
      modules = [
        ./configuration.nix
        inputs.home-manager.nixosModules.default
      ];
    };


    ## home-manager modules
    #homeManagerModules = import ./modules/home-manager;

    ## Standalone home-manager configuration entrypoint
    #homeConfigurations = {
    #  "username@hostname" = home-manager.lib.homeManagerConfiguration {
    #    pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance
    #    extraSpecialArgs = {inherit inputs outputs;};
    #    modules = [
    #      ./home.nix
    #    ];
    #  };
    #};

  };
}

Docker nix file

{ config, pkgs, ... }:

let
  composeFiles = [
    "./docker-mgmt.yml"
    # "./pihole.yml"
    # "./media.yml"
  ];
  composeServices = builtins.map (file: {
    name = file;
    value = "${pkgs.docker-compose}/bin/docker-compose -f ${./docker-compose}/${file} up -d";
  }) composeFiles;
in
{
  services.docker.enable = true;

  systemd.services = builtins.listToAttrs composeServices;
}

Nix does lazy evaluate the expressions. If an expression is not “consumed” somewhere, it should not happen much.

In your case you have a variable “my containers” that is not consumed somewhere, so your importing file is not doing anything.

Try to add the myContainers variable to the modules list (where you import also home manager).

Then it should have an effect. If the docker stuff is correct I can not say as I am not using docker with nix(os)

The same problem should also apply for your VA code Server code that you try to load.