diff --git a/flake.lock b/flake.lock index e8408e5..9a7be9d 100644 --- a/flake.lock +++ b/flake.lock @@ -7,43 +7,43 @@ ] }, "locked": { - "lastModified": 1627649712, - "narHash": "sha256-AJBasvMKpsyJmCLdjroBElCHY5AlalbVy+XY5vjbgXc=", + "lastModified": 1639871969, + "narHash": "sha256-6feWUnMygRzA9tzkrfAzpA5/NBYg75bkFxnqb1DtD7E=", "owner": "rycee", "repo": "home-manager", - "rev": "b39647e52ed3c0b989e9d5c965e598ae4c38d7ef", + "rev": "697cc8c68ed6a606296efbbe9614c32537078756", "type": "github" }, "original": { "owner": "rycee", - "ref": "release-21.05", + "ref": "release-21.11", "repo": "home-manager", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1629033443, - "narHash": "sha256-Vo3TvQvR5hsd3incx/xOt6GFgTm651CYVauHS/irOFo=", + "lastModified": 1642190797, + "narHash": "sha256-cxeEEAtfIACnm8sV1oz0xlNp9IVk10Fxcc09ggoEZuo=", "owner": "nixos", "repo": "nixpkgs", - "rev": "8ac785da9843aa110caeed6c912875e46a415a11", + "rev": "3ddd960a3b575bf3230d0e59f42614b71f9e0db9", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixos-21.05", + "ref": "nixos-21.11", "repo": "nixpkgs", "type": "github" } }, "nur": { "locked": { - "lastModified": 1629143403, - "narHash": "sha256-Z57DBF3MUTqTnJyYjqEN+DNZLrVukEJJotcxYPHNR/M=", + "lastModified": 1642392502, + "narHash": "sha256-ZRgwagDhwT5eQgTSqhupXz3ugQmFat0836d5Hh8ZK4Q=", "owner": "nix-community", "repo": "NUR", - "rev": "79a06a9145c61960dd4b5c2eda67e26276976db1", + "rev": "8993a1cfc2d6ed69725788a2ccafbe8cde0510e3", "type": "github" }, "original": { @@ -62,11 +62,11 @@ }, "unstable": { "locked": { - "lastModified": 1629048390, - "narHash": "sha256-do7HuXFSKyj4ulMlRvGigNZCqOaGD9i0M3OLkFQgEAc=", + "lastModified": 1642104392, + "narHash": "sha256-m71b7MgMh9FDv4MnI5sg9MiBVW6DhE1zq+d/KlLWSC8=", "owner": "nixos", "repo": "nixpkgs", - "rev": "e41ba38114055832e5ba4a851e9c00149eef3e4a", + "rev": "5aaed40d22f0d9376330b6fa413223435ad6fee5", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index ead7175..e79abc6 100644 --- a/flake.nix +++ b/flake.nix @@ -2,16 +2,16 @@ description = "Michael Thomas's NixOS configuration"; inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; + unstable.url = "github:nixos/nixpkgs/nixos-unstable"; + nur.url = "github:nix-community/NUR"; + home-manager = { - url = "github:rycee/home-manager/release-21.05"; + url = "github:rycee/home-manager/release-21.11"; inputs = { nixpkgs.follows = "nixpkgs"; }; }; - - nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; - unstable.url = "github:nixos/nixpkgs/nixos-unstable"; - nur.url = "github:nix-community/NUR"; }; outputs = inputs: { @@ -39,6 +39,58 @@ specialArgs = { inherit inputs; }; }; + work = inputs.nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./modules/containers.nix + ./modules/nix.nix + ./modules/vscode-server.nix + + ./machines/work/configuration.nix + ]; + specialArgs = { inherit inputs; }; + }; + + }; + + homeConfigurations = { + nixos = inputs.home-manager.lib.homeManagerConfiguration { + system = "x86_64-linux"; + homeDirectory = "/home/michael"; + username = "michael"; + stateVersion = "21.05"; + configuration = { config, pkgs, ... }: + { + nixpkgs.config = { + allowUnfree = true; + }; + + programs.home-manager.enable = true; + + imports = [ + ./user/environments/nixos/home.nix + ]; + }; + }; + + wsl = inputs.home-manager.lib.homeManagerConfiguration { + system = "x86_64-linux"; + homeDirectory = "/home/michael"; + username = "michael"; + stateVersion = "21.05"; + configuration = { config, pkgs, ... }: + { + nixpkgs.config = { + allowUnfree = true; + }; + + programs.home-manager.enable = true; + + imports = [ + ./user/environments/wsl/home.nix + ]; + }; + }; }; }; } diff --git a/machines/kitchen/configuration.nix b/machines/kitchen/configuration.nix index c27d5f4..0970b27 100644 --- a/machines/kitchen/configuration.nix +++ b/machines/kitchen/configuration.nix @@ -10,25 +10,7 @@ ./hardware-configuration.nix ]; - # Auto cleanup - nix = { - package = pkgs.nixUnstable; - extraOptions = '' - experimental-features = nix-command flakes - ''; - autoOptimiseStore = true; - gc = { - automatic = true; - dates = "weekly"; - options = "--delete-older-than 30d"; - }; - }; - - nixpkgs.config = { - allowUnfree = true; - }; - - networking.hostName = "nixos"; # Define your hostname. + networking.hostName = "kitchen-nixos"; # Define your hostname. # The global useDHCP flag is deprecated, therefore explicitly set to false here. # Per-interface useDHCP will be mandatory in the future, so this generated config diff --git a/machines/loft/configuration.nix b/machines/loft/configuration.nix index 054a204..1dcc820 100644 --- a/machines/loft/configuration.nix +++ b/machines/loft/configuration.nix @@ -10,24 +10,6 @@ ./hardware-configuration.nix ]; - # Auto cleanup - nix = { - package = pkgs.nixUnstable; - extraOptions = '' - experimental-features = nix-command flakes - ''; - autoOptimiseStore = true; - gc = { - automatic = true; - dates = "weekly"; - options = "--delete-older-than 30d"; - }; - }; - - nixpkgs.config = { - allowUnfree = true; - }; - # Set your time zone. time.timeZone = "America/New_York"; diff --git a/machines/work/configuration.nix b/machines/work/configuration.nix new file mode 100644 index 0000000..cadde05 --- /dev/null +++ b/machines/work/configuration.nix @@ -0,0 +1,61 @@ +{ lib, pkgs, config, modulesPath, ... }: + +with lib; +let + defaultUser = "michael"; + 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; + + time.timeZone = "America/New_York"; + + programs.adb.enable = true; + networking.dhcpcd.enable = false; + + # Proxychains + programs.proxychains = { + enable = true; + proxies.main = { + enable = true; + type = "http"; + host = "172.21.32.1"; + port = 1080; + }; + }; + + users.users.${defaultUser} = { + isNormalUser = true; + extraGroups = [ "wheel" "docker" ]; + shell = pkgs.zsh; + }; + + users.users.root = { + shell = "${syschdemd}/bin/syschdemd"; + # Otherwise WSL fails to login as root with "initgroups failed 5" + extraGroups = [ "root" ]; + }; + + 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; +} diff --git a/machines/work/syschdemd.nix b/machines/work/syschdemd.nix new file mode 100644 index 0000000..29b7817 --- /dev/null +++ b/machines/work/syschdemd.nix @@ -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; +} diff --git a/machines/work/syschdemd.sh b/machines/work/syschdemd.sh new file mode 100644 index 0000000..bf94dda --- /dev/null +++ b/machines/work/syschdemd.sh @@ -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@ "$@" diff --git a/modules/common.nix b/modules/common.nix index 0a86359..c4b83ae 100644 --- a/modules/common.nix +++ b/modules/common.nix @@ -7,6 +7,7 @@ ./flatpak.nix ./fonts.nix ./gnome.nix + ./nix.nix ./sound.nix ]; } \ No newline at end of file diff --git a/modules/nix.nix b/modules/nix.nix new file mode 100644 index 0000000..233b2ba --- /dev/null +++ b/modules/nix.nix @@ -0,0 +1,21 @@ +{ pkgs, ... }: +{ + nix = { + extraOptions = '' + experimental-features = flakes nix-command + ''; + # this is required until nix 2.4 is released + package = pkgs.nixUnstable; + + autoOptimiseStore = true; + gc = { + automatic = true; + dates = "weekly"; + options = "--delete-older-than 30d"; + }; + }; + + nixpkgs.config = { + allowUnfree = true; + }; +} diff --git a/modules/vscode-server.nix b/modules/vscode-server.nix new file mode 100644 index 0000000..0ee46c8 --- /dev/null +++ b/modules/vscode-server.nix @@ -0,0 +1,7 @@ +{ + imports = [ + (fetchTarball "https://github.com/msteen/nixos-vscode-server/tarball/master") + ]; + + services.vscode-server.enable = true; +} \ No newline at end of file diff --git a/user/machines/loft/config.nix b/user/environments/mac/config.nix similarity index 100% rename from user/machines/loft/config.nix rename to user/environments/mac/config.nix diff --git a/user/machines/mac/home.nix b/user/environments/mac/home.nix similarity index 100% rename from user/machines/mac/home.nix rename to user/environments/mac/home.nix diff --git a/user/machines/mac/config.nix b/user/environments/nixos/config.nix similarity index 100% rename from user/machines/mac/config.nix rename to user/environments/nixos/config.nix diff --git a/user/machines/loft/home.nix b/user/environments/nixos/home.nix similarity index 80% rename from user/machines/loft/home.nix rename to user/environments/nixos/home.nix index eb460cb..4ccf46c 100644 --- a/user/machines/loft/home.nix +++ b/user/environments/nixos/home.nix @@ -2,7 +2,6 @@ { imports = [ - ../../modules/home-manager.nix ../../modules/dev.nix ../../modules/fonts.nix ../../modules/git.nix @@ -13,9 +12,6 @@ ]; home.packages = with pkgs; [ - neofetch - fortune - google-chrome firefox foxitreader ]; diff --git a/user/machines/wsl/config.nix b/user/environments/wsl/config.nix similarity index 100% rename from user/machines/wsl/config.nix rename to user/environments/wsl/config.nix diff --git a/user/machines/wsl/home.nix b/user/environments/wsl/home.nix similarity index 90% rename from user/machines/wsl/home.nix rename to user/environments/wsl/home.nix index 8b95958..db17ab0 100644 --- a/user/machines/wsl/home.nix +++ b/user/environments/wsl/home.nix @@ -2,7 +2,7 @@ { imports = [ - ../../modules/home-manager.nix + ../../modules/dev.nix ../../modules/git.nix ../../modules/zsh.nix ]; diff --git a/user/machines/kitchen/config.nix b/user/machines/kitchen/config.nix deleted file mode 100644 index 1dd1750..0000000 --- a/user/machines/kitchen/config.nix +++ /dev/null @@ -1,3 +0,0 @@ -{ - allowUnfree = true; -} diff --git a/user/machines/kitchen/home.nix b/user/machines/kitchen/home.nix deleted file mode 100644 index 918fc12..0000000 --- a/user/machines/kitchen/home.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ config, pkgs, ... }: - -{ - imports = [ - ../../modules/home-manager.nix - ../../modules/fonts.nix - ../../modules/git.nix - ../../modules/git_nixos.nix - ../../modules/gnome.nix - ../../modules/dev.nix - ../../modules/vscode.nix - ../../modules/zsh.nix - ]; - - home.packages = with pkgs; [ - neofetch - fortune - ]; - -} \ No newline at end of file diff --git a/user/modules/zsh.nix b/user/modules/zsh.nix index d1ac3e1..98f146d 100644 --- a/user/modules/zsh.nix +++ b/user/modules/zsh.nix @@ -41,6 +41,7 @@ enableZshIntegration = true; settings = { character.success_symbol = "[➜](green)"; + character.error_symbol = "[➜](red)"; }; }; } \ No newline at end of file