aboutsummaryrefslogtreecommitdiffstats
path: root/modules/by-name/ni/nixos-shell/module.nix
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-05-17 13:39:56 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-05-17 13:39:56 +0200
commitde11e018dca18d11499debb8102ba6151cc21834 (patch)
tree22c06529d68394cd19ec7792f5e71c6f2a230b4a /modules/by-name/ni/nixos-shell/module.nix
parentpkgs/default.nix: Migrate to the package arguments (diff)
downloadnixos-config-de11e018dca18d11499debb8102ba6151cc21834.zip
modules/nixos-shell: Init
A VM at your disposal. This is based on: https://github.com/Mic92/nixos-shell
Diffstat (limited to '')
-rw-r--r--modules/by-name/ni/nixos-shell/module.nix128
1 files changed, 128 insertions, 0 deletions
diff --git a/modules/by-name/ni/nixos-shell/module.nix b/modules/by-name/ni/nixos-shell/module.nix
new file mode 100644
index 00000000..219f080d
--- /dev/null
+++ b/modules/by-name/ni/nixos-shell/module.nix
@@ -0,0 +1,128 @@
+# nixos-config - My current NixOS configuration
+#
+# Copyright (C) 2025 Jörg Thalheim and contributors
+# SPDX-License-Identifier: MIT
+#
+# This file is part of my nixos-config.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+{
+ lib,
+ config,
+ pkgs,
+ self,
+ ...
+}: let
+ cfg = config.soispha.nixos-shell;
+in {
+ options.soispha.nixos-shell = {
+ enable = lib.mkEnableOption "nixos-shell";
+
+ user_name = lib.mkOption {
+ type = lib.types.str;
+ default = "soispha";
+ description = "The user to auto-login into the vm.";
+ };
+
+ configuration = {
+ specialArgs = lib.mkOption {
+ type = lib.types.attrsOf lib.types.anything;
+ default = {};
+ description = ''
+ The arguments to pass to the `specialArgs` attribute set.
+ '';
+ };
+ value = lib.mkOption {
+ type = lib.types.deferredModule;
+ default = {};
+ description = ''
+ Additional NixOS configuration to load into the VM's config.
+ '';
+ };
+ };
+
+ mounts = lib.mkOption {
+ type = lib.types.attrsOf (lib.types.submodule ({config, ...}: {
+ options = {
+ target = lib.mkOption {
+ type = lib.types.path;
+ description = "Target on the guest.";
+ };
+
+ cache_mode = lib.mkOption {
+ type = lib.types.enum ["none" "loose" "fscache" "mmap"];
+ default = "loose"; # bad idea? Well, at least it is fast!1!!
+ description = "9p caching policy";
+ };
+
+ readOnly =
+ (lib.mkEnableOption "mount this disk in read-only mode")
+ // {
+ default = true;
+ };
+
+ tag = lib.mkOption {
+ type = lib.types.str;
+ internal = true;
+ };
+ };
+
+ config.tag = lib.mkDefault (
+ builtins.substring 0 31 ( # tags must be shorter than 32 bytes
+ "a"
+ + # tags must not begin with a digit
+ builtins.hashString "md5" config._module.args.name
+ )
+ );
+ }));
+ default = {};
+ description = ''
+ Extra paths to make available in the vm.
+ These will be mounted ro to their `target.`
+ '';
+ };
+ };
+
+ config = let
+ vmSystem = self.inputs.nixpkgs.lib.nixosSystem {
+ inherit (cfg.configuration) specialArgs;
+
+ modules = [
+ {
+ # TODO(@bpeetz): This should be bumped each release. <2025-05-17>
+ system.stateVersion = "25.05";
+ }
+
+ cfg.configuration.value
+
+ (import ./shell_setup.nix {inherit cfg;})
+ ];
+ };
+
+ nixos-shell = pkgs.writeShellApplication {
+ name = "nixos-shell";
+ text = builtins.readFile ./nixos-shell.sh;
+
+ # We need to keep the PATH, as we otherwise can't pass it along.
+ inheritPath = true;
+
+ runtimeInputs = [
+ vmSystem.config.system.build.vm
+ pkgs.mktemp
+ pkgs.coreutils
+ pkgs.moreutils # for sponge
+ ];
+ runtimeEnv = {
+ HOST_NAME = vmSystem.config.system.name;
+ };
+ };
+ in
+ lib.mkIf cfg.enable {
+ environment.systemPackages = [
+ nixos-shell
+ ];
+
+ system.build.nixos-shell = vmSystem.config.system.build.vm;
+ };
+}