diff --git a/default.nix b/default.nix index 3ce80ff..0c9248a 100644 --- a/default.nix +++ b/default.nix @@ -47,5 +47,5 @@ let type != "unknown" && builtins.baseNameOf path != ".git" && !matchesGitIgnore path ) ./.; in -if !(evaluatingInStore) then import selfInStore -else import ./outputs.nix +if !(evaluatingInStore) then { ... }@args: import selfInStore ({ selfPath = selfInStore; } // args ) +else { ... }@args: import ./outputs.nix ({ selfPath = selfInStore; } // args) diff --git a/hosts/main.nix b/hosts/main.nix deleted file mode 100644 index 0fca5f6..0000000 --- a/hosts/main.nix +++ /dev/null @@ -1,52 +0,0 @@ -{ inputs, pkgs, ... }: - -{ - imports = [ - ../nix-os/core.nix - ../nix-os/core-desktop.nix - ../nix-os/nvidia.nix - ../nix-os/docker.nix - ../nix-os/razer.nix - ../nix-os/desktopManagers/gnome.nix - ../nix-os/displayManagers/gdm.nix - #../nix-os/desktop/kde-plasma.nix - ../nix-os/shell.nix - ../nix-os/virtualization.nix - ../nix-os/polkit/disable-shutdown.nix - ../nix-os/locale.nix - ../nix-os/adb.nix - ../nix-os/account.nix - ../nix-os/xdg-default-apps.nix - ../nix-os/services/nix-binary-cache.nix - ../nix-os/udev.nix - - "${inputs.nixos-vscode-server}" - ]; - - config = { - boot.loader.systemd-boot.enable = true; - boot.loader.efi.canTouchEfiVariables = true; - - networking.hostName = "wroclaw-main"; - - services.xrdp.enable = true; - users.groups."tsusers".members = [ "wroclaw" ]; - - services.printing.drivers = with pkgs; [ - hplip - ]; - - # nixos-vscode-server module needs this - programs.nix-ld.enable = true; - services.vscode-server = { - enable = true; - extraRuntimeDependencies = with pkgs; [ - docker - ]; - }; - - services.printing.startWhenNeeded = false; - - system.stateVersion = "23.05"; - }; -} diff --git a/hosts/main/default.nix b/hosts/main/default.nix new file mode 100644 index 0000000..d35b5bc --- /dev/null +++ b/hosts/main/default.nix @@ -0,0 +1,64 @@ +{ inputs, pkgs, ... }: + +{ + imports = [ + ../../nix-os/core.nix + ../../nix-os/core-desktop.nix + ../../nix-os/nvidia.nix + ../../nix-os/docker.nix + ../../nix-os/razer.nix + ../../nix-os/desktopManagers/gnome.nix + ../../nix-os/displayManagers/gdm.nix + ../../nix-os/shell.nix + ../../nix-os/virtualization.nix + ../../nix-os/polkit/disable-shutdown.nix + ../../nix-os/locale.nix + ../../nix-os/adb.nix + ../../nix-os/account.nix + ../../nix-os/xdg-default-apps.nix + ../../nix-os/services/nix-binary-cache.nix + ../../nix-os/udev.nix + ../../nix-os/gnupg.nix + + "${inputs.nixos-vscode-server}" + ]; + + config = { + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + networking.hostName = "wroclaw-main"; + + services.xrdp.enable = true; + users.groups."tsusers".members = [ "wroclaw" ]; + + services.printing.drivers = with pkgs; [ + hplip + ]; + + # nixos-vscode-server module needs this + programs.nix-ld.enable = true; + services.vscode-server = { + enable = true; + extraRuntimeDependencies = with pkgs; [ + docker + ]; + }; + + services.pipewire.wireplumber.configPackages = [( + pkgs.stdenvNoCC.mkDerivation { + name = "wireplumber-config"; + src = ./wireplumber; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out/share/wireplumber/wireplumber.conf.d + cp -r $src/* $out/share/wireplumber/wireplumber.conf.d + ''; + } + )]; + + services.printing.startWhenNeeded = false; + + system.stateVersion = "23.05"; + }; +} diff --git a/hosts/main/wireplumber/51-digital-output.conf b/hosts/main/wireplumber/51-digital-output.conf new file mode 100644 index 0000000..57bdff3 --- /dev/null +++ b/hosts/main/wireplumber/51-digital-output.conf @@ -0,0 +1,10 @@ +monitor.alsa.rules = [{ + matches = [{ + node.name = "alsa_output.pci-0000_00_1f.3.iec958-stereo" + }] + actions = { + update-props = { + node.description = "Digital Output" + } + } +}] diff --git a/hosts/main/wireplumber/51-hdmi-otuput.conf b/hosts/main/wireplumber/51-hdmi-otuput.conf new file mode 100644 index 0000000..265b78a --- /dev/null +++ b/hosts/main/wireplumber/51-hdmi-otuput.conf @@ -0,0 +1,10 @@ +monitor.alsa.rules = [{ + matches = [{ + node.name = "alsa_output.pci-0000_01_00.1.hdmi-stereo" + }] + actions = { + update-props = { + node.description = "Monitor speakers" + } + } +}] diff --git a/hosts/main/wireplumber/51-razerHeadphones-device.conf b/hosts/main/wireplumber/51-razerHeadphones-device.conf new file mode 100644 index 0000000..b159a49 --- /dev/null +++ b/hosts/main/wireplumber/51-razerHeadphones-device.conf @@ -0,0 +1,11 @@ +monitor.alsa.rules = [{ + matches = [{ + device.name = "alsa_card.usb-Razer_Razer_USB_Audio_Controller_000000000000000000000000-00" + }] + actions = { + update-props = { + device.description = "Headphones" + device.profile = "Pro Audio" + } + } +}] diff --git a/hosts/main/wireplumber/51-razerHeadphones-input.conf b/hosts/main/wireplumber/51-razerHeadphones-input.conf new file mode 100644 index 0000000..c24a599 --- /dev/null +++ b/hosts/main/wireplumber/51-razerHeadphones-input.conf @@ -0,0 +1,10 @@ +monitor.alsa.rules = [{ + matches = [{ + node.name = "alsa_input.usb-Razer_Razer_USB_Audio_Controller_000000000000000000000000-00.pro-input-0" + }] + actions = { + update-props = { + node.description = "Headphones" + } + } +}] diff --git a/hosts/main/wireplumber/51-razerHeadphones-output.conf b/hosts/main/wireplumber/51-razerHeadphones-output.conf new file mode 100644 index 0000000..11cb43e --- /dev/null +++ b/hosts/main/wireplumber/51-razerHeadphones-output.conf @@ -0,0 +1,22 @@ +monitor.alsa.rules = [ + { + matches = [{ + node.name = "alsa_output.usb-Razer_Razer_USB_Audio_Controller_000000000000000000000000-00.pro-output-0" + }] + actions = { + update-props = { + node.description = "Headphones (Chat)" + } + } + } + { + matches = [{ + node.name = "alsa_output.usb-Razer_Razer_USB_Audio_Controller_000000000000000000000000-00.pro-output-1" + }] + actions = { + update-props = { + node.description = "Headphones (Game)" + } + } + } +] diff --git a/hosts/tablet.nix b/hosts/tablet.nix index 7c449bf..ad06d9b 100644 --- a/hosts/tablet.nix +++ b/hosts/tablet.nix @@ -8,6 +8,7 @@ ../nix-os/adb.nix ../nix-os/locale.nix ../nix-os/shell.nix + ../nix-os/gnupg.nix ../nix-os/desktopManagers/gnome.nix ../nix-os/displayManagers/gdm.nix diff --git a/lock.nix b/lock.nix index 09cca69..2963614 100644 --- a/lock.nix +++ b/lock.nix @@ -4,7 +4,7 @@ sha256 = "1rq8mrlmbzpcbv9ys0x88alw30ks70jlmvnfr2j8v830yy5wvw7h"; }; nixpkgs = { - revision = "10c832d0548e9e3a6df7eb51e68c2783212a303e"; - sha256 = "1p206hgfxbz0rmkzaslfrknbdss4n4dnb09pi5466h8ksmm8216q"; + revision = "05405724efa137a0b899cce5ab4dde463b4fd30b"; + sha256 = "06490pn22x9xl4chfx12iwdgx7nlbn14v8x05rnv2y1nancljisl"; }; } diff --git a/nix-os/account.nix b/nix-os/account.nix index 9affded..b1693ad 100644 --- a/nix-os/account.nix +++ b/nix-os/account.nix @@ -21,7 +21,7 @@ proprietaryCodecs = true; commandLineArgs = [ "--ozone-platform=wayland" ]; }) - discord-canary + vesktop unstablePkgs.vscode gimp inkscape diff --git a/nix-os/core.nix b/nix-os/core.nix index cfb55e4..53eaab8 100644 --- a/nix-os/core.nix +++ b/nix-os/core.nix @@ -5,23 +5,7 @@ { inputs, lib, pkgs, ... }: let - /* - * pkg: package - nixpkgs package - * exe: string - executable (under bin) in pkgs - * wrapperArgs: string[] - arguments to pass to the wrapper - */ - mkWrappedExecutable = {pkg, exe ? pkg.meta.mainProgram, wrapperArgs}: let inherit (pkgs) lib makeWrapper; in lib.hiPrio ( - pkgs.stdenv.mkDerivation { - inherit wrapperArgs; - name = "${pkg.name}-wrap-${exe}"; - nativeBuildInputs = [ makeWrapper ]; - phases = ["installPhase"]; - installPhase = '' - mkdir -p $out/bin - makeWrapper ${pkg}/bin/${exe} $out/bin/${exe} $wrapperArgs - ''; - } - ); + inherit (pkgs) mkWrappedExecutable; # bool -> nixpkgs[] wrappedNixExecutables = inEnvironment: assert builtins.isBool inEnvironment; [ @@ -79,6 +63,21 @@ in rerere.enabled = true; }; + # Use nix-index for command-not-found handler + programs.command-not-found.enable = false; + programs.nix-index = { + package = pkgs.nix-index.override { + nix-index-unwrapped = pkgs.nix-index-unwrapped.overrideAttrs (oldAttrs: { + patches = oldAttrs.patches or [] ++ [ + ../pkgs/by-name/ni/nix-index/cnfOutput.patch + ]; + }); + + }; + enable = true; + enableBashIntegration = true; + }; + # Enable fail2ban because of the OpenSSH server services.fail2ban = { enable = true; diff --git a/nix-os/gnupg.nix b/nix-os/gnupg.nix new file mode 100644 index 0000000..1c9b20e --- /dev/null +++ b/nix-os/gnupg.nix @@ -0,0 +1,15 @@ +{ pkgs, ... }: + +{ + config = { + # Use pcscd for smartcard support + services.pcscd.enable = true; + + environment.systemPackages = [( + pkgs.gnupg.overrideAttrs (superAttrs: { + configureFlags = superAttrs.configureFlags or [] + ++ [ "--disable-ccid-driver" ]; + }) + )]; + }; +} diff --git a/nix-os/nvidia.nix b/nix-os/nvidia.nix index 2113d0a..c166ac5 100644 --- a/nix-os/nvidia.nix +++ b/nix-os/nvidia.nix @@ -13,10 +13,12 @@ open = false; nvidiaSettings = true; package = config.boot.kernelPackages.nvidiaPackages.mkDriver { - version = "555.42.02"; - sha256_64bit = "sha256-k7cI3ZDlKp4mT46jMkLaIrc2YUx1lh1wj/J4SVSHWyk="; - settingsSha256 = "sha256-rtDxQjClJ+gyrCLvdZlT56YyHQ4sbaL+d5tL4L4VfkA="; - persistencedSha256 = ""; + version = "555.58.02"; + sha256_64bit = "sha256-xctt4TPRlOJ6r5S54h5W6PT6/3Zy2R4ASNFPu8TSHKM="; + sha256_aarch64 = "sha256-wb20isMrRg8PeQBU96lWJzBMkjfySAUaqt4EgZnhyF8="; + openSha256 = "sha256-8hyRiGB+m2hL3c9MDA/Pon+Xl6E788MZ50WrrAGUVuY="; + settingsSha256 = "sha256-ZpuVZybW6CFN/gz9rx+UJvQ715FZnAOYfHn5jt5Z2C8="; + persistencedSha256 = "sha256-a1D7ZZmcKFWfPjjH1REqPM5j/YLWKnbkP9qfRyIyxAw="; }; }; nixpkgs.config.nvidia.acceptLicense = true; diff --git a/outputs.nix b/outputs.nix index ad24442..f69f3bf 100644 --- a/outputs.nix +++ b/outputs.nix @@ -1,11 +1,15 @@ -{ inputs ? import ./inputs.nix {} }: +{ + inputs ? import ./inputs.nix {}, + selfPath ? ./. +}: let lib = (import "${inputs.nixpkgs}/lib").extend (import ./lib/overlays/version-info-fixup.nix { inherit inputs; }); self = { - inherit lib inputs; + inherit inputs lib self; + __toString = _: selfPath; modifiedNixpkgs = import ./pkgs/top-level/impure.nix; modifiedNixpkgsPure = import ./pkgs/top-level/default.nix; overlays = { @@ -18,30 +22,30 @@ self = { filePaths = lib.pipe ./hosts [ builtins.readDir ( lib.filterAttrs (name: type: - # filter out non-nix files - type == "regular" - # filter out files that don't end in .nix - && lib.hasSuffix ".nix" name + ( # regular .nix files + (type == "regular" && lib.hasSuffix ".nix" name) + || # directories that contain a default.nix file + (type == "directory" && builtins.pathExists "${./hosts}/${name}/default.nix") + ) # filter out files that start with . && !lib.hasPrefix "." name )) - (lib.mapAttrsToList (name: _: name)) ]; nixosSystem = import "${inputs.nixpkgs}/nixos/lib/eval-config.nix"; in # mapped list of nix file paths to attrSet with initialized NixOS configurations, # whose names are derived from file names lib.pipe filePaths [ - (builtins.map (name: { - name = builtins.substring 0 (builtins.stringLength name - 4) name; + (builtins.mapAttrs (name: type: { + name = if type == "directory" then name else builtins.substring 0 (builtins.stringLength name - 4) name; value = nixosSystem { inherit lib; modules = [ ./hosts/${name} { config.nixpkgs.overlays = [ - ( import ./pkgs/overlays/selfExpr.nix { nixpkgsPath = "${builtins.toString ./.}/pkgs/top-level/impure.nix"; } ) - ( import "${inputs.nixpkgs}/pkgs/top-level/by-name-overlay.nix" "${builtins.toString ./.}/pkgs/by-name" ) + ( import ./pkgs/overlays/selfExpr.nix { nixpkgsPath = "${self}/pkgs/top-level/impure.nix"; } ) + ( import ./pkgs/top-level/by-name-overlay.nix "${self}/pkgs/by-name" ) self.overlays.versionInfoFixup ]; } @@ -49,6 +53,7 @@ self = { specialArgs = { inherit self inputs; }; }; })) + builtins.attrValues builtins.listToAttrs ]; }; diff --git a/pkgs/by-name/mk/mkScriptOverride/package.nix b/pkgs/by-name/mk/mkScriptOverride/package.nix new file mode 100644 index 0000000..6777a0c --- /dev/null +++ b/pkgs/by-name/mk/mkScriptOverride/package.nix @@ -0,0 +1,29 @@ +{ + lib, + stdenv, +}: + +{ + src, + script, + ... +} @ args: +lib.hiPrio (stdenv.mkDerivation ( + { + src = src; + name = "${src.name}-script-override"; + phases = [ "installPhase" "scriptOverridePhase" ]; + installPhase = '' + runHook preInstall + + cp -r $src $out + chmod u+w -R $out + + runHook postInstall + ''; + scriptOverridePhase = script; + } // lib.removeAttrs args [ + "pkg" + "commands" + ] +)) diff --git a/pkgs/by-name/mk/mkWrappedExecutable/package.nix b/pkgs/by-name/mk/mkWrappedExecutable/package.nix new file mode 100644 index 0000000..039b6f4 --- /dev/null +++ b/pkgs/by-name/mk/mkWrappedExecutable/package.nix @@ -0,0 +1,22 @@ +{ + lib, + makeWrapper, + stdenv +}: + +/* + pkg: package - nixpkgs package + exe: string - executable (under bin) in pkg + wrapperArgs: string[] - arguments to pass to the wrapper +*/ +{ pkg, exe ? pkg.meta.mainProgram, wrapperArgs }: +lib.hiPrio (stdenv.mkDerivation { + inherit wrapperArgs; + name = "${pkg.name}-wrap-${exe}"; + nativeBuildInputs = [ makeWrapper ]; + phases = ["installPhase"]; + installPhase = '' + mkdir -p $out/bin + makeWrapper ${pkg}/bin/${exe} $out/bin/${exe} $wrapperArgs + ''; +}) diff --git a/pkgs/by-name/ni/nix-index/cnfOutput.patch b/pkgs/by-name/ni/nix-index/cnfOutput.patch new file mode 100644 index 0000000..8564d9b --- /dev/null +++ b/pkgs/by-name/ni/nix-index/cnfOutput.patch @@ -0,0 +1,66 @@ +diff --git a/command-not-found.sh b/command-not-found.sh +index 5f30bad..3854297 100755 +--- a/command-not-found.sh ++++ b/command-not-found.sh +@@ -73,51 +73,30 @@ EOF + else + if [ -e "$HOME/.nix-profile/manifest.json" ]; then + >&2 cat <&2 cat <&2 cat <&2 echo " nix profile install $toplevel#$attr" +- else +- >&2 echo " nix-env -iA $toplevel.$attr" +- fi +- done <<< "$attrs" +- +- >&2 cat <&2 echo " nix shell $toplevel#$attr -c $cmd ..." ++ >&2 echo " nix shell $toplevel#$attr" + else +- >&2 echo " nix-shell -p $attr --run '$cmd ...'" ++ >&2 echo " nix-shell -p $attr" + fi + done <<< "$attrs" + ;; diff --git a/pkgs/overlays/selfExpr.nix b/pkgs/overlays/selfExpr.nix index ae28729..4dd0312 100644 --- a/pkgs/overlays/selfExpr.nix +++ b/pkgs/overlays/selfExpr.nix @@ -25,11 +25,13 @@ self: super: { in '' { ... } @ args: - import ${nixpkgsPath} { - ${self.lib.optionalString useConfig configText} - } // builtins.removeAttrs args (builtins.fromJSON ''' - ${removedAttrNamesText} - ''') + import ${nixpkgsPath} ( + { + ${self.lib.optionalString useConfig configText} + } // builtins.removeAttrs args (builtins.fromJSON ''' + ${removedAttrNamesText} + ''') + ) ''; mkNixpkgsChannel = args: self.writeTextFile { diff --git a/pkgs/top-level/by-name-overlay.nix b/pkgs/top-level/by-name-overlay.nix new file mode 100644 index 0000000..ed63216 --- /dev/null +++ b/pkgs/top-level/by-name-overlay.nix @@ -0,0 +1,50 @@ +# Modified copy of github:NixOS/nixpkgs pkgs/top-level/by-name-overlay.nix +# as of commit c0d0be00d4ecc4b51d2d6948e37466194c1e6c51 + +# This file turns the pkgs/by-name directory into an overlay that adds all the defined packages. +# No validity checks are done here. + +# Type: Path -> Overlay +baseDirectory: +let + lib = (import ../../outputs.nix {}).lib; + + inherit (builtins) + readDir + ; + + inherit (lib.attrsets) + mapAttrs + mapAttrsToList + mergeAttrsList + ; + + # Package files for a single shard + # Type: String -> String -> String -> AttrsOf Path + namesForShard = nixFilename: shard: type: + if type != "directory" then + # Ignore all non-directories. + { } + else + mapAttrs + (name: _: baseDirectory + "/${shard}/${name}/${nixFilename}") + (readDir (baseDirectory + "/${shard}")); + + # The attribute set mapping names to the package files defining them + # Type: String -> AttrsOf Path + packageFiles = nixFilename: lib.pipe baseDirectory [ + readDir + (mapAttrsToList (namesForShard nixFilename)) + mergeAttrsList + # Filter out paths that don't have a ${nixFilename} file + (lib.filterAttrs (_: lib.pathExists)) + ]; +in +self: super: +mapAttrs (name: file: + self.callPackage file { inherit self super; package = super.${name}; } +) (packageFiles "override.nix") +// mapAttrs (name: file: + self.callPackage file { } +) (packageFiles "package.nix") + diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix index 5bfdc46..fd3e12a 100644 --- a/pkgs/top-level/default.nix +++ b/pkgs/top-level/default.nix @@ -12,10 +12,11 @@ let options = (builtins.removeAttrs args attrsToRemove) // { overlays = (args.overlays or []) ++ [ - ( import ../overlays/selfExpr.nix { nixpkgsPath = ./impure.nix; } ) + # ../.. should be nix store path that represents self in outputs.nix that is gc-rooted by this point + ( import ../overlays/selfExpr.nix { nixpkgsPath = "${builtins.toString ../..}/pkgs/top-level/impure.nix"; } ) ( import ../overlays/unstable.nix ) ( import ../overlays/version-info-fixup.nix { inherit inputs; } ) - ( import "${inputs.nixpkgs}/pkgs/top-level/by-name-overlay.nix" ../by-name ) + ( import ./by-name-overlay.nix ../by-name ) ]; }; in