commit 7fa4bb5fa62359b9d811255429d332ccc44a0ed0 Author: Alexander Kobjolke Date: Sun Jan 14 11:50:31 2024 +0100 Initial commit diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..faf3fdd --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.pre-commit-config.yaml +result +.direnv +nixos.qcow2 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..913bdf6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,44 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1652776076, + "narHash": "sha256-gzTw/v1vj4dOVbpBSJX4J0DwUR6LIyXo7/SuuTJp1kM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "04c1b180862888302ddfb2e3ad9eaa63afc60cf8", + "type": "github" + }, + "original": { + "owner": "numtide", + "ref": "v1.0.0", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1701282334, + "narHash": "sha256-MxCVrXY6v4QmfTwIysjjaX0XUhqBbxTWWB4HXtDYsdk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "057f9aecfb71c4437d2b27d3323df7f93c010b7e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..fa619a0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,53 @@ +{ + inputs = { + flake-utils.url = "github:numtide/flake-utils/v1.0.0"; + + nixpkgs.url = "github:NixOS/nixpkgs/23.11"; + }; + + outputs = { flake-utils, nixpkgs, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages."${system}"; + + base = { lib, modulesPath, ... }: { + imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ]; + + # https://github.com/utmapp/UTM/issues/2353 + networking.nameservers = lib.mkIf pkgs.stdenv.isDarwin [ "8.8.8.8" ]; + + virtualisation = { + graphics = false; + + host = { inherit pkgs; }; + }; + }; + + machine = nixpkgs.lib.nixosSystem { + system = builtins.replaceStrings [ "darwin" ] [ "linux" ] system; + + modules = [ base ./module.nix ]; + }; + + program = pkgs.writeShellScript "run-vm.sh" '' + export NIX_DISK_IMAGE=$(mktemp -u -t nixos.qcow2) + + trap "rm -f $NIX_DISK_IMAGE" EXIT + + ${machine.config.system.build.vm}/bin/run-nixos-vm + ''; + + in { + packages = { inherit machine; }; + + apps.default = { + type = "app"; + + program = "${program}"; + }; + + devShells.default = + pkgs.mkShell { buildInputs = with pkgs; [ nixfmt nil ]; }; + + }); +} diff --git a/module.nix b/module.nix new file mode 100644 index 0000000..5ec0ece --- /dev/null +++ b/module.nix @@ -0,0 +1,2 @@ +{ services.getty.autologinUser = "root"; +}