To home manager or not to home manager...?

hi every!!!

dont got a problem today, i actually want to share i something ive learned in nixOS today, so it could be rather obvious to some of you…

so, there is this option programs.yazi.initLua of type null or absolute path, right? one could think that, well, “that sucks! i guess only HOME MANAGER can help me now…”, and they would be right, because home manager, indeed, has this option of null or absolute path or strings concatenated with "\n" type, so it does allow you to actually write text straight away…

but what if i told you that you dont need home manager… most of the time…

below is an example of pkgs.yaziPlugins.full-border configuration:

  programs.yazi = {
  enable = true;
  plugins = {
    "full-border.yazi" = pkgs.yaziPlugins.full-border;
  };
  initLua = pkgs.writeText "init.lua" ''
    require("full-border"):setup {
      type = ui.Border.PLAIN,
    }
  '';

…because otherwise that plugin wont execute by itself.

THATS IT! short and sweet. with the power of… pkgs.writeText, which also has one with subdirectories, pkgs.writeTextDir, that are documented here:

https://nixos.org/manual/nixpkgs/unstable/#trivial-builder-writeText

BUT OF COURSE! this isnt limited only to yazi, this can be applied ANYWHERE… as long as they are not dotfiles in $HOME, that is… then that’d be home manager, most certainly

but there’s more! you can use enviornment.etc. to write files (symlinks) to etc/:

environment.etc."path/to/foo.bar".text = ''
  echo OMG
'';

this was mindblowing to me, so i apologise if this wasnt worthwhile to all of you…

byebye!!!

1 Like

Yup, realizing you can just… make a file as needed anywhere in the nix language is often a mindblowing moment.

Though I’ll also point out, you don’t even need nixpkgs available in order to do this (so long as you don’t want to put any store paths into the file, anyway), as builtins.toFile also exists.

1 Like