commit 47dd9a11373274f3e90abef7e0eee329da473354 Author: didier amyot Date: Thu Oct 24 19:59:09 2024 -0400 build gcp image diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..22324b2 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ + use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a96a7f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +nixpkgs +nixpkgs +result +.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ef5a836 --- /dev/null +++ b/flake.lock @@ -0,0 +1,98 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixlib": { + "locked": { + "lastModified": 1729386149, + "narHash": "sha256-hUP9oxmnOmNnKcDOf5Y55HQ+NnoT0+bLWHLQWLLw9Ks=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "cce4521b6df014e79a7b7afc58c703ed683c916e", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixos-generators": { + "inputs": { + "nixlib": "nixlib", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1729472750, + "narHash": "sha256-s93LPHi5BN7I2xSGNAFWiYb8WRsPvT1LE9ZjZBrpFlg=", + "owner": "nix-community", + "repo": "nixos-generators", + "rev": "7c60ba4bc8d6aa2ba3e5b0f6ceb9fc07bc261565", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixos-generators", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1729658218, + "narHash": "sha256-9Rg+AqLqvqqJniP/OQB3GtgXoAd8IlazsHp97va042Y=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "dfffb2e7a52d29a0ef8e21ec8a0f30487b227f1a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixos-generators": "nixos-generators", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..456e8d0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,36 @@ +{ + description = "Tool to build NixOS for GCP. "; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + nixos-generators = { + url = "github:nix-community/nixos-generators"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, flake-utils, nixos-generators }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + gcp = nixos-generators.nixosGenerate { + system = "x86_64-linux"; + + modules = [ ./gcp-configuration.nix ]; + format = "gce"; + + pkgs = nixpkgs.legacyPackages.x86_64-linux; + lib = nixpkgs.legacyPackages.x86_64-linux.lib; + }; + in { + + packages.gcp = gcp; + devShells.default = pkgs.mkShell { + buildInputs = [ pkgs.google-cloud-sdk ]; + shellHook = '' + export PROJECT_ID="all-dressed-programming" + export BUCKET_NAME="nautilus-plus" + ''; + }; + }); +} diff --git a/gcp-configuration.nix b/gcp-configuration.nix new file mode 100644 index 0000000..3924981 --- /dev/null +++ b/gcp-configuration.nix @@ -0,0 +1,33 @@ +{ pkgs, lib, modulesPath, ... }: { + imports = [ "${modulesPath}/virtualisation/google-compute-image.nix" ]; + + config = { + system.stateVersion = "23.11"; + boot.kernel.sysctl."net.ipv4.ip_forward" = true; + + networking.nameservers = [ "8.8.8.8" ]; # Todo: include? "169.254.169.254"]; + + virtualisation.containers.enable = true; + virtualisation.docker = { + enable = true; + autoPrune.enable = true; + }; + + nix = { + settings.auto-optimise-store = true; + extraOptions = '' + experimental-features = nix-command flakes + min-free = ${toString (100 * 1024 * 1024)} + max-free = ${toString (1024 * 1024 * 1024)} + ''; + gc = { + automatic = true; + dates = "weekly"; + options = "--delete-older-than 60d --max-freed $((1024**3))"; + }; + }; + + services.openssh.settings.PasswordAuthentication = false; + + }; +}