If it's only for your self I would write a nix module that does everything you need, then import the module in the system configuration. If you want to enable/disable it all you need is to add/remove one line in the imports section.
this post was submitted on 27 Apr 2025
15 points (100.0% liked)
Nix / NixOS
2152 readers
3 users here now
Main links
Videos
founded 2 years ago
MODERATORS
I'm a fan of putting factored expressions into their own files and importing those files as NixOS modules. For example, let's say that we want to install vim. We might start with a vim.nix
:
{ pkgs, ... }: {
environment.systemPackages = [ pkgs.vim ];
}
Then in the main configuration, this can be imported by path:
{
imports = [ ./vim.nix ];
}
Adding the import is like enabling the feature, but without any options
or config
. Later on, the feature can be customized without changing the import-oriented usage pattern:
{ pkgs, ... }:
let
vim = ...;
in {
environment.systemPackages = [ vim ];
}
Since the imported file is a complete NixOS module, it can carry other configuration. Here's a real example, adb.nix
, which adds Android debugger support:
{ pkgs, ... }: {
programs.adb.enable = true;
environment.systemPackages = [ pkgs.pmount ];
users.users.corbin.extraGroups = [ "adbusers" ];
}
Write a NixOS module, publish it in a flake in the nixosModules
output, import that flake in your flake-based NixOS configs.