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

{
  description = "Nix flake";

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

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

./modules/systems.nix

Module declaring systems supported by your flake.

{
  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.

{ 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

{
  perSystem = { pkgs, ... }: {
    packages.default = pkgs.vim;
    devShells.default = pkgs.mkShell {
      packages = with pkgs; [
        git
        vim
      ];
    };
  };
}