diff --git a/devices/android/default.nix b/devices/android/default.nix index 3072f43f..281808de 100644 --- a/devices/android/default.nix +++ b/devices/android/default.nix @@ -3,11 +3,11 @@ lib, pkgs, ... -}: { +}: let + inherit (lib) attrValues concatStringsSep; +in { imports = [./nix-on-droid.nix]; - vars.mainUser = "nix-on-droid"; - environment.variables.FLAKE = "/data/data/com.termux.nix/files/home/.nix"; terminal.font = "${(pkgs.nerdfonts.override { @@ -19,7 +19,8 @@ environment.packages = [ (pkgs.writeShellApplication { name = "switch"; - runtimeInputs = builtins.attrValues { + + runtimeInputs = attrValues { inherit (pkgs) coreutils @@ -27,10 +28,11 @@ nvd ; }; + text = '' oldProfile=$(realpath /nix/var/nix/profiles/per-user/nix-on-droid/profile) - nix-on-droid ${lib.concatStringsSep " " [ + nix-on-droid ${concatStringsSep " " [ "switch" "--flake ${config.environment.variables.FLAKE}" "--builders ssh-ng://matt@100.64.0.7" diff --git a/devices/android/nix-on-droid.nix b/devices/android/nix-on-droid.nix index 57b7c7a5..8f306dfd 100644 --- a/devices/android/nix-on-droid.nix +++ b/devices/android/nix-on-droid.nix @@ -1,13 +1,16 @@ -# FIXME: eval is broken { config, self, ... }: { imports = [ - ../../common/vars - ../../common/modules/global.nix - ../../common/packages.nix + self.nixosModules.base-droid + { + roles.base = { + enable = true; + user = "nix-on-droid"; + }; + } self.nixosModules.tmux {programs.tmux.enableCustomConf = true;} diff --git a/nixosModules/base/default-droid.nix b/nixosModules/base/default-droid.nix new file mode 100644 index 00000000..d6fecc50 --- /dev/null +++ b/nixosModules/base/default-droid.nix @@ -0,0 +1,22 @@ +self: {lib, ...}: let + inherit (lib) mkOption types; +in { + imports = [ + (import ./common-nix self) + (import ./packages self) + ]; + + options.roles.base = { + enable = mkOption { + type = types.bool; + default = true; + }; + + user = mkOption { + type = types.str; + }; + }; + + # For accurate stack trace + _file = ./default.nix; +} diff --git a/nixosModules/base/default.nix b/nixosModules/base/default.nix index 3e200739..ca9a227d 100644 --- a/nixosModules/base/default.nix +++ b/nixosModules/base/default.nix @@ -33,7 +33,7 @@ in { }; }; - config = mkIf (cfg.enable) { + config = mkIf cfg.enable { environment.variables.FLAKE = mkDefault "/home/${cfg.user}/.nix"; programs.tmux.enableCustomConf = true; diff --git a/nixosModules/base/locale/default.nix b/nixosModules/base/locale/default.nix index 50ebc38c..d78ea42e 100644 --- a/nixosModules/base/locale/default.nix +++ b/nixosModules/base/locale/default.nix @@ -1,45 +1,55 @@ -{pkgs, ...}: { - fonts = { - fontconfig = { - enable = true; - defaultFonts = { - emoji = ["Noto Color Emoji"]; - monospace = ["JetBrainsMono Nerd Font"]; - sansSerif = ["Noto Nerd Font"]; - serif = ["Noto Nerd Font"]; +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib) attrValues mkIf; + + cfg = config.roles.base; +in + mkIf cfg.enable { + fonts = { + fontconfig = { + enable = true; + defaultFonts = { + emoji = ["Noto Color Emoji"]; + monospace = ["JetBrainsMono Nerd Font"]; + sansSerif = ["Noto Nerd Font"]; + serif = ["Noto Nerd Font"]; + }; }; + + packages = + [ + (pkgs.nerdfonts.override { + fonts = [ + "JetBrainsMono" + "Go-Mono" + "Iosevka" + "NerdFontsSymbolsOnly" + "SpaceMono" + "Ubuntu" + "Noto" + ]; + }) + ] + ++ (attrValues { + inherit + (pkgs) + noto-fonts + noto-fonts-cjk-sans + noto-fonts-emoji + liberation_ttf + font-awesome + meslo-lgs-nf + jetbrains-mono + ubuntu_font_family + ; + }); }; - packages = - [ - (pkgs.nerdfonts.override { - fonts = [ - "JetBrainsMono" - "Go-Mono" - "Iosevka" - "NerdFontsSymbolsOnly" - "SpaceMono" - "Ubuntu" - "Noto" - ]; - }) - ] - ++ (builtins.attrValues { - inherit - (pkgs) - noto-fonts - noto-fonts-cjk-sans - noto-fonts-emoji - liberation_ttf - font-awesome - meslo-lgs-nf - jetbrains-mono - ubuntu_font_family - ; - }); - }; - - # Select internationalisation properties. - i18n.defaultLocale = "en_CA.UTF-8"; - console.useXkbConfig = true; -} + # Select internationalisation properties. + i18n.defaultLocale = "en_CA.UTF-8"; + console.useXkbConfig = true; + } diff --git a/nixosModules/base/locate/default.nix b/nixosModules/base/locate/default.nix index 7bc63a99..17cf6035 100644 --- a/nixosModules/base/locate/default.nix +++ b/nixosModules/base/locate/default.nix @@ -4,7 +4,7 @@ lib, ... }: let - inherit (lib) concatStringsSep getName; + inherit (lib) concatStringsSep getName mkIf; baseCfg = config.roles.base; cfg = config.services.locate; @@ -23,59 +23,60 @@ ${updatedb} -o ${database} --prunefs "${pruneFS}" \ --prunepaths "${prunePaths}" --prunenames "${pruneNames}" ''; -in { - users.users.${baseCfg.user}.extraGroups = [ - locateGroup - ]; +in + mkIf (baseCfg.enable) { + users.users.${baseCfg.user}.extraGroups = [ + locateGroup + ]; - # TODO: add timer - systemd.services.locate = { - wantedBy = ["default.target"]; - serviceConfig = { - User = baseCfg.user; - Group = locateGroup; - StateDirectory = "locate"; - StateDirectoryMode = "0770"; - ExecStart = updatedbBin; + # TODO: add timer + systemd.services.locate = { + wantedBy = ["default.target"]; + serviceConfig = { + User = baseCfg.user; + Group = locateGroup; + StateDirectory = "locate"; + StateDirectoryMode = "0770"; + ExecStart = updatedbBin; + }; }; - }; - home-manager.users.${baseCfg.user}.programs.bash.shellAliases = { - locate = "${pkgs.writeShellScriptBin "lct" '' - exec ${locate} -d ${database} "$@" 2> >(grep -v "/var/cache/locatedb") - ''}/bin/lct"; + home-manager.users.${baseCfg.user}.programs.bash.shellAliases = { + locate = "${pkgs.writeShellScriptBin "lct" '' + exec ${locate} -d ${database} "$@" 2> >(grep -v "/var/cache/locatedb") + ''}/bin/lct"; - updatedb = updatedbBin; - }; + updatedb = updatedbBin; + }; - services.locate = { - enable = true; - package = pkgs.mlocate; - localuser = null; - interval = "never"; + services.locate = { + enable = true; + package = pkgs.mlocate; + localuser = null; + interval = "never"; - prunePaths = [ - "/var/lib/flatpak" + prunePaths = [ + "/var/lib/flatpak" - # Defaults - "/tmp" - "/var/tmp" - "/var/cache" - "/var/lock" - "/var/run" - "/var/spool" - "/nix/var/log/nix" - ]; + # Defaults + "/tmp" + "/var/tmp" + "/var/cache" + "/var/lock" + "/var/run" + "/var/spool" + "/nix/var/log/nix" + ]; - pruneNames = [ - "node_modules" + pruneNames = [ + "node_modules" - # Defaults - ".bzr" - ".cache" - ".git" - ".hg" - ".svn" - ]; - }; -} + # Defaults + ".bzr" + ".cache" + ".git" + ".hg" + ".svn" + ]; + }; + } diff --git a/nixosModules/base/substituters/default.nix b/nixosModules/base/substituters/default.nix index 8804bbe1..fbc50c95 100644 --- a/nixosModules/base/substituters/default.nix +++ b/nixosModules/base/substituters/default.nix @@ -4,7 +4,9 @@ pkgs, ... }: let - inherit (lib) foldl isList mergeAttrsWithFunc optionals unique; + inherit (lib) foldl isList mergeAttrsWithFunc mkIf optionals unique; + + cfg = config.roles.base; mergeAttrsList = list: foldl (mergeAttrsWithFunc (a: b: @@ -12,35 +14,36 @@ then unique (a ++ b) else b)) {} list; -in { - environment.systemPackages = [ - (pkgs.writeShellApplication { - name = "rebuild-no-cache"; - runtimeInputs = [config.programs.nh.package]; - text = '' - exec nh os switch -- --option binary-caches "https://cache.nixos.org" "$@" - ''; - }) - ]; +in + mkIf cfg.enable { + environment.systemPackages = [ + (pkgs.writeShellApplication { + name = "rebuild-no-cache"; + runtimeInputs = [config.programs.nh.package]; + text = '' + exec nh os switch -- --option binary-caches "https://cache.nixos.org" "$@" + ''; + }) + ]; - nix = { - settings = let - mkSubstituterConf = url: key: { - substituters = [url]; - trusted-public-keys = optionals (key != null) [key]; - }; - in - mergeAttrsList ([ - (mkSubstituterConf "https://cache.nixos.org" "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=") - (mkSubstituterConf "https://hyprland.cachix.org" "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=") - (mkSubstituterConf "https://nix-gaming.cachix.org" "nix-gaming.cachix.org-1:nbjlureqMbRAxR1gJ/f3hxemL9svXaZF/Ees8vCUUs4=") - (mkSubstituterConf "https://nixpkgs-wayland.cachix.org" "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA=") - (mkSubstituterConf "https://nix-community.cachix.org" "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=") - (mkSubstituterConf "https://viperml.cachix.org" "viperml.cachix.org-1:qZhKBMTfmcLL+OG6fj/hzsMEedgKvZVFRRAhq7j8Vh8=") - (mkSubstituterConf "https://cuda-maintainers.cachix.org" "cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E=") - ] - ++ optionals (!config.services.nix-serve.enable) [ - (mkSubstituterConf "https://cache.nelim.org" "cache.nelim.org:JmFqkUdH11EA9EZOFAGVHuRYp7EbsdJDHvTQzG2pPyY=") - ]); - }; -} + nix = { + settings = let + mkSubstituterConf = url: key: { + substituters = [url]; + trusted-public-keys = optionals (key != null) [key]; + }; + in + mergeAttrsList ([ + (mkSubstituterConf "https://cache.nixos.org" "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=") + (mkSubstituterConf "https://hyprland.cachix.org" "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=") + (mkSubstituterConf "https://nix-gaming.cachix.org" "nix-gaming.cachix.org-1:nbjlureqMbRAxR1gJ/f3hxemL9svXaZF/Ees8vCUUs4=") + (mkSubstituterConf "https://nixpkgs-wayland.cachix.org" "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA=") + (mkSubstituterConf "https://nix-community.cachix.org" "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=") + (mkSubstituterConf "https://viperml.cachix.org" "viperml.cachix.org-1:qZhKBMTfmcLL+OG6fj/hzsMEedgKvZVFRRAhq7j8Vh8=") + (mkSubstituterConf "https://cuda-maintainers.cachix.org" "cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E=") + ] + ++ optionals (!config.services.nix-serve.enable) [ + (mkSubstituterConf "https://cache.nelim.org" "cache.nelim.org:JmFqkUdH11EA9EZOFAGVHuRYp7EbsdJDHvTQzG2pPyY=") + ]); + }; + } diff --git a/nixosModules/default.nix b/nixosModules/default.nix index 6df0adb3..7f9cf94b 100644 --- a/nixosModules/default.nix +++ b/nixosModules/default.nix @@ -1,5 +1,6 @@ self: { base = import ./base self; + base-droid = import ./base/default-droid.nix self; borgbackup = import ./borgbackup; desktop = import ./desktop self; docker = import ./docker self.inputs.khepri;