Initial commit: Nix WSL Wrapper project with DDD, Clean Code, and tests

This commit is contained in:
Marek Novák
2026-07-01 02:04:43 +02:00
commit 161eb7d387
22 changed files with 932 additions and 0 deletions
@@ -0,0 +1,52 @@
using System;
namespace NixWslWrapper.Core.Domain
{
public class WslTarget
{
public string Distribution { get; }
public string User { get; }
public string NixProfilePath { get; }
public WslTarget(string distribution, string user, string nixProfilePath = "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh")
{
if (string.IsNullOrWhiteSpace(distribution))
throw new ArgumentException("WSL Distribution name cannot be null or empty.", nameof(distribution));
if (string.IsNullOrWhiteSpace(user))
throw new ArgumentException("WSL User cannot be null or empty.", nameof(user));
if (string.IsNullOrWhiteSpace(nixProfilePath))
throw new ArgumentException("Nix Profile Path cannot be null or empty.", nameof(nixProfilePath));
Distribution = distribution.Trim();
User = user.Trim();
NixProfilePath = nixProfilePath.Trim();
}
public override bool Equals(object? obj)
{
if (obj is not WslTarget other) return false;
return string.Equals(Distribution, other.Distribution, StringComparison.OrdinalIgnoreCase) &&
string.Equals(User, other.User, StringComparison.OrdinalIgnoreCase) &&
string.Equals(NixProfilePath, other.NixProfilePath, StringComparison.Ordinal);
}
public override int GetHashCode()
{
return HashCode.Combine(
Distribution.ToLowerOrdinal(),
User.ToLowerOrdinal(),
NixProfilePath
);
}
public override string ToString()
{
return $"WSL Distro: {Distribution}, User: {User}, Profile: {NixProfilePath}";
}
}
internal static class StringExtensions
{
public static string ToLowerOrdinal(this string str) => str.ToLowerInvariant();
}
}