diff --git a/flake.lock b/flake.lock index ed3a4f5..5961158 100644 --- a/flake.lock +++ b/flake.lock @@ -95,6 +95,22 @@ "type": "github" } }, + "nixos-hardware": { + "locked": { + "lastModified": 1680876084, + "narHash": "sha256-eP9yxP0wc7XuVaODugh+ajgbFGaile2O1ihxiLxOuvU=", + "owner": "NixOS", + "repo": "nixos-hardware", + "rev": "3006d2860a6ed5e01b0c3e7ffb730e9b293116e2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "master", + "repo": "nixos-hardware", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1681303793, @@ -200,6 +216,7 @@ "inputs": { "home-manager": "home-manager", "nixos-cn": "nixos-cn", + "nixos-hardware": "nixos-hardware", "nixpkgs": "nixpkgs", "nixpkgs-stable": "nixpkgs-stable", "nur": "nur", diff --git a/flake.nix b/flake.nix index 3c3b675..10d3a93 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,8 @@ inputs.nixpkgs.follows = "nixpkgs"; }; + nixos-hardware.url = "github:NixOS/nixos-hardware/master"; + nixos-cn = { url = "github:nixos-cn/flakes"; # Use the same nixpkgs @@ -25,7 +27,8 @@ }; - outputs = { self, nixpkgs, nur, home-manager, sops-nix, nixos-cn, ... }@inputs: + outputs = { self, ... }@inputs: + with inputs; let mkHome = user: host: home-manager.nixosModules.home-manager { extraSpecialArgs = { inherit inputs; }; @@ -45,5 +48,27 @@ ]; specialArgs = inputs; }; + nixosConfigurations.rpi4 = nixpkgs.lib.nixosSystem { + system = "aarch64-linux"; + modules = [ + machines/rpi4/configuration.nix + nixos-hardware.nixosModules.raspberry-pi-4 + ]; + }; + + images.rpi4 = (nixpkgs.lib.nixosSystem { + system = "aarch64-linux"; + modules = [ + "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix" + machines/rpi4/configuration.nix + nixos-hardware.nixosModules.raspberry-pi-4 + { + nixpkgs.config.allowUnsupportedSystem = true; + nixpkgs.hostPlatform.system = "aarch64-linux"; + nixpkgs.buildPlatform.system = "x86_64-linux"; + # ... extra configs as above + } + ]; + }).config.system.build.sdImage; }; } diff --git a/machines/rpi4/configuration.nix b/machines/rpi4/configuration.nix new file mode 100644 index 0000000..230bca5 --- /dev/null +++ b/machines/rpi4/configuration.nix @@ -0,0 +1,38 @@ +{ config, libs, pkgs, ... }: + +{ + environment.systemPackages = with pkgs; [ + vim + ]; + nixpkgs.overlays = [ + # Workaround https://github.com/NixOS/nixpkgs/issues/126755#issuecomment-869149243 + (final: super: { + makeModulesClosure = x: + super.makeModulesClosure (x // { allowMissing = true; }); + }) + ]; + + imports = [ ]; + + system.stateVersion = "22.11"; + + networking = { + hostName = "pi-wh"; + useDHCP = false; + interfaces.eth0.useDHCP = true; + }; + + services.openssh = { + enable = true; + }; + + systemd.services.sshd.wantedBy = pkgs.lib.mkForce [ "multi-user.target" ]; + + users.users.pi = { + isNormalUser = true; + home = "/home/pi"; + extraGroups = [ "wheel" "networkmanager" ]; + openssh.authorizedKeys.keys = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIInPn+7cMbH7zCEPJArU/Ot6oq8NHo8a2rYaCfTp7zgd xin@nixos" ]; + }; + +} \ No newline at end of file