Skip to content
lunicsPublic

Latest commit

 

History

2,255 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Features

  • flake-parts
  • flake-aspects
  • flake-file
  • import-tree
  • nixpkgs-multiverse
  • disko
  • dual boot
  • lanzaboote
  • preservation (nixos)
  • impermanence (home-manager)
  • microvm
  • sops-nix
  • nixvim
  • hosts kept private
  • raspberry-pi

Integrate nixos to your flake

Structure example

nixos
├─ host-1.nix
├─ host-2/
├─── main.nix
├─ host-3/
├─── darwin.nix
├─── home-manager.nix
└─ flake.nix
flake.nix (minimal)
{
  inputs.nixos.url = "github:lunics/nixos";

  outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } {
    imports = [
      inputs.nixos.flakeModules.default
      ((inputs.import-tree.matchNot ".*flake\\.nix") ./.)
    ];
  };
}

Only the entry point is provided here. nixos modules resolve inputs.<name> against this flake, so declaring the inputs they use is left to the consumer.

flake.nix (fully following lunics/nixos)

Declaring them as follows keeps nixos as the single source of truth: its own flake.lock drives every version and no url is ever duplicated.

{
  inputs = {
    nixos.url           = "github:lunics/nixos";
    nixpkgs.follows     = "nixos/nixpkgs";
    flake-parts.follows = "nixos/flake-parts";
    import-tree.follows = "nixos/import-tree";
  };

  outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } {
    imports = [
      inputs.nixos.flakeModules.default
      ((inputs.import-tree.matchNot ".*flake\\.nix") ./.)
    ];
  };
}
host-A/main.nix
{ config, ... }:{
  flake.nixosConfigurations = config.flake.lib.make_nixos "x86_64-linux" "host-A";

  flake.aspects = { aspects, ... }:{
    host-A = {
      includes = with aspects; [   # aspects provided by nixos
        options
        disk
        boot
        nix
        ...
      ];

      nixos = {
        _ = {       # parent root option
          hostname  = "host-A";
          flake_dir = "/path/to/this/repo";
        };
      };
    };
  };
}

Caveats:

  • self and inputs inside nixos modules resolve against the consumer flake, so its input set must cover every inputs.<name> used by nixos.
  • the consumer flake is written by hand: write-flake would regenerate it with every url duplicated, so override flake-file.outputs with lib.mkForce only if that is wanted.