feat: fix one attempt

This commit is contained in:
Deepak Mallubhotla 2022-03-29 13:39:44 +00:00
parent 0155646a78
commit a5d148c1d6
8 changed files with 164 additions and 24 deletions

View File

@ -1,28 +1,24 @@
{
description = "Configuration v1";
description = "Configuration v1";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-21.11";
homeManager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-21.11";
homeManager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, homeManager, ...}: {
nixosConfigurations."maxos" = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration.nix
homeManager.nixosModules.home-manager {
home-manager.useGlobalPkgs = true;
home-manager.users.deepak = {
imports = [ ./home.nix ];
};
}
];
};
};
outputs = { self, nixpkgs, homeManager, ...}@inputs: {
nixosConfigurations = (
import ./hosts.nix {
inherit nixpkgs;
inherit homeManager;
inherit (nixpkgs) lib;
}
);
};
}

28
hosts/hosts.nix Normal file
View File

@ -0,0 +1,28 @@
{ lib, inputs, nixpkgs, homeManager, ... }:
{
"maxos" = lib.nixosSystem {
system = "x86_64-linux";
modules = [
./maxos/configuration.nix
homeManager.nixosModules.home-manager {
home-manager.useGlobalPkgs = true;
home-manager.users.deepak = {
imports = [ ../home/deepak/home.nix ];
};
}
];
};
"nixosWSL" = lib.nixosSystem {
system = "x86_64-linux";
modules = [
./nixosWSL/configuration.nix
homeManager.nixosModules.home-manager {
home-manager.useGlobalPkgs = true;
home-manager.users.deepak = {
imports = [ ../home/deepak/home.nix ];
};
}
];
};
}

View File

@ -0,0 +1,75 @@
{ lib, pkgs, config, modulesPath, ... }:
with lib;
let
defaultUser = "nixos";
syschdemd = import ./syschdemd.nix { inherit lib pkgs config defaultUser; };
in
{
imports = [
"${modulesPath}/profiles/minimal.nix"
];
# WSL is closer to a container than anything else
boot.isContainer = true;
environment.etc.hosts.enable = false;
environment.etc."resolv.conf".enable = false;
networking.dhcpcd.enable = false;
users.users.${defaultUser} = {
isNormalUser = true;
extraGroups = [ "wheel" ];
};
networking.hostName = "nixosWSL"; # Define your hostname.
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
# Set your time zone.
time.timeZone = "America/Chicago";
users.users.root = {
shell = "${syschdemd}/bin/syschdemd";
# Otherwise WSL fails to login as root with "initgroups failed 5"
extraGroups = [ "root" ];
};
users.users.deepak = {
isNormalUser = true;
home = "/home/deepak";
description = "Deepak Mallubhotla";
extraGroups = [ "wheel" "networkmanager" ]; # Enable sudo for the user.
};
# List packages installed in system profile. To search, run:
# $ nix search wget
environment.systemPackages = with pkgs; [
wget vim
firefox
git
];
nixpkgs.config.allowUnfree = true;
security.sudo.wheelNeedsPassword = false;
# Disable systemd units that don't make sense on WSL
systemd.services."serial-getty@ttyS0".enable = false;
systemd.services."serial-getty@hvc0".enable = false;
systemd.services."getty@tty1".enable = false;
systemd.services."autovt@".enable = false;
systemd.services.firewall.enable = false;
systemd.services.systemd-resolved.enable = false;
systemd.services.systemd-udevd.enable = false;
# Don't allow emergency mode, because we don't have a console.
systemd.enableEmergencyMode = false;
nix = {
package = pkgs.nixFlakes;
extraOptions = ''experimental-features = nix-command flakes'';
};
}

View File

@ -0,0 +1,15 @@
{ lib, pkgs, config, defaultUser, ... }:
pkgs.substituteAll {
name = "syschdemd";
src = ./syschdemd.sh;
dir = "bin";
isExecutable = true;
buildInputs = with pkgs; [ daemonize ];
inherit (pkgs) daemonize;
inherit defaultUser;
inherit (config.security) wrapperDir;
fsPackagesPath = lib.makeBinPath config.system.fsPackages;
}

View File

@ -0,0 +1,26 @@
#! @shell@
set -e
sw="/nix/var/nix/profiles/system/sw/bin"
systemPath=`${sw}/readlink -f /nix/var/nix/profiles/system`
# Needs root to work
if [[ $EUID -ne 0 ]]; then
echo "[ERROR] Requires root! :( Make sure the WSL default user is set to root"
exit 1
fi
if [ ! -e "/run/current-system" ]; then
/nix/var/nix/profiles/system/activate
fi
if [ ! -e "/run/systemd.pid" ]; then
PATH=/run/current-system/systemd/lib/systemd:@fsPackagesPath@ \
LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive \
@daemonize@/bin/daemonize /run/current-system/sw/bin/unshare -fp --mount-proc systemd
/run/current-system/sw/bin/pgrep -xf systemd > /run/systemd.pid
fi
userShell=$($sw/getent passwd @defaultUser@ | $sw/cut -d: -f7)
exec $sw/nsenter -t $(< /run/systemd.pid) -p -m --wd="$PWD" -- @wrapperDir@/su -s $userShell @defaultUser@ "$@"