Skip to content

Nix functions to create sharable, flexible and standardized Nixos configurations.

License

Notifications You must be signed in to change notification settings

pipelight/nixos-tidy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nixos-tidy - Make filesystem based configurations.

Modules and library for filesystem based configuration.

Install (add to your config).

Add the flake to your existing configuration.

# flake.nix
inputs = {
  nixos-tidy = {
    url = "github:pipelight/nixos-tidy";
    inputs.nixpkgs.follows = "nixpkgs";
  };
};
# flake.nix
outputs = {
  self,
  nixpkgs,
  ...
}: {
  nixosConfiguration = {
    default = pkgs.lib.nixosSystem {
      modules = [
        # pick some modules
        inputs.nixos-tidy.nixosModules.home-merger
        ({
          config,
          pkgs,
          lib,
          inputs,
          ...
        }: let
            # Use functions from library.
            slib = inputs.nixos-tidy.lib;
        in {

        })
      ];
    };
  }
};

Examples

  • Minimalist

    Find many minimalists examples self-contained in a single flake.nix file, in the templates directory.

  • Real world

    And a complete working example at crocuda.nixos. Where all the magic happens in default.nix.

A single Top-level imports 🤌 (umports).

Use slib = inputs.nixos-tidy.lib

Get rid of imports statements everywhere. You only need one top-level imports statement.

It imports recursively all the files from inside a directory.

Nix only (without home-manager)

# flake.nix
imports = let
  slib = inputs.nixos-tidy.lib;
in
  []
  # Import all nixos modules recursively
  ++ slib.umportNixModules {
    paths = [
      inputs.anOtherFlake.nixosModules.default
      ./.
    ];
    exclude = [
      # Do not forget to exclude current file
      # and flake definition.
      ./default.nix
      ./flake.nix
    ];
  };

With home-manager

It enables a most wanted separation of concerns, where home-manager modules and nix modules can lay in the same directory.

.
├── gnome
│   ├── default.nix
│   ├── test.nix
│   └── home.nix
├── hyprland
│   ├── default.nix
│   ├── test.nix
│   └── home.nix
└── flake.nix # put boilerplate code at the flake top-level.
imports = let
  slib = inputs.nixos-tidy.lib;
in
  []
  # Import all nixos modules recursively
  ++ slib.umportNixModules {
    paths = [
      inputs.anOtherFlake.nixosModules.default
      ./.
    ];
    exclude = [
      # Do not forget to exclude current file
      # and flake definition.
      ./default.nix
      ./flake.nix
    ]
  }
  ++ slib.umportHomeModules {
    paths = [
      inputs.nur.modules.homeManager.default
      ./.
    ];
  }
  # Home-merger options
  {
    users = ["anon"];
  };

File naming constraints.

See the template flake with umports for a working example (with home-manager).

Umports makes the distinctions between module types based on filenames. So be sure to have your filenames checked.

Nix: *.nix Home-manager: home.nix || home.*.nix || home_*.nix Unit-tests: test.nix || test.*.nix || test_*.nix.

A flexible home-manager (Home-merger).

Use inputs.nixos-tidy.nixosModules.home-merger. Checkout module definition for options list.

Home-merger is a wrapper around home-manager that you can call multiple times, in order to scatter user definitions in separate files.

Top-level import (Umports)

  • Use it to split user definition.
# file_1.nix
home-merger = {
  users = ["alice"];
  umports.paths = [
    ./alice_modules
  ];
};
# file_2.nix
home-merger = {
  users = ["bob"];
  extraSpecialArgs = {inherit inputs;};
  imports = [
    inputs.anOtherModule.homeManagerModules.default
  ];
  umports.paths = [
    ./bob_modules
  ];
};
  • Or use it to import a home.nix module from an adjacent default.nix module.
.
└── fish
    ├── default.nix
    └── home.nix
# fish/default.nix
programs.fish.enable = true;

home-merger = {
  users = ["bob"];
  umports.paths = [
      ./home.nix
  ];
};
# fish/home.nix
home.programs.fish.enable = true;

Allow-unfree

Use inputs.nixos-tidy.nixosModules.allow-unfree

Cherry-pick unfree software exceptions with regexes.

#default.nix
allow-unfree = [
  # use regexes
  "nvidia-.*"
  "cuda.*"
];

Network privacy (ipv6)

Use inputs.nixos-tidy.nixosModules.networking-privacy

Not released yet. Only on dev branch.

Strengthen ipv6 privacy configuration for Linux kernel, NetworkManager, openvswitch, static configuration and systemd-networkd.

About

Nix functions to create sharable, flexible and standardized Nixos configurations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages