diff --git a/flake.nix b/flake.nix index 329bc9c..f925a36 100644 --- a/flake.nix +++ b/flake.nix @@ -37,6 +37,8 @@ ./public-keys ./lib ./overlays + ./modules + ./hosts ]; perSystem = { system, pkgs, config, ... }: { @@ -73,88 +75,11 @@ flake = let username = "barkeeper"; - system = "x86_64-linux"; in { - nixosConfigurations = { - nachtigall = self.nixos-flake.lib.mkLinuxSystem { - imports = [ - self.nixosModules.common - ./hosts/nachtigall - self.pub-solar.lib.linux.unlockZFSOnBoot - self.nixosModules.home-manager - self.nixosModules.linux - self.nixosModules.overlays - inputs.agenix.nixosModules.default - { - home-manager.users.${username} = { - imports = [ - self.homeModules.common - ]; - home.stateVersion = "23.05"; - }; - } - ]; - }; - }; + inherit username; checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) inputs.deploy-rs.lib; - nixosModules = { - # Common nixos/nix-darwin configuration shared between Linux and macOS. - common = { pkgs, ... }: { - virtualisation.docker = { - enable = true; - extraOptions = '' - --data-root /var/lib/docker - ''; - storageDriver = "zfs"; - }; - - services.openssh.enable = true; - services.openssh.settings.PermitRootLogin = "prohibit-password"; - services.openssh.settings.PasswordAuthentication = false; - }; - - # NixOS specific configuration - linux = { pkgs, ... }: { - users.users.${username} = { - name = username; - group = username; - extraGroups = ["wheel"]; - isNormalUser = true; - openssh.authorizedKeys.keys = self.publicKeys.allAdmins; - }; - users.groups.${username} = {}; - - security.sudo.wheelNeedsPassword = false; - nix.settings.trusted-users = [ "root" username ]; - - # TODO: Remove when we stop locking ourselves out. - users.users.root.openssh.authorizedKeys.keys = self.publicKeys.allAdmins; - }; - }; - - # All home-manager configurations are kept here. - homeModules = { - # Common home-manager configuration shared between Linux and macOS. - common = { pkgs, ... }: { - programs.git.enable = true; - programs.starship.enable = true; - programs.bash.enable = true; - programs.neovim = { - enable = true; - vimAlias = true; - viAlias = true; - defaultEditor = true; - # configure = { - # packages.myVimPackages = with pkgs.vimPlugins; { - # start = [vim-nix vim-surrund rainbow]; - # }; - # }; - }; - }; - }; - deploy.nodes = self.pub-solar.lib.deploy.mkDeployNodes self.nixosConfigurations { nachtigall = { sshUser = username; diff --git a/hosts/default.nix b/hosts/default.nix new file mode 100644 index 0000000..8a2913b --- /dev/null +++ b/hosts/default.nix @@ -0,0 +1,18 @@ + { self, ... }: + { + flake = { + nixosConfigurations = { + nachtigall = self.nixos-flake.lib.mkLinuxSystem { + imports = [ + self.inputs.agenix.nixosModules.default + self.nixosModules.home-manager + ./nachtigall + self.nixosModules.overlays + self.nixosModules.unlock-zfs-on-boot + self.nixosModules.core + self.nixosModules.docker + ]; + }; + }; + }; + } diff --git a/hosts/nachtigall/configuration.nix b/hosts/nachtigall/configuration.nix index ea1b774..19b9048 100644 --- a/hosts/nachtigall/configuration.nix +++ b/hosts/nachtigall/configuration.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: +{ config, pkgs, flake, ... }: { # Use GRUB2 as the boot loader. # We don't use systemd-boot because Hetzner uses BIOS legacy boot. @@ -39,26 +39,9 @@ systemPackages = with pkgs; [ vim ]; }; - users.users.hakkonaut = { - description = "CI and automation user"; - home = "/home/hakkonaut"; - createHome = true; - useDefaultShell = true; - uid = 998; - group = "hakkonaut"; - isSystemUser = true; - openssh.authorizedKeys.keys = [ - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGP5MvCwNRtCcP1pSDrn0XZTNlpOqYnjHDm9/OI4hECW hakkonaut@flora-6" - ]; - }; - # https://nixos.wiki/wiki/ZFS#declarative_mounting_of_ZFS_datasets systemd.services.zfs-mount.enable = false; - users.groups.hakkonaut = {}; - - users.users.root.initialHashedPassword = "$y$j9T$bIN6GjQkmPMllOcQsq52K0$q0Z5B5.KW/uxXK9fItB8H6HO79RYAcI/ZZdB0Djke32"; - # This value determines the NixOS release with which your system is to be # compatible, in order to avoid breaking some software such as database # servers. You should change this only after NixOS release notes say you diff --git a/hosts/nachtigall/default.nix b/hosts/nachtigall/default.nix index 4780506..9f3aabc 100644 --- a/hosts/nachtigall/default.nix +++ b/hosts/nachtigall/default.nix @@ -7,7 +7,6 @@ ./configuration.nix ./networking.nix - ./nix.nix ./apps/nginx.nix ./apps/collabora.nix diff --git a/hosts/nachtigall/networking.nix b/hosts/nachtigall/networking.nix index 82470b0..5328cc4 100644 --- a/hosts/nachtigall/networking.nix +++ b/hosts/nachtigall/networking.nix @@ -21,14 +21,4 @@ ]; networking.defaultGateway = "138.201.80.65"; networking.defaultGateway6 = { address = "fe80::1"; interface = "enp35s0"; }; - - services.resolved = { - enable = true; - extraConfig = '' - DNS=193.110.81.0#dns0.eu 185.253.5.0#dns0.eu 2a0f:fc80::#dns0.eu 2a0f:fc81::#dns0.eu 9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net - FallbackDNS=5.1.66.255#dot.ffmuc.net 185.150.99.255#dot.ffmuc.net 2001:678:e68:f000::#dot.ffmuc.net 2001:678:ed0:f000::#dot.ffmuc.net - Domains=~. - DNSOverTLS=yes - ''; - }; } diff --git a/lib/default.nix b/lib/default.nix index 20566ff..d7448e4 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -11,10 +11,6 @@ ## In configs, they can be used under "lib.our" deploy = import ./deploy.nix { inherit inputs lib; }; - - linux = { - unlockZFSOnBoot = import ./unlock-zfs-on-boot.nix {publicKeys = self.publicKeys.allAdmins;}; - }; }; }; } diff --git a/modules/default.nix b/modules/default.nix new file mode 100644 index 0000000..16ac03f --- /dev/null +++ b/modules/default.nix @@ -0,0 +1,26 @@ +{ self, ... }: +{ + flake = { + nixosModules = rec { + nix = import ./nix.nix; + networking = import ./networking.nix; + unlock-zfs-on-boot = import ./unlock-zfs-on-boot.nix; + docker = import ./docker.nix; + terminal-tooling = import ./terminal-tooling.nix; + users = import ./users.nix; + + core = { + imports = [ + nix + networking + terminal-tooling + users + ]; + + home-manager.users.${self.username} = { + home.stateVersion = "23.05"; + }; + }; + }; + }; +} diff --git a/modules/docker.nix b/modules/docker.nix new file mode 100644 index 0000000..8021dad --- /dev/null +++ b/modules/docker.nix @@ -0,0 +1,9 @@ +{ pkgs, ... }: { + virtualisation.docker = { + enable = true; + extraOptions = '' + --data-root /var/lib/docker + ''; + storageDriver = "zfs"; + }; +} diff --git a/modules/networking.nix b/modules/networking.nix new file mode 100644 index 0000000..bd27877 --- /dev/null +++ b/modules/networking.nix @@ -0,0 +1,15 @@ +{ pkgs, ... }: { + services.openssh.enable = true; + services.openssh.settings.PermitRootLogin = "prohibit-password"; + services.openssh.settings.PasswordAuthentication = false; + + services.resolved = { + enable = true; + extraConfig = '' + DNS=193.110.81.0#dns0.eu 185.253.5.0#dns0.eu 2a0f:fc80::#dns0.eu 2a0f:fc81::#dns0.eu 9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net + FallbackDNS=5.1.66.255#dot.ffmuc.net 185.150.99.255#dot.ffmuc.net 2001:678:e68:f000::#dot.ffmuc.net 2001:678:ed0:f000::#dot.ffmuc.net + Domains=~. + DNSOverTLS=yes + ''; + }; +} diff --git a/hosts/nachtigall/nix.nix b/modules/nix.nix similarity index 95% rename from hosts/nachtigall/nix.nix rename to modules/nix.nix index ec0040b..c1e3218 100644 --- a/hosts/nachtigall/nix.nix +++ b/modules/nix.nix @@ -36,7 +36,7 @@ nixPath = [ "nixpkgs=${flake.inputs.nixpkgs}" - "nixos-config=${../../lib/compat/nixos}" + "nixos-config=${../lib/compat/nixos}" "home-manager=${flake.inputs.home-manager}" ]; }; diff --git a/modules/terminal-tooling.nix b/modules/terminal-tooling.nix new file mode 100644 index 0000000..c0d0050 --- /dev/null +++ b/modules/terminal-tooling.nix @@ -0,0 +1,18 @@ +{ flake, ... }: { + home-manager.users.${flake.self.username} = { + programs.git.enable = true; + programs.starship.enable = true; + programs.bash.enable = true; + programs.neovim = { + enable = true; + vimAlias = true; + viAlias = true; + defaultEditor = true; + # configure = { + # packages.myVimPackages = with pkgs.vimPlugins; { + # start = [vim-nix vim-surrund rainbow]; + # }; + # }; + }; + }; +} diff --git a/lib/unlock-zfs-on-boot.nix b/modules/unlock-zfs-on-boot.nix similarity index 92% rename from lib/unlock-zfs-on-boot.nix rename to modules/unlock-zfs-on-boot.nix index 529b272..2e507df 100644 --- a/lib/unlock-zfs-on-boot.nix +++ b/modules/unlock-zfs-on-boot.nix @@ -1,4 +1,4 @@ -{publicKeys}: { +{ flake, ... }: { # From https://nixos.wiki/wiki/ZFS#Unlock_encrypted_zfs_via_ssh_on_boot boot.initrd.network = { enable = true; @@ -10,7 +10,7 @@ # Please create this manually the first time. hostKeys = [ "/etc/secrets/initrd/ssh_host_ed25519_key" ]; - authorizedKeys = publicKeys; + authorizedKeys = flake.self.publicKeys.admins; }; # this will automatically load the zfs password prompt on login # and kill the other prompt so boot can continue diff --git a/modules/users.nix b/modules/users.nix new file mode 100644 index 0000000..5f8b43c --- /dev/null +++ b/modules/users.nix @@ -0,0 +1,30 @@ +{ flake, pkgs, ... }: { + users.users.${flake.self.username} = { + name = flake.self.username; + group = flake.self.username; + extraGroups = ["wheel"]; + isNormalUser = true; + openssh.authorizedKeys.keys = flake.self.publicKeys.admins; + }; + users.groups.${flake.self.username} = {}; + + # TODO: Remove when we stop locking ourselves out. + users.users.root.openssh.authorizedKeys.keys = flake.self.publicKeys.admins; + + users.users.hakkonaut = { + description = "CI and automation user"; + home = "/home/hakkonaut"; + createHome = true; + useDefaultShell = true; + uid = 998; + group = "hakkonaut"; + isSystemUser = true; + openssh.authorizedKeys.keys = flake.self.publicKeys.robots; + }; + + users.groups.hakkonaut = {}; + + users.users.root.initialHashedPassword = "$y$j9T$bIN6GjQkmPMllOcQsq52K0$q0Z5B5.KW/uxXK9fItB8H6HO79RYAcI/ZZdB0Djke32"; + + security.sudo.wheelNeedsPassword = false; +} diff --git a/public-keys/default.nix b/public-keys/default.nix index a5fdaa3..f7f05ee 100644 --- a/public-keys/default.nix +++ b/public-keys/default.nix @@ -2,7 +2,8 @@ { flake = { publicKeys = { - allAdmins = lib.attrsets.attrValues (import ./admins.nix); + admins = lib.attrsets.attrValues (import ./admins.nix); + robots = lib.attrsets.attrValues (import ./robots.nix); }; }; } diff --git a/public-keys/robots.nix b/public-keys/robots.nix new file mode 100644 index 0000000..83b6cb8 --- /dev/null +++ b/public-keys/robots.nix @@ -0,0 +1,7 @@ +{ + # Used for restic backups to droppie, a server run by @b12f + "root@droppie" = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBZQSephFJU0NMbVbhwvVJ2/m6jcPYo1IsWCsoarqKin root@droppie"; + + # robot user on flora-6 + "hakkonaut@flora-6" = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGP5MvCwNRtCcP1pSDrn0XZTNlpOqYnjHDm9/OI4hECW hakkonaut@flora-6"; +}