let nixpkgs_channel = builtins.getEnv "nixpkgs_channel"; # Bootstraping Nixpkgs to get tools to patch it. originNixpkgs = import (.config/nixpkgs-channel + ("/${nixpkgs_channel}.nix")); originPkgs = import originNixpkgs { config = {}; # Make the config pure, ignoring user's config. overlays = []; }; remoteNixpkgsPatches = [ { meta.description = "dstat: fix pluginpath"; url = "https://github.com/NixOS/nixpkgs/pull/80151.diff"; sha256 = "0jjw2gvp7b7v2n2m2d6yj0gw711j6p9lyjf5ywp2y9ql6905qf4b"; } { meta.description = "syncoid: fix PATH to let it use sudo"; url = "https://github.com/NixOS/nixpkgs/pull/83901.diff"; sha256 = "0q2dicmvl3h3hb9xdd870n5hf6lac489p000c7f1r6k70sh2id4l"; } { meta.description = "sanoid: fix sanoid.conf generation"; url = "https://github.com/NixOS/nixpkgs/pull/83904.diff"; sha256 = "0lj4krmmbz82zpmbacw0qj2ywsx895bq4d1psjn753ymh7jjqj8k"; } { meta.description = "nixos/public-inbox: init"; url = "https://github.com/NixOS/nixpkgs/pull/77450.diff"; sha256 = "13ikg7chpbf6rrg5sngbdb95q3awhdgl4g8vci42xmqyf208hzzd"; } { meta.description = "transmission: apply RFC0042 and harden the service"; url = "https://github.com/NixOS/nixpkgs/pull/92106.diff"; sha256 = "0d3dd511h7fw0k5q0k6wp7hcwkk7xikfwracp68f1y7hn4jj0pn0"; } { meta.description = "apparmor: fix and improve the service"; url = "https://github.com/NixOS/nixpkgs/pull/93457.diff"; sha256 = "1yhs0459r7mxdzl70l67yzbj6i67ps2znaca852hd1gffi650bkr"; } { meta.description = "nixos/security.gnupg: provisioning GnuPG-protected secrets through the Nix store"; url = "https://github.com/NixOS/nixpkgs/pull/93659.diff"; sha256 = "08pmka7ryz2gbyc8by40p31ky7s3dqxlj90dnw7fmlgb4pb3pkn0"; } { meta.description = "nixos/croc: init"; url = "https://github.com/NixOS/nixpkgs/pull/93629.diff"; sha256 = "0fv3lpj244hvxyixxv4akrr70jv5wwbhb3kmbmd2yskx59a71rch"; } { meta.description = "prosody-modules: update to revision 2dcbc01c9931"; url = "https://github.com/NixOS/nixpkgs/pull/94916.diff"; sha256 = "1cpdv5bd3837qh54yd0n6vvbfpn0p0cshkic5q0lv60lmm9raqk4"; } { meta.description = "nixos/biboumi: init"; url = "https://github.com/NixOS/nixpkgs/pull/94917.diff"; sha256 = "18my9hpl3y44yikqryrygwl0jg3dgsn1p778lja6bac6m512xk2w"; } { meta.description = "dovecot_fts_xapian: 1.3.1 -> 1.3.3"; url = "https://github.com/NixOS/nixpkgs/pull/94938.diff"; sha256 = "10bjwcwpvq7nnqdpz0n7c61kb3b27v1abyc80pki7d13jmzzjc04"; } ]; localNixpkgsPatches = [ nixpkgs/patches/installer.ssh-nixos.diff nixpkgs/patches/fix-flushBeforeStage2.diff ]; # Build nixpkgs with some patches. nixpkgs = originPkgs.applyPatches { name = "nixpkgs-patched"; src = originNixpkgs; patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches; postPatch = '' patch=$(printf '%s\n' ${builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} | sort | sha256sum | cut -c -7) echo "+patch-$patch" >.version-suffix ''; }; # Final pkgs with custom overlays. pkgs = import nixpkgs { config = {}; # Make the config pure, ignoring user's config. overlays = import nixpkgs/overlays.nix; }; # Configuration of shell/modules/ # to expand shellHook and buildInputs of this shell.nix shellConfig = {config, ...}: { imports = [ shell/gnupg.nix ]; nix = { nixConf = '' auto-optimise-store = true ''; }; nix-plugins = { enable = true; }; gnupg = { enable = true; gnupgHome = toString ../sec/gnupg; gpgExtraConf = '' # julm@sourcephile.fr trusted-key 0xB2450D97085B7B8C ''; gpgAgentExtraConf = '' #pretend-request-origin remote #extra-socket ${toString ./.}/S.gpg-agent.extra #log-file ${toString ./.}/gpg-agent.log #no-grab #debug-level expert #allow-loopback-pinentry ''; }; openssl = { enable = true; opensslHome = toString ../sec/openssl; certificates = import shell/x509.nix; }; openssh = { enable = true; sshConf = '' Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr Compression no #CompressionLevel 4 ControlMaster auto ControlPath ${toString ../sec/ssh}/ssh-%h-%p-%r.socket HashKnownHosts no #SSAPIAuthentication no SendEnv LANG LC_* StrictHostKeyChecking yes UserKnownHostsFile ${toString ../sec/ssh/known_hosts} ''; }; virtualbox = { enable = false; }; }; # Using modules enables to separate specific configurations # from reusable code in shell/modules.nix and shell/modules/ # which may find its way in another git repository one day. shell = (pkgs.lib.evalModules { modules = [ shellConfig ] ++ map import (pkgs.lib.findFiles ".*\\.nix" shell/modules); args = { inherit pkgs; }; }).config; pwd = toString (./. + ""); sourcephile-shred-tmp = pkgs.writeShellScriptBin "sourcephile-shred-tmp" '' # This is done when entering the nix-shell # because direnv already hooks trap EXIT. cd "${pwd}" test ! -e sec/tmp || { find sec/tmp -type f -exec shred -fu {} + rm -rf sec/tmp } ''; in pkgs.mkShell { name = "sourcephile-nix"; src = null; #preferLocalBuild = true; #allowSubstitutes = false; buildInputs = shell.nix-shell.buildInputs ++ [ sourcephile-shred-tmp (pkgs.nixos []).nixos-generate-config (pkgs.nixos []).nixos-install (pkgs.nixos []).nixos-enter #pkgs.binutils pkgs.coreutils pkgs.cryptsetup pkgs.curl #pkgs.direnv pkgs.dnsutils #pkgs.dropbear pkgs.e2fsprogs pkgs.git pkgs.glibcLocales pkgs.gnumake pkgs.gnupg pkgs.htop #pkgs.inetutils pkgs.ipcalc #pkgs.iputils pkgs.less pkgs.libfaketime pkgs.ldns #pkgs.ldns.examples #pkgs.mailutils pkgs.man pkgs.mdadm pkgs.gptfdisk pkgs.ncdu pkgs.ncurses #pkgs.nixops #pkgs.openssl pkgs.pass pkgs.procps pkgs.rsync #pkgs.rxvt_unicode.terminfo #pkgs.sqlite pkgs.sqlite #pkgs.sudo pkgs.tig pkgs.time #pkgs.tmux pkgs.tree pkgs.utillinux #pkgs.vim #pkgs.virtualbox pkgs.which pkgs.xdg_utils pkgs.zfs pkgs.fio pkgs.strace pkgs.utillinux #pkgs.zfstools pkgs.linuxPackages.perf #pkgs.go2nix pkgs.wireguard pkgs.stun ]; #enableParallelBuilding = true; shellHook = '' echo >&2 "nix: running shellHook" # password-store export PASSWORD_STORE_DIR="$PWD"/../sec/pass # Nix PATH=$NIX_SHELL_PATH:$PATH export NIX_PATH="${pkgs.lib.concatStringsSep ":" [ "machines=$PWD/machines.nix" #"pass=$PASSWORD_STORE_DIR" "nixpkgs=${toString pkgs.path}" "nixpkgs-overlays=$PWD/nixpkgs/overlays.nix" ]}" # Since the .envrc calls this shellHook # the EXIT trap cannot be freely used # because it's already used by direnv, # hence shred at startup, which is not ideal. sourcephile-shred-tmp ${shell.nix-shell.shellHook} # gpg export GPG_TTY=$(tty) gpg-connect-agent updatestartuptty /bye >/dev/null ''; }