Skip to content

Commit

Permalink
require network connection for home-config clone
Browse files Browse the repository at this point in the history
the general idea is described here:
<https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/>

note that all machines also need `network-manager` for this to work.
otherwise the appropriate `systemd` unit
`NetworkManager-wait-online.service` will be broken (even if it exists,
which is really confusing).

unfortunately waiting for the network to be up with
`network-online.target` will not work because of inconsistent service names:
<NixOS/nixpkgs#59603>

it seems that NixOS 19.03 still is not fixed in that regard:
<NixOS/nixpkgs#59603>

on NixOS 18.09 it will only work after this commit:
<NixOS/nixpkgs@022eb6a>

as we want the service to run immediately after bootstrapping (which is
the whole point of this project), you have to build your own image for
that, as currently the latest 18.09 release binary does not incorporate
above patch.

here is how to build an image:
<https://nixos.org/nixos/manual/index.html#sec-building-cd>

even more unfortunately building `release-18.09` branch will fail due to
a deprecated kernel API used by ZFS, used for the NixOS minimal image:
<NixOS/nixpkgs#60907>

    git clone https://github.com/NixOS/nixpkgs \
    # fix is on 18.09, and the repository is huge
    --single-branch --branch release-18.09 --depth 200
    # commit 44c66417f4e05f0a211735f024b58bdb9770108f
    # Author: Tim Steinbach <[email protected]>
    # Date:   Thu May 2 13:19:13 2019 -0400
    #
    #     linux: 4.19.37 -> 4.19.38
    #
    #     (cherry picked from commit e0bf73dbde74e66167bd9ccf385a1fbc228c4036)
    git checkout 44c66417f4e05f0a211735f024b58bdb9770108f~1
    cd nixpkgs/nixos
    nix-build -A config.system.build.isoImage \
    -I nixos-config=nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix \
    nixpkgs/nixos/default.nix --max-jobs auto --cores $(nproc)

in both cases you have to add these lines to the config:

    systemd.services.NetworkManager-wait-online = {
      wantedBy = [ "network-online.target" ];
    };

which corresponds to a patch on `master`:
<NixOS/nixpkgs@4588661>

this is what you get if you want to use immature software...
  • Loading branch information
fricklerhandwerk committed Sep 11, 2022
1 parent a9d2d87 commit cafeb78
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 5 additions & 0 deletions machines/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ with config;
nssmdns = true;
};

networking.networkmanager.enable = true;
systemd.services.NetworkManager-wait-online = {
wantedBy = [ "network-online.target" ];
};

programs.fish.enable = true;
}
2 changes: 0 additions & 2 deletions machines/x240/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ in
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;

networking.networkmanager.enable = true;

services.xserver = {
enable = true;
displayManager.lightdm.enable = true;
Expand Down
4 changes: 2 additions & 2 deletions modules/home-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ in
nameValuePair ("home-config-${utils.escapeSystemdPath username}") {
description = "initial home-manager configuration for ${username}";
wantedBy = [ "multi-user.target" ];
wants = [ "nix-daemon.socket" ];
after = [ "nix-daemon.socket" ];
after = [ "nix-daemon.socket" "network-online.target" ];
requires = [ "nix-daemon.socket" "network-online.target" ];
serviceConfig = with pkgs; {
User = username;
Type = "oneshot";
Expand Down

0 comments on commit cafeb78

Please sign in to comment.