diff --git a/README.md b/README.md index 7b1a87a..39161e6 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,9 @@ # My Nix config To install, simply run `nixos-rebuild switch --flake .` and -`home-manager switch --flake .`. - -The reason I don't use the NixOS home-manager module is is because I -want to be able to iterate home config quickly, and `nixos-rebuild`'ing -the entire system for every little change is pretty annoying (not to -mention the necessity of `sudo`). I'll probably merge them later, -especially after [Tvix](https://tvl.fyi/blog/rewriting-nix) becomes -feature-complete. +`home-manager switch --flake .`... just kidding, this config relies on a +bunch of secrets that I'm too lazy to make defaults for (such as initial +root password for impermanence), so you won't be able to run it as-is. +Home-manager config and modules are in `./home`, NixOS config and +modules are in `./system`. diff --git a/flake.lock b/flake.lock index 5e7f710..17c56ce 100644 --- a/flake.lock +++ b/flake.lock @@ -152,11 +152,11 @@ "utils": "utils" }, "locked": { - "lastModified": 1684962389, - "narHash": "sha256-pGAbDgIusNLVUFF5BcfI8ZPQGuQvMmlINOJUztHZrsg=", + "lastModified": 1684964237, + "narHash": "sha256-dDS+GhdZN2MAa2FJKFGM2gpgAXhx+xoMkpVsRx9qpDE=", "owner": "simple-nixos-mailserver", "repo": "nixos-mailserver", - "rev": "fd605a419bcad2513844ccee0fc6f7760cdd657e", + "rev": "1bcfcf786bc289ca1bd2c9d29d6f02d9141b1da3", "type": "gitlab" }, "original": { diff --git a/flake.nix b/flake.nix index 4843d74..1556174 100644 --- a/flake.nix +++ b/flake.nix @@ -36,56 +36,35 @@ if builtins.pathExists ./private.nix then (import ./private.nix) else if builtins.pathExists ./private/default.nix then (import ./private) else { }; + # if x has key s, get it. Otherwise return def getOr = def: s: x: with builtins; if hasAttr s x then getAttr s x else def; + # All private config for hostname getPriv = hostname: getOr { } hostname priv; + # Private NixOS config for hostname getPrivSys = hostname: getOr { } "system" (getPriv hostname); + # Private home-manager config for hostname and username getPrivUser = hostname: user: getOr { } user (getPriv hostname); + # extended lib lib = nixpkgs.lib // { quoteListenAddr = addr: if nixpkgs.lib.hasInfix ":" addr then "[${addr}]" else addr; }; - config = { - nixmsi = rec { - system = "x86_64-linux"; - modules = [ - nix-gaming.nixosModules.pipewireLowLatency - ./system/hardware/msi_delta_15.nix - ./system/hosts/nixmsi.nix - ]; - home.user = { - pkgs = import nixpkgs { - inherit system; - binaryCachePublicKeys = [ - "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" - # "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA=" - ]; - binaryCaches = [ - "https://cache.nixos.org" - # "https://nixpkgs-wayland.cachix.org" - ]; - overlays = [ - (self: super: import ./home/pkgs { - # can't use callPackage here, idk why - pkgs = super; - lib = super.lib; - nur = import nur { - pkgs = super; - nurpkgs = super; - }; - nix-gaming = nix-gaming.packages.${system}; - }) - ]; - }; - extraSpecialArgs = { - notlua = notlua.lib.${system}; - # pkgs-wayland = nixpkgs-wayland.packages.${system}; - }; - modules = [ - nur.nixosModules.nur - ./home/hosts/nixmsi.nix - ]; - }; + # can't use callPackage here, idk why; use import instead + overlay = self: super: import ./pkgs { + pkgs = super; + lib = super.lib; + nur = import nur { + pkgs = super; + nurpkgs = super; }; + nix-gaming = nix-gaming.packages.${super.system}; + }; + # I override some settings down the line, but overlays always stay the same + mkPkgs = config: import nixpkgs (config // { + overlays = (if config?overlays then config.overlays else [ ]) ++ [ overlay ]; + }); + # this is actual config, it gets processed later + config = { nixserver = { modules = [ nixos-mailserver.nixosModules.default @@ -100,11 +79,55 @@ ./system/hosts/router ]; }; + nixmsi = rec { + system = "x86_64-linux"; + nixpkgs.config.allowUnfreePredicate = pkg: (lib.getName pkg) == "steam-original"; + modules = [ + nix-gaming.nixosModules.pipewireLowLatency + ./system/hardware/msi_delta_15.nix + ./system/hosts/nixmsi.nix + ]; + home.common.pkgs = mkPkgs { + inherit system; + config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ + "steam-run" + "steam" + "steam-original" + "steam-runtime" + "steamcmd" + "osu-lazer-bin" + ]; + binaryCachePublicKeys = [ + "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" + # "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA=" + ]; + binaryCaches = [ + "https://cache.nixos.org" + # "https://nixpkgs-wayland.cachix.org" + ]; + }; + home.common.extraSpecialArgs = { + notlua = notlua.lib.${system}; + }; + home.user = [ + nur.nixosModules.nur + ./home/hosts/nixmsi.nix + ]; + }; }; in { - nixosConfigurations = builtins.mapAttrs (hostname: args @ { system ? "x86_64-linux", modules, ... }: + overlays.default = overlay; + packages = lib.genAttrs [ + "x86_64-linux" + "aarch64-linux" + ] (system: let self = overlay self (import nixpkgs { inherit system; }); in self ); + # this is the system config part + nixosConfigurations = builtins.mapAttrs (hostname: args @ { system ? "x86_64-linux", modules, nixpkgs ? {}, home ? {}, ... }: lib.nixosSystem ({ inherit system; + pkgs = mkPkgs ({ + inherit system; + } // nixpkgs); modules = modules ++ [ { networking.hostName = hostname; } ./system/modules/vfio.nix @@ -128,27 +151,48 @@ (lib.filterAttrs (_: v: builtins.pathExists "${v}/default.nix") inputs); nix.nixPath = [ "/etc/nix/inputs" ]; } - ]; + ] ++ (lib.optionals (home != {} && (!(home?common) || !(home.common?pkgs))) [ + # only use NixOS HM module if same nixpkgs as system nixpkgs is used for user + # why? because it seems that HM lacks the option to override pkgs, only change nixpkgs.* settings + home-manager.nixosModules.home-manager + { + home-manager = builtins.removeAttrs (getOr { } "common" home) [ "nixpkgs" ]; + } + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users = builtins.mapAttrs (k: v: { + imports = v ++ [ { + nixpkgs = getOr { } "nixpkgs" (getOr { } "common" home); + } ]; + }) (builtins.removeAttrs home [ "common" ]); + } + ]); specialArgs = { inherit lib nixpkgs; hardware = nixos-hardware.nixosModules; }; - } // (builtins.removeAttrs args [ "home" "modules" ]))) + } // (builtins.removeAttrs args [ "home" "modules" "nixpkgs" ]))) config; + # for each hostname, for each user, generate an attribute "${user}@${hostname}" homeConfigurations = builtins.foldl' (a: b: a // b) { } (builtins.concatLists (lib.mapAttrsToList - (hostname: config: + (hostname: sysConfig: + let common = builtins.removeAttrs (getOr { } "common" sysConfig.home) [ "nixpkgs" ]; in lib.mapAttrsToList - (user: config@{ modules, ... }: { - "${user}@${hostname}" = home-manager.lib.homeManagerConfiguration (config // { - modules = config.modules ++ [ (getPrivUser hostname user) ]; + # this is where actual config takes place + (user: homeConfig: { + "${user}@${hostname}" = home-manager.lib.homeManagerConfiguration (common // { + modules = homeConfig ++ [ + (getPrivUser hostname user) + ]; }); }) - (getOr { } "home" config)) + (builtins.removeAttrs (getOr { } "home" sysConfig) [ "common" ])) config)); }; } diff --git a/home/hosts/nixmsi.nix b/home/hosts/nixmsi.nix index b4f5e16..fbd7519 100644 --- a/home/hosts/nixmsi.nix +++ b/home/hosts/nixmsi.nix @@ -29,14 +29,6 @@ enable = true; }; services.kdeconnect.enable = true; - nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ - "steam-run" - "steam" - "steam-original" - "steam-runtime" - "steamcmd" - "osu-lazer-bin" - ]; home.sessionVariables = { STEAM_EXTRA_COMPAT_TOOLS_PATHS = "${pkgs.proton-ge}"; CARGO_PROFILE_DEV_INCREMENTAL = "true"; diff --git a/system/pkgs/Cargo.lock b/pkgs/Cargo.lock similarity index 100% rename from system/pkgs/Cargo.lock rename to pkgs/Cargo.lock diff --git a/home/_sources/generated.json b/pkgs/_sources/generated.json similarity index 100% rename from home/_sources/generated.json rename to pkgs/_sources/generated.json diff --git a/home/_sources/generated.nix b/pkgs/_sources/generated.nix similarity index 100% rename from home/_sources/generated.nix rename to pkgs/_sources/generated.nix diff --git a/home/pkgs/default.nix b/pkgs/default.nix similarity index 85% rename from home/pkgs/default.nix rename to pkgs/default.nix index 7ce1e2d..f762543 100644 --- a/home/pkgs/default.nix +++ b/pkgs/default.nix @@ -5,7 +5,7 @@ , ... }: let inherit (pkgs) callPackage; - sources = import ../_sources/generated.nix { + sources = import ./_sources/generated.nix { inherit (pkgs) fetchgit fetchurl fetchFromGitHub dockerTools; }; in @@ -30,6 +30,8 @@ in fetchSubmodules = true; }; }); + maubot = callPackage ./maubot.nix { }; + pineapplebot = callPackage ./pineapplebot.nix { }; proton-ge = pkgs.stdenvNoCC.mkDerivation { inherit (sources.proton-ge) pname version src; installPhase = '' @@ -38,6 +40,7 @@ in ''; }; rofi-steam-game-list = callPackage ./rofi-steam-game-list { }; + system76-scheduler = callPackage ./system76-scheduler.nix { }; techmino = callPackage ./techmino { }; firefox-addons = lib.recurseIntoAttrs (callPackage ./firefox-addons { inherit nur sources; }); diff --git a/home/pkgs/firefox-addons/addons.json b/pkgs/firefox-addons/addons.json similarity index 100% rename from home/pkgs/firefox-addons/addons.json rename to pkgs/firefox-addons/addons.json diff --git a/home/pkgs/firefox-addons/default.nix b/pkgs/firefox-addons/default.nix similarity index 100% rename from home/pkgs/firefox-addons/default.nix rename to pkgs/firefox-addons/default.nix diff --git a/home/pkgs/firefox-addons/generated.nix b/pkgs/firefox-addons/generated.nix similarity index 100% rename from home/pkgs/firefox-addons/generated.nix rename to pkgs/firefox-addons/generated.nix diff --git a/home/pkgs/ghidra-stdcall.patch b/pkgs/ghidra-stdcall.patch similarity index 100% rename from home/pkgs/ghidra-stdcall.patch rename to pkgs/ghidra-stdcall.patch diff --git a/home/pkgs/home-daemon/.gitignore b/pkgs/home-daemon/.gitignore similarity index 100% rename from home/pkgs/home-daemon/.gitignore rename to pkgs/home-daemon/.gitignore diff --git a/home/pkgs/home-daemon/Cargo.lock b/pkgs/home-daemon/Cargo.lock similarity index 100% rename from home/pkgs/home-daemon/Cargo.lock rename to pkgs/home-daemon/Cargo.lock diff --git a/home/pkgs/home-daemon/Cargo.toml b/pkgs/home-daemon/Cargo.toml similarity index 100% rename from home/pkgs/home-daemon/Cargo.toml rename to pkgs/home-daemon/Cargo.toml diff --git a/home/pkgs/home-daemon/default.nix b/pkgs/home-daemon/default.nix similarity index 100% rename from home/pkgs/home-daemon/default.nix rename to pkgs/home-daemon/default.nix diff --git a/home/pkgs/home-daemon/shell.nix b/pkgs/home-daemon/shell.nix similarity index 100% rename from home/pkgs/home-daemon/shell.nix rename to pkgs/home-daemon/shell.nix diff --git a/home/pkgs/home-daemon/src/main.rs b/pkgs/home-daemon/src/main.rs similarity index 100% rename from home/pkgs/home-daemon/src/main.rs rename to pkgs/home-daemon/src/main.rs diff --git a/home/pkgs/lalrpop/default.nix b/pkgs/lalrpop/default.nix similarity index 100% rename from home/pkgs/lalrpop/default.nix rename to pkgs/lalrpop/default.nix diff --git a/home/pkgs/lalrpop/use-correct-binary-path-in-tests.patch b/pkgs/lalrpop/use-correct-binary-path-in-tests.patch similarity index 100% rename from home/pkgs/lalrpop/use-correct-binary-path-in-tests.patch rename to pkgs/lalrpop/use-correct-binary-path-in-tests.patch diff --git a/system/pkgs/maubot.nix b/pkgs/maubot.nix similarity index 100% rename from system/pkgs/maubot.nix rename to pkgs/maubot.nix diff --git a/home/pkgs/mpv-scripts/default.nix b/pkgs/mpv-scripts/default.nix similarity index 100% rename from home/pkgs/mpv-scripts/default.nix rename to pkgs/mpv-scripts/default.nix diff --git a/home/pkgs/mpv-scripts/subserv/custom.patch b/pkgs/mpv-scripts/subserv/custom.patch similarity index 100% rename from home/pkgs/mpv-scripts/subserv/custom.patch rename to pkgs/mpv-scripts/subserv/custom.patch diff --git a/home/pkgs/mpv-scripts/subserv/default.nix b/pkgs/mpv-scripts/subserv/default.nix similarity index 100% rename from home/pkgs/mpv-scripts/subserv/default.nix rename to pkgs/mpv-scripts/subserv/default.nix diff --git a/home/pkgs/mpv-scripts/subserv/settings.patch b/pkgs/mpv-scripts/subserv/settings.patch similarity index 100% rename from home/pkgs/mpv-scripts/subserv/settings.patch rename to pkgs/mpv-scripts/subserv/settings.patch diff --git a/home/nvfetcher.toml b/pkgs/nvfetcher.toml similarity index 100% rename from home/nvfetcher.toml rename to pkgs/nvfetcher.toml diff --git a/system/pkgs/pineapplebot.nix b/pkgs/pineapplebot.nix similarity index 100% rename from system/pkgs/pineapplebot.nix rename to pkgs/pineapplebot.nix diff --git a/home/pkgs/rofi-steam-game-list/.gitignore b/pkgs/rofi-steam-game-list/.gitignore similarity index 100% rename from home/pkgs/rofi-steam-game-list/.gitignore rename to pkgs/rofi-steam-game-list/.gitignore diff --git a/home/pkgs/rofi-steam-game-list/Cargo.lock b/pkgs/rofi-steam-game-list/Cargo.lock similarity index 100% rename from home/pkgs/rofi-steam-game-list/Cargo.lock rename to pkgs/rofi-steam-game-list/Cargo.lock diff --git a/home/pkgs/rofi-steam-game-list/Cargo.toml b/pkgs/rofi-steam-game-list/Cargo.toml similarity index 100% rename from home/pkgs/rofi-steam-game-list/Cargo.toml rename to pkgs/rofi-steam-game-list/Cargo.toml diff --git a/home/pkgs/rofi-steam-game-list/default.nix b/pkgs/rofi-steam-game-list/default.nix similarity index 100% rename from home/pkgs/rofi-steam-game-list/default.nix rename to pkgs/rofi-steam-game-list/default.nix diff --git a/home/pkgs/rofi-steam-game-list/hardcode_xdg_open.patch b/pkgs/rofi-steam-game-list/hardcode_xdg_open.patch similarity index 100% rename from home/pkgs/rofi-steam-game-list/hardcode_xdg_open.patch rename to pkgs/rofi-steam-game-list/hardcode_xdg_open.patch diff --git a/home/pkgs/rofi-steam-game-list/src/main.rs b/pkgs/rofi-steam-game-list/src/main.rs similarity index 100% rename from home/pkgs/rofi-steam-game-list/src/main.rs rename to pkgs/rofi-steam-game-list/src/main.rs diff --git a/system/pkgs/system76-scheduler.nix b/pkgs/system76-scheduler.nix similarity index 100% rename from system/pkgs/system76-scheduler.nix rename to pkgs/system76-scheduler.nix diff --git a/home/pkgs/techmino/Cargo.lock b/pkgs/techmino/Cargo.lock similarity index 100% rename from home/pkgs/techmino/Cargo.lock rename to pkgs/techmino/Cargo.lock diff --git a/home/pkgs/techmino/ccloader.nix b/pkgs/techmino/ccloader.nix similarity index 100% rename from home/pkgs/techmino/ccloader.nix rename to pkgs/techmino/ccloader.nix diff --git a/home/pkgs/techmino/default.nix b/pkgs/techmino/default.nix similarity index 100% rename from home/pkgs/techmino/default.nix rename to pkgs/techmino/default.nix diff --git a/home/pkgs/techmino/libcoldclear.nix b/pkgs/techmino/libcoldclear.nix similarity index 100% rename from home/pkgs/techmino/libcoldclear.nix rename to pkgs/techmino/libcoldclear.nix diff --git a/postpush.sh b/postpush.sh new file mode 100755 index 0000000..16a547f --- /dev/null +++ b/postpush.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +mv .git .git.bak diff --git a/push.sh b/push.sh index 335aaba..9f478d9 100755 --- a/push.sh +++ b/push.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash git push git push github master -mv .git .git.bak +./postpush.sh diff --git a/system/hosts/nixmsi.nix b/system/hosts/nixmsi.nix index 7a56e8f..51f3d4d 100644 --- a/system/hosts/nixmsi.nix +++ b/system/hosts/nixmsi.nix @@ -93,7 +93,6 @@ in { # zen619.configuration.boot.kernelPackages = zenKernelPackages "6.1.9" "0fsmcjsawxr32fxhpp6sgwfwwj8kqymy0rc6vh4qli42fqmwdjgv"; # }; - nixpkgs.config.allowUnfreePredicate = pkg: (lib.getName pkg) == "steam-original"; hardware = { steam-hardware.enable = true; opengl.driSupport32Bit = true; diff --git a/system/pkgs/default.nix b/system/pkgs/default.nix deleted file mode 100644 index 5d65d2d..0000000 --- a/system/pkgs/default.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ pkgs -, lib -, ... }: - -let - inherit (pkgs) callPackage; -in { - system76-scheduler = callPackage ./system76-scheduler.nix { }; - maubot = callPackage ./maubot.nix { }; - pineapplebot = callPackage ./pineapplebot.nix { }; - inherit lib; -} -/* -// (lib.optionalAttrs (pkgs.system == "...") { - fdroidserver = pkgs.fdroidserver.overridePythonAttrs (oldAttrs: { - # remove apksigner, since official Android SDK is unavailable on arm64 - makeWrapperArgs = [ ]; - }); -}) -*/ diff --git a/update.sh b/update.sh index 396c921..2905d12 100755 --- a/update.sh +++ b/update.sh @@ -1,11 +1,15 @@ #!/usr/bin/env bash -cp ~/.config/nixpkgs/overlays.nix ./overlays.nix || echo "probably no overlays exist" +cp ~/.config/nixpkgs/overlays.nix ./overlays.nix || (mkdir -p ~/.config/nixpkgs && cp ./overlays.nix ~/.config/nixpkgs) nix flake update nvfetcher \ - -o ./home/_sources \ - -c ./home/nvfetcher.toml || echo "failed to update nvfetcher sources" + -o ./pkgs/_sources \ + -c ./pkgs/nvfetcher.toml || echo "failed to update nvfetcher sources" mozilla-addons-to-nix \ - ./home/pkgs/firefox-addons/addons.json \ - ./home/pkgs/firefox-addons/generated.nix || echo "failed to update firefox addons" -s nixos-rebuild switch --flake . || sudo nixos-rebuild switch --flake . + ./pkgs/firefox-addons/addons.json \ + ./pkgs/firefox-addons/generated.nix || echo "failed to update firefox addons" +if [ -z ${SUDO_ASKPASS+x} ]; then + sudo nixos-rebuild switch --flake . +else + sudo -A nixos-rebuild switch --flake . +fi home-manager switch --flake .