let sources = import ../npins; default_nixpgs = sources.nixpkgs_nixos-unstable; pkgs_overlays = [ base.args.overlays.default (import sources.rust-overlay) ]; # pkgs versions pkgs = import default_nixpgs { overlays = pkgs_overlays; }; pkgs-stable = import sources.nixpkgs_nixos-26-05 { overlays = pkgs_overlays; }; pkgs-master = import sources.nixpkgs_master { }; lib = pkgs.lib; mods = { priv_mod = import ../modules/priv { inherit lib; }; pub_mod = { containers = ../modules/pub/containers.nix; arr = ../modules/pub/arr.nix; }; host = { work = { hjem-rum = ../hosts/work/hjem-rum; }; sand-archives = { hjem-rum = ../hosts/sand-archives/hjem-rum; }; }; }; pins = ( helpers.gen_pins sources [ "helix_nix" "nixpkgs" "dune" "awoopkgs" ] ); base = { wire = import sources.wire; args = { inherit sources; inherit pkgs; inherit pkgs-master; inherit pkgs-stable; inherit mods; inherit pins; pup_lib = import ./.; overlays = { default = import ../overlays/default/overlay.nix { inherit pins; inherit pkgs-master; }; }; pm = mods.priv_mod.get_data; }; }; # Attribute set of helper functions helpers = { nixosSystem = import "${toString default_nixpgs.outPath}/nixos/lib/eval-config.nix"; # Helper function that merges all nixos modules from a given directory and returns them # Currently only used to merge multiple program definitions and set the merged result as the value # For example # # programs = ( # args.pup_lib.merge_modules (./. + "/programs") { # inherit args; # inherit pkgs; # } # ); # merge_modules = ( path: args: let files = builtins.readDir path; nix_files = lib.attrNames ( lib.filterAttrs (name: value: (lib.hasSuffix ".nix" name && value == "regular")) files ); result = map (file_name: (import "${path}/${file_name}" args)) nix_files; in lib.mkMerge result ); # Helper function that gets all the nix files from specific directory and returns them as a list # Used for the imports = []; statements to keep it cleaner module_imports = ( path: let files = builtins.readDir path; nix_files = lib.attrNames ( lib.filterAttrs (name: value: (lib.hasSuffix ".nix" name && value == "regular")) files ); result = map (file_name: "${path}/${file_name}") nix_files; in result ); gen_pins = ( src: excl: (lib.mapAttrs ( name: value: if builtins.elem name excl then (import value { }) else (import src.flake-compat { src = builtins.path { inherit name; path = value; }; }).outputs ) src) ); gen_host = ( modules: arguments: (helpers.nixosSystem { inherit modules; specialArgs = let args = arguments // { inherit mods; }; in { inherit args; }; }) ); get_netbird_dashboard = ( netbird_dashboard_settings: let toStringEnv = value: if lib.isBool value then lib.boolToString value else toString value; in pkgs.runCommand "netbird-dashboard" { nativeBuildInputs = [ pkgs.gettext ]; env = { ENV_STR = lib.concatStringsSep " " [ "$AUTH_AUDIENCE" "$AUTH_AUTHORITY" "$AUTH_CLIENT_ID" "$AUTH_CLIENT_SECRET" "$AUTH_REDIRECT_URI" "$AUTH_SILENT_REDIRECT_URI" "$AUTH_SUPPORTED_SCOPES" "$NETBIRD_DRAG_QUERY_PARAMS" "$NETBIRD_GOOGLE_ANALYTICS_ID" "$NETBIRD_GOOGLE_TAG_MANAGER_ID" "$NETBIRD_HOTJAR_TRACK_ID" "$NETBIRD_MGMT_API_ENDPOINT" "$NETBIRD_MGMT_GRPC_API_ENDPOINT" "$NETBIRD_TOKEN_SOURCE" "$NETBIRD_WASM_PATH" "$USE_AUTH0" ]; } // (lib.mapAttrs (_: toStringEnv) netbird_dashboard_settings); } '' cp -R ${pkgs.netbird-dashboard} build find build -type d -exec chmod 755 {} \; OIDC_TRUSTED_DOMAINS="build/OidcTrustedDomains.js" envsubst "$ENV_STR" < "$OIDC_TRUSTED_DOMAINS.tmpl" > "$OIDC_TRUSTED_DOMAINS" for f in $(grep -R -l AUTH_SUPPORTED_SCOPES build/); do mv "$f" "$f.copy" envsubst "$ENV_STR" < "$f.copy" > "$f" rm "$f.copy" done cp -R build $out '' ); }; in helpers // { inherit base; }