Modular, context-aware and aspect-oriented dendritic Nix configurations. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ den.oeiuwq.com
configurations den dendritic nix aspect oriented

add `wsl` class and den.ctx.wsl-host (#213)

closes #209

authored by oeiuwq.com and committed by

GitHub 94fbfc95 26b263bc

+96 -7
+4 -7
modules/aspects/provides/primary-user.nix
··· 1 - { lib, ... }: 1 + { lib, den, ... }: 2 2 let 3 3 description = '' 4 4 Sets user as *primary*. 5 5 6 6 On NixOS adds wheel and networkmanager groups. 7 7 On Darwin sets user as system.primaryUser 8 - On WSL sets wsl.defaultUser if host has an `wsl` attribute. 8 + On WSL sets defaultUser if host has `wsl` support. 9 9 10 10 ## Usage 11 11 ··· 15 15 16 16 userToHostContext = 17 17 { user, host, ... }: 18 - let 19 - on-wsl.nixos.wsl.defaultUser = user.userName; 20 - in 21 18 { 22 19 inherit description; 23 - includes = lib.optionals (host ? wsl) [ on-wsl ]; 24 20 darwin.system.primaryUser = user.userName; 21 + wsl.defaultUser = user.userName; 25 22 nixos.users.users.${user.userName} = { 26 23 isNormalUser = true; 27 24 extraGroups = [ ··· 33 30 34 31 in 35 32 { 36 - den.provides.primary-user = userToHostContext; 33 + den.provides.primary-user = den.lib.take.exactly userToHostContext; 37 34 }
+63
modules/aspects/provides/wsl.nix
··· 1 + { 2 + den, 3 + lib, 4 + inputs, 5 + ... 6 + }: 7 + let 8 + description = '' 9 + Enables WSL support on NixOS. Using NixOS-WSL project. 10 + 11 + # Requirements 12 + 13 + - have an inputs.nixos-wsl input or specify host.wsl.module. 14 + - host.class is "nixos" 15 + 16 + # Usage 17 + 18 + On a single host: 19 + 20 + den.hosts.x86_64-linux.igloo.wsl.enable = true; 21 + 22 + On ALL hosts (works only on nixos class hosts): 23 + 24 + den.base.host.wsl.enable = true; 25 + ''; 26 + 27 + ctx.host.into.wsl-host = 28 + { host }: lib.optional (host.class == "nixos" && host.wsl.enable) { inherit host; }; 29 + 30 + ctx.wsl-host.provides.wsl-host = 31 + { host }: 32 + { 33 + inherit description; 34 + ${host.class}.imports = [ host.wsl.module ]; 35 + includes = [ (fwd host) ]; 36 + }; 37 + 38 + fwd = 39 + host: 40 + { class, aspect-chain }: 41 + den._.forward { 42 + each = lib.singleton true; 43 + fromClass = _: "wsl"; 44 + intoClass = _: host.class; 45 + intoPath = _: [ "wsl" ]; 46 + fromAspect = _: lib.head aspect-chain; 47 + guard = { options, ... }: options ? wsl; 48 + }; 49 + 50 + hostConf.options.wsl = { 51 + enable = lib.mkEnableOption "Enable WSL on this host"; 52 + module = lib.mkOption { 53 + description = "The NixOS-WSL module"; 54 + type = lib.types.deferredModule; 55 + default = inputs.nixos-wsl.nixosModules.default; 56 + }; 57 + }; 58 + 59 + in 60 + { 61 + den.ctx = ctx; 62 + den.base.host.imports = [ hostConf ]; 63 + }
+29
templates/ci/modules/features/wsl-class.nix
··· 1 + { denTest, ... }: 2 + let 3 + mockWslModule = 4 + { lib, ... }: 5 + { 6 + options.wsl.defaultUser = lib.mkOption { type = lib.types.str; }; 7 + }; 8 + in 9 + { 10 + flake.tests.wsl-class = { 11 + 12 + test-wsl-forwards = denTest ( 13 + { den, igloo, ... }: 14 + { 15 + den.hosts.x86_64-linux.igloo = { 16 + wsl.enable = true; 17 + wsl.module = mockWslModule; 18 + users.tux = { }; 19 + }; 20 + 21 + den.aspects.tux.includes = [ den.provides.primary-user ]; 22 + 23 + expr = igloo.wsl.defaultUser; 24 + expected = "tux"; 25 + } 26 + ); 27 + 28 + }; 29 + }