flake.nix.md

Flake-parts example

This flake-parts example comes equipped with automatic module importing, one nixos system, one nixos module for it, one default package, and one devShell. The default package is also imported in the system.

A great start for a dendritic flake.

./flake.nix

Entry point of your flake

FlakeFlake inputs and outputs are understood here, with flake-aware hovers and completion.Project filesNearby files from the example project are mounted, so relative paths and imports are real.
{
  description = "Nix flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-parts.url = "github:hercules-ci/flake-parts";
    import-tree.url = "github:vic/import-tree";
  };

  outputs = inputs: inputs.flake-parts.lib.mkFlake {inherit inputs;} (inputs.import-tree ./modules);
}

./modules/systems.nix

Module declaring systems supported by your flake.

FlakeFlake inputs and outputs are understood here, with flake-aware hovers and completion.
{
  systems = [
    "x86_64-linux"
    "aarch64-linux"
    "x86_64-darwin"
    "aarch64-darwin"
  ];
}

./modules/nixos.nix

Module outputting a nixos system and a configuration module for it.

FlakeFlake inputs and outputs are understood here, with flake-aware hovers and completion.
{ self, inputs, ... }: {

  flake.nixosConfigurations.HOSTNAME = inputs.nixpkgs.lib.nixosSystem {
    modules = [
      self.nixosModules.HOSTNAMEModule
    ];
  };

  flake.nixosModules.HOSTNAMEModule = { pkgs, ... }: {
    environment.systemPackages = [
      self.packages.${pkgs.system}.default
    ];
  };

}

./modules/other.nix

Module outputting a package and a shell

FlakeFlake inputs and outputs are understood here, with flake-aware hovers and completion.
{
  perSystem = { pkgs, ... }: {
    packages.default = pkgs.vim;
    devShells.default = pkgs.mkShell {
      packages = with pkgs; [
        git
        vim
      ];
    };
  };
}

Share your thoughts