diff --git a/README.md b/README.md index e97b51a..d4bd039 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,27 @@ -# Nixos on GCP +# Nixos on Google Cloud + +## Building image + +To build the gpc image use the below command + +```shell +nix build .#gcp +``` + +Once the image has been built, + + +```shell +python upload.py --file result/nixos-image-... +``` + + + +### GCE shit + + +#### Metadata ``` -img_path=$(echo result/*.tar.gz) -img_name=${IMAGE_NAME:-$(basename "$img_path")} -img_id=$(echo "$img_name" | sed 's|.raw.tar.gz$||;s|\.|-|g;s|_|-|g') -img_family=$(echo "$img_id" | cut -d - -f1-4) -gcloud compute images create "$img_id" --source-uri "gs://${BUCKET_NAME}/$img_name" --family="$img_family" -gcloud compute images add-iam-policy-binding "$img_id" --member='allAuthenticatedUsers' --role='roles/compute.imageUser' +enable-oslogin: TRUE ``` diff --git a/flake.nix b/flake.nix index 90686c8..c2a0792 100644 --- a/flake.nix +++ b/flake.nix @@ -18,7 +18,7 @@ system = "x86_64-linux"; modules = [ ./gcp-configuration.nix ]; - format = "gce"; + format = "vm"; pkgs = nixpkgs.legacyPackages.x86_64-linux; lib = nixpkgs.legacyPackages.x86_64-linux.lib; diff --git a/gcp-configuration.nix b/gcp-configuration.nix index 31fa37c..9add12c 100644 --- a/gcp-configuration.nix +++ b/gcp-configuration.nix @@ -4,6 +4,7 @@ config = { system.stateVersion = "23.11"; boot.kernel.sysctl."net.ipv4.ip_forward" = true; + networking.hostName = "trainer-0001"; networking.nameservers = [ "8.8.8.8" ]; @@ -27,6 +28,8 @@ }; }; + users.defaultUserShell = pkgs.zsh; + users.extraUsers.didier = { createHome = true; isNormalUser = true; @@ -35,6 +38,8 @@ group = "users"; extraGroups = [ "wheel" ]; useDefaultShell = true; + hashedPassword = + "$6$tFmX1GFwslsmHJ6A$9O7jYzbo6hV2/ed39Y.ynhqoQbsPAiqTW5HR1CvnubWBysaOljPtUHlnqaPbvEkxdjUwuqHwhhvWIvsHsSMmF1"; openssh.authorizedKeys.keys = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILtqtELim0nDxVG0j/IJc/ZcWYfFBCay8fVIw/16ieDy didier.amyot@all-dressed-programming.com" ]; @@ -54,5 +59,7 @@ services.openssh.settings.PasswordAuthentication = false; + programs.zsh.enable = true; + }; } diff --git a/unnamed.qcow2 b/unnamed.qcow2 new file mode 100644 index 0000000..5e6aee3 Binary files /dev/null and b/unnamed.qcow2 differ diff --git a/upload.py b/upload.py index 64b51de..44dada7 100644 --- a/upload.py +++ b/upload.py @@ -29,15 +29,14 @@ def main(file, bucket_name): cmd = [ 'gsutil', 'cp', file, s3_loc ] - check_call(cmd) + print(" ".join([str(s) for s in cmd])) + # return cmd = [ 'gcloud', 'compute','images','create', img_id, '--source-uri', s3_loc, '--family', img_family ] # check_call(cmd) - # print(' '.join(cmd)) - # return cmd = [ 'gcloud', 'compute', 'images', 'add-iam-policy-binding',