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

FlakeA flake with inputs and outputs.Project filesA file in the example project.
{
  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.

FlakeA flake with inputs and outputs.
{
  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.

FlakeA flake with inputs and outputs.
{ 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

FlakeA flake with inputs and outputs.
{
  perSystem = { pkgs, ... }: {
    packages.default = pkgs.vim;
    devShells.default = pkgs.mkShell {
      packages = with pkgs; [
        git
        vim
      ];
    };
  };
}

Share your thoughts