Hi! I’m trying out Nix and I’m trying to set up and organize everything. Usually I put all my configs in a directory which is also a git repo and synced to my NAS, using the same subfolders they’d be in, and use GNU Stow to symlink the top-level folders (/dotfiles/home/ to /home/username/, /dotfiles/etc to /etc and /dotfiles/usr to /usr) and let it do its thing. Would it cause problems to also do that for configuration.nix?

On Arch I already had a /dotfiles/etc symlinked to /etc for my custom keyboard layouts, which worked fine… until the update which moved the location of the GUI keyboard layouts. It prevented the update so I undid the symlinks, updated, and put them again to the new location… but somehow it broke everything except the tty and no Wayland compositor I tried would work anymore (and there went my record of having never broken Arch since the first install over a year ago 😅 )

So I’m kinda wary of doing it on an even more critical file… but also I’m very lazy and having everything in a single repo is very convenient… How do you do it?

    • phantomwise@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      3
      ·
      12 days ago

      Thanks! it’s good to know, I was worried about breaking stuff on an unfamiliar system 😅

  • dinckel@lemmy.world
    link
    fedilink
    English
    arrow-up
    5
    ·
    12 days ago

    If you’re not using flakes: nixos-rebuild switch -I nixos-config=path/to/configuration.nix

    If you are:
    nixos-rebuild switch --flake path/to/flake.nix#hostname or a shorter nixos-rebuild switch --flake .#hostname where . is the current path, assuming you’re already navigated to where flake.nix is

    • eneff@discuss.tchncs.de
      link
      fedilink
      English
      arrow-up
      5
      ·
      12 days ago

      FYI – The reference to the flake doesn’t have to be a path, but can also point to git repositories. This let’s you do fun stuff like:

      nixos-rebuild switch --flake github:myusername/mynixosrepo

      The default fragment name used is the current hostname of the machine, so it can be omitted most of the time.

      • dinckel@lemmy.world
        link
        fedilink
        English
        arrow-up
        3
        ·
        12 days ago

        That’s actually pretty sick. I knew you could run things this way, but not rebuild

  • balsoft@lemmy.ml
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    11 days ago

    The “nix way” to handle this is actually to have all your dotfiles generated and “installed” by Nix as part of your NixOS config (via home-manager), and keep your NixOS config in a git repo that you then nixos-rebuild from (either with nixos-rebuild switch -I nixos-config=. or nixos-rebuild switch --flake ., depending on if you’re using flakes or not).

    So I’m kinda wary of doing it on an even more critical file

    Actually, configuration.nix is not critical to the functioning of the system at all; it is only read at “evaluation time”, i.e. when you are using nixos-rebuild. As long as it’s under a VCS (i.e. you won’t lose the contents by the time you want to nixos-rebuild again), you have nothing to worry about. You can ship a NixOS system without it (in fact that’s kind of the default). (unrelated but fun fact: you can also ship a NixOS system without Nix, it’s not actually needed for it to run!)

    • phantomwise@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      7 days ago

      That’s reassuring thanks! I’m not planning on using home manager for now because it makes more sense to keep original config files so I can use them both on Nix and Arch, but I’ll need to look into it when I set up my media server (I know I know, reasonable people just do a debian server, but that seems really boring 😅 ).

      unrelated but fun fact: you can also ship a NixOS system without Nix, it’s not actually needed for it to run! Wait without which Nix? the package manager or the language or something else? (Why is EVERYTHING called “Nix”? 😭 )

      • balsoft@lemmy.ml
        link
        fedilink
        English
        arrow-up
        2
        ·
        edit-2
        7 days ago

        Wait without which Nix? the package manager or the language or something else?

        Yes, without the package manager. Shipping “with a language” doesn’t make much sense :)

        • phantomwise@lemmy.mlOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          6 days ago

          Ah for a moment I had a false hope that maybe you could replace it with another language that didn’t have error messages from hell 😅

    • phantomwise@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      12 days ago

      Thanks for the reply! Not using flakes so I won’t have to worry about that, things are already confusing enough 😁

  • Arkhive (they/she)@lemmy.blahaj.zone
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    10 days ago

    The nix wiki actually contains a way to handle this. If you look up “NixOS configuration editors” it has a couple quick commands to make a folder in your user space and link it to the default location of your nix config. This allows you to edit your config without having to escalate privileges of your editor.

    • phantomwise@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      edit-2
      12 days ago

      Yes that’s what I’m using, it’s really a great program! But I was wondering if configuration.nix being a symlink would cause problems or if it was fine

      Edit: Ah someone else already replied that it was fine 🙂