diff options
Diffstat (limited to '')
| -rw-r--r-- | modules/by-name/ni/nix-index/command_not_found.fish | 111 | ||||
| -rw-r--r-- | modules/by-name/ni/nix-index/command_not_found.zsh (renamed from modules/by-name/ni/nix-index/command_not_found.sh) | 4 | ||||
| -rw-r--r-- | modules/by-name/ni/nix-index/module.nix | 8 | ||||
| -rw-r--r-- | modules/by-name/ni/nix/module.nix | 89 | ||||
| -rw-r--r-- | modules/by-name/ni/nixos-option/module.nix | 18 | ||||
| -rw-r--r-- | modules/by-name/ni/nixos-shell/module.nix | 7 | ||||
| -rwxr-xr-x | modules/by-name/ni/nixos-shell/nixos-shell.sh | 2 | ||||
| -rw-r--r-- | modules/by-name/ni/nixpkgs/config.nix | 43 | ||||
| -rw-r--r-- | modules/by-name/ni/nixpkgs/module.nix | 19 |
9 files changed, 199 insertions, 102 deletions
diff --git a/modules/by-name/ni/nix-index/command_not_found.fish b/modules/by-name/ni/nix-index/command_not_found.fish new file mode 100644 index 00000000..bbdb2230 --- /dev/null +++ b/modules/by-name/ni/nix-index/command_not_found.fish @@ -0,0 +1,111 @@ +#!/usr/bin/env fish + +# nixos-config - My current NixOS configuration +# +# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This file is part of my nixos-config. +# +# You should have received a copy of the License along with this program. +# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. + +# This was taken from the +# `${pkgs.nix-index}/etc/profile.d/command-not-found.sh` file on 2024-02-28 + +function _log + printf $argv >&2 +end + +function _bail + __fish_default_command_not_found_handler $argv + return "$status" +end + +function _common_prefix + set --function prefix + + for str in $argv + set position 1 + for c in (string split '' "$str") + if test -z $prefix[$position] + set prefix[$position] "$c" + else if test $prefix[$position] != "$c" + if test $position = 1 + # The first letter of the prefix mis-matched. + # As such there is no shared prefix, and we can simple bail early. + echo "" + return + else + set prefix $prefix[1..(math $position - 1)] + end + break + end + + set position (math $position + 1) + end + end + + echo "$(string join "" $prefix)" +end + +function fish_command_not_found + # Only run if it's an interactive shell + if not status is-interactive + return (_bail $argv) + end + + # The nixpkgs flake should always be available on NixOS + set --local toplevel nixpkgs + set --local cmd "$argv[1]" + + set --local attrs "$(nix-locate --minimal --no-group --type x --type s --whole-name --at-root "/bin/$cmd")" + + if test -n "$attrs" + set --function len "$(echo "$attrs" | count)" + else + set --function len 0 + end + + switch "$len" + case 0 + case 1 or '*' + _log "The program '%s' is currently not installed.\n" "$cmd" + end + + switch "$len" + case 0 + return (_bail $argv) + case 1 + # If only one package provides this, then we can invoke it + # without asking the user. + + # These will not return 127 if they worked correctly. + + _log "A shell will be opened with it.\n" + + if nix build "$toplevel#$attrs" --no-link + nix shell "$toplevel#$attrs" + return "$status" + else + _log "Failed to build: '%s#%s'\n" "$toplevel" "$attrs" + return (_bail $argv) + end + case '*' + _log "It is provided by several packages. You can run it load it with:\n" + + set --local counter 0 + set --local attrs $(echo $attrs) + for attr in $attrs + _log "%3s)" "$counter" + _log " nix shell %s#%s\n" "$toplevel" "$attr"; + + set counter "$(math "$counter" + 1)" + end + + commandline "nix shell $toplevel#$(_common_prefix $attrs)" + end + + # command not found should always exit with 127 + return 127 +end diff --git a/modules/by-name/ni/nix-index/command_not_found.sh b/modules/by-name/ni/nix-index/command_not_found.zsh index f650cf7b..579f9db4 100644 --- a/modules/by-name/ni/nix-index/command_not_found.sh +++ b/modules/by-name/ni/nix-index/command_not_found.zsh @@ -26,12 +26,12 @@ command_not_found_handle() { toplevel=nixpkgs # nixpkgs should always be available even in NixOS cmd="$1" - attrs=$(nix-locate --minimal --no-group --type x --type s --top-level --whole-name --at-root "/bin/$cmd") + attrs=$(nix-locate --minimal --no-group --type x --type s --whole-name --at-root "/bin/$cmd") len=$(if [ -n "$attrs" ]; then echo "$attrs" | wc -l; else echo 0; fi) case "$len" in 0) - eprintln "$cmd: command not found" + printf "%s: command not found\n" "$cmd" >&2 ;; 1) # If only one package provides this, then we can invoke it diff --git a/modules/by-name/ni/nix-index/module.nix b/modules/by-name/ni/nix-index/module.nix index 06acfc8a..72be6b52 100644 --- a/modules/by-name/ni/nix-index/module.nix +++ b/modules/by-name/ni/nix-index/module.nix @@ -20,10 +20,14 @@ in { }; config = lib.mkIf cfg.enable { - soispha.programs.zsh.integrations.nix-index = ./command_not_found.sh; + soispha.programs = { + zsh.integrations.nix-index = ./command_not_found.zsh; + fish.integrations.nix-index = ./command_not_found.fish; + }; + home-manager.users.soispha = { imports = [ - modules.nix-index-database.hmModules.nix-index + modules.nix-index-database.homeModules.nix-index ]; programs.nix-index = { diff --git a/modules/by-name/ni/nix/module.nix b/modules/by-name/ni/nix/module.nix index 0072164f..b7e64989 100644 --- a/modules/by-name/ni/nix/module.nix +++ b/modules/by-name/ni/nix/module.nix @@ -9,63 +9,74 @@ # If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. { pkgs, + libraries, + config, + lib, # flakes + sources, self, system, externalDependencies, ... -}: { - # TODO(@bpeetz): Modularize <2025-02-08> +}: let + inherit (sources) nixpkgs; - nix = { - package = pkgs.lix; + cfg = config.soispha.nix; +in { + options.soispha.nix = { + enable = libraries.base.options.mkEnable "nix"; + }; - # Disable nix channels (this is a remnant of old days) - channel.enable = false; + config = lib.mkIf cfg.enable { + nix = { + package = pkgs.lixPackageSets.latest.lix; - registry = { - nixpkgs.flake = self.inputs.nixpkgs; - n.flake = - self.inputs.nixpkgs - // { - # Otherwise nixpkgs's config and overlays are not available: + # Disable nix channels (this is a remnant of old days) + channel.enable = false; - # Both attrs exists, so we just override both and hope - outputs.legacyPackages."${system}" = pkgs; - legacyPackages."${system}" = pkgs; - }; + registry = { + nixpkgs.flake = nixpkgs; + n.flake = + nixpkgs + // { + # Otherwise nixpkgs's config and overlays are not available: - t.flake = externalDependencies.templates; + # Both attrs exists, so we just override both and hope + outputs.legacyPackages."${system}" = pkgs; + legacyPackages."${system}" = pkgs; + }; - my_flake.flake = self; - m.flake = self; - }; + t.flake = externalDependencies.templates; - gc = { - automatic = true; - dates = "weekly"; - options = "--delete-older-than 7d"; - }; + my_flake.flake = self; + m.flake = self; + }; + + gc = { + automatic = true; + dates = "weekly"; + options = "--delete-older-than 7d"; + }; - settings = { - auto-optimise-store = true; - experimental-features = [ - "nix-command" - "flakes" - #"ca-derivations" - ]; + settings = { + # Don't warn about dirty git trees (It is usually absolutely useless) + warn-dirty = false; - use-xdg-base-directories = true; + auto-optimise-store = true; + experimental-features = [ + "nix-command" + "flakes" + ]; - #substituters = ["https://cache.ngi0.nixos.org/"]; - #trusted-public-keys = ["cache.ngi0.nixos.org-1:KqH5CBLNSyX184S9BKZJo1LxrxJ9ltnY2uAs5c/f1MA="]; + use-xdg-base-directories = true; - fallback = true; # Build from source, if binary can't be substituted + fallback = true; # Build from source, if binary can't be substituted - keep-failed = false; # keep failed tmp build dirs - pure-eval = true; # restrict file system and network access to hash + keep-failed = false; # keep failed tmp build dirs + pure-eval = true; # restrict file system and network access to hash - sandbox-fallback = false; # Don't disable the sandbox, if the kernel doesn't support it + sandbox-fallback = false; # Don't disable the sandbox, if the kernel doesn't support it + }; }; }; } diff --git a/modules/by-name/ni/nixos-option/module.nix b/modules/by-name/ni/nixos-option/module.nix new file mode 100644 index 00000000..0053d357 --- /dev/null +++ b/modules/by-name/ni/nixos-option/module.nix @@ -0,0 +1,18 @@ +{ + config, + lib, + libraries, + ... +}: let + cfg = config.soispha.programs.nixos-option; +in { + options.soispha.programs.nixos-option = { + enable = libraries.base.options.mkEnable "nixos-option"; + }; + + config = lib.mkIf cfg.enable { + # NOTE: We disable nixos-option here explicitly, because I never used it, and it + # depends on cppnix. <2025-12-11> + system.tools.nixos-option.enable = false; + }; +} diff --git a/modules/by-name/ni/nixos-shell/module.nix b/modules/by-name/ni/nixos-shell/module.nix index 219f080d..1a0190c8 100644 --- a/modules/by-name/ni/nixos-shell/module.nix +++ b/modules/by-name/ni/nixos-shell/module.nix @@ -11,10 +11,11 @@ lib, config, pkgs, - self, + sources, ... }: let cfg = config.soispha.nixos-shell; + inherit (sources) nixpkgs; in { options.soispha.nixos-shell = { enable = lib.mkEnableOption "nixos-shell"; @@ -85,13 +86,13 @@ in { }; config = let - vmSystem = self.inputs.nixpkgs.lib.nixosSystem { + vmSystem = nixpkgs.lib.nixosSystem { inherit (cfg.configuration) specialArgs; modules = [ { # TODO(@bpeetz): This should be bumped each release. <2025-05-17> - system.stateVersion = "25.05"; + system.stateVersion = "25.11"; } cfg.configuration.value diff --git a/modules/by-name/ni/nixos-shell/nixos-shell.sh b/modules/by-name/ni/nixos-shell/nixos-shell.sh index 390e60b1..3b34019a 100755 --- a/modules/by-name/ni/nixos-shell/nixos-shell.sh +++ b/modules/by-name/ni/nixos-shell/nixos-shell.sh @@ -10,7 +10,7 @@ # You should have received a copy of the License along with this program. # If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. -SHARED_DIR="$(mktemp --directory)" +SHARED_DIR="$(mktemp -t --directory "nixos_shell_XXXXXXXXX")" cleanup() { rm --recursive "$SHARED_DIR" } diff --git a/modules/by-name/ni/nixpkgs/config.nix b/modules/by-name/ni/nixpkgs/config.nix deleted file mode 100644 index ea8f3c45..00000000 --- a/modules/by-name/ni/nixpkgs/config.nix +++ /dev/null @@ -1,43 +0,0 @@ -# nixos-config - My current NixOS configuration -# -# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> -# SPDX-License-Identifier: GPL-3.0-or-later -# -# This file is part of my nixos-config. -# -# You should have received a copy of the License along with this program. -# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. -{ - cfg, - lib, - packageSets, - ... -}: let - myPkgsOverlay = self: super: packageSets.soispha; -in { - nixpkgs = { - hostPlatform = cfg.systemName; - - overlays = [ - myPkgsOverlay - ]; - - config = { - # TODO: this fails because of the root tempsize, which should be increased - # contentAddressedByDefault = true; - - hostSystem = cfg.systemName; - - allowUnfreePredicate = pkg: - builtins.elem (lib.getName pkg) [ - "pypemicro" # required by pynitrokey - - # TODO(@bpeetz): Allow moving them to their respective module. <2025-04-25> - "steam" - "steam-unwrapped" - "steam-original" - "steam-run" - ]; - }; - }; -} diff --git a/modules/by-name/ni/nixpkgs/module.nix b/modules/by-name/ni/nixpkgs/module.nix index fcde9505..1ded8444 100644 --- a/modules/by-name/ni/nixpkgs/module.nix +++ b/modules/by-name/ni/nixpkgs/module.nix @@ -22,7 +22,13 @@ in { example = "x86_64-linux"; type = lib.types.str; }; + unfreePackageNames = lib.mkOption { + description = "Names of unfree packages to allow"; + example = "[ steam steam-unwrapped ]"; + type = lib.types.listOf lib.types.str; + }; }; + config = let myPkgsOverlay = self: super: packageSets.soispha; in @@ -36,21 +42,10 @@ in { ]; config = { - # TODO: this fails because of the root tempsize, which should be increased - # contentAddressedByDefault = true; - hostSystem = cfg.systemName; allowUnfreePredicate = pkg: - builtins.elem (lib.getName pkg) [ - "pypemicro" # required by pynitrokey - - # TODO(@bpeetz): Allow moving them to their respective module. <2025-04-25> - "steam" - "steam-unwrapped" - "steam-original" - "steam-run" - ]; + builtins.elem (lib.getName pkg) cfg.unfreePackageNames; }; }; }; |
