Giter Club home page Giter Club logo

Comments (5)

hlissner avatar hlissner commented on July 21, 2024 1

Yes, it can, and is in fact exactly what I'm doing. Before that, I merged the built-in lib and mine.

Now my personal library is available everywhere under lib.my.

from dotfiles.

shadowrylander avatar shadowrylander commented on July 21, 2024

Perfect! Mind if I copy your lib setup, then? 😺

from dotfiles.

hlissner avatar hlissner commented on July 21, 2024

Feel free. Glad I could help!

from dotfiles.

shadowrylander avatar shadowrylander commented on July 21, 2024

Thanks! However, could you help me with this? I'm getting the error attribute '_' missing in my config, which is what I called my extra modules instead of my; lib/default.nix imports just fine, though.
configuration.nix:

# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).

{ config, pkgs, lib, ... }:

# let extraBuiltins = (import /etc/nixos/shared/global/_extraBuiltins.nix { inherit lib; }); in {
{
    imports = lib._.zettelkasten.list [];

    config = lib.mkMerge [{

            powerManagement = {
                enable = true;
                cpuFreqGovernor = lib.mkDefault "powersave";
            };

            # Select internationalisation properties.
            i18n.defaultLocale = "en_US.UTF-8";
            console = {
                # font = lib.mkDefault "${pkgs.terminus_font}/share/consolefonts/ter-u28n.psf.gz";
                font = "Cartograph CF Light Italic";
                keyMap = "us";
            };

            # Set your time zone.
            time.timeZone = "America/Toronto";

            # Enable sound.
            sound.enable = true;
            hardware.pulseaudio.enable = true;

            # This value determines the NixOS release from which the default
            # settings for stateful data, like file locations and database versions
            # on your system were taken. It‘s perfectly fine and recommended to leave
            # this value at the release version of the first install of this system.
            # Before changing this value read the documentation for this option
            # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
        }
    ];
}

flake.nix:

{
  description = "shadowrylander";

  inputs = rec {
    home-manager = {
      url = "github:nix-community/home-manager/master";
      # https://github.com/nix-community/home-manager/blob/master/flake.nix#L4
      # HM takes 'nixpkgs' as input
      inputs.nixpkgs.follows = "nixpkgs";
    };
    mach-nix = {
        # url = "github:davhau/mach-nix/master";
        # url = "/home/shadowrylander/mach-nix";
        url = "/etc/nixos/extras/mach-nix";
        inputs.nixpkgs.follows = "nixpkgs";
    };
    impermanence = {
      url = "github:nix-community/impermanence";
      flake = false;
    };
    flake-utils = {
        url = "github:numtide/flake-utils";
        inputs.nixpkgs.follows = "nixpkgs";
    };
    nur = {
      url = github:nix-community/NUR;
      inputs.nixpkgs.follows = "nixpkgs";
    };

    r2003.url = "github:NixOS/nixpkgs/nixos-20.03";
    r2003small.url = "github:NixOS/nixpkgs/nixos-20.03-small";
    r2009.url = "github:NixOS/nixpkgs/nixos-20.09";
    r2009small.url = "github:NixOS/nixpkgs/nixos-20.09-small";
    # r2103.url = "github:NixOS/nixpkgs/nixos-21.03";
    # r2103small.url = "github:NixOS/nixpkgs/nixos-21.03-small";
    unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
    small.url = "github:NixOS/nixpkgs/nixos-unstable-small";
    master.url = "github:NixOS/nixpkgs/master";

    nixpkgs.follows = "master";

    nix = { url = "github:NixOS/nix/master"; };

  };

  outputs = inputs@{ self, nixpkgs, flake-utils, ... }: let

    createOverlay = name: {
      inherit name;
      # value = final: prev: { "${name}" = inputs.${name}.legacyPackages.${system}; };
      value = final: prev: { "${name}" = inputs.${name}; };
    };

    global = "/shared/global";

    _pkgs = {
      set = (import nixpkgs {});
      func = _: (import nixpkgs _);
    };
    
    ########################################################
    lib = (import (./. + "${global}/lib") { inherit nixpkgs; });
    inherit (lib) nameValuePair mapAttrsToList removeSuffix filterAttrs hasSuffix;
    ########################################################

  in rec {

    overlays = (map createOverlay [
      "r2003"
      "r2003small"
      "r2009"
      "r2009small"
      # "r2103"
      # "r2103small"
      "unstable"
      "small"
    ]) ++ [ inputs.nur.overlay ];

    nixosConfigurations = let

      ##########################
      specialArgs = { inherit lib inputs; };
      ##########################

      configDir = "/configs";

      create = hostname: let

        system = if (
          hostname == "bastion"
        ) then "armv7l-linux" else "x86_64-linux";

        # system = lib.mkIf lib.mkForce ( hostname == "flipper" ) "";

        config = ./. + "${configDir}/${hostname}.nix";

        pkgs = _pkgs.func (import (./. + "${global}/_nixpkgs.nix") {
          inherit lib;
          # mach-nix = inputs.mach-nix.packages.${system}.mach-nix;
          stdenv = {
            inherit system;
            package = _pkgs.set.gcc10.stdenv;
          };
          pkgs = _pkgs.set;
        });

        base = {
          global = {
            modules = with inputs; [
              home-manager.nixosModules.home-manager
              "${impermanence}/nixos.nix"
              # "${impermanence}/home-manager.nix"
            ];
          };
        };

      in nixpkgs.lib.nixosSystem {
        inherit system pkgs;
        modules = base.global.modules ++ [ (import config) ];
      };

      devices = mapAttrsToList (
        name: value: removeSuffix ".nix" name
      ) (
        filterAttrs (
          name: value: (value == "regular") && (hasSuffix ".nix" name)
        ) (builtins.readDir (./. + configDir))
      );

    in (builtins.listToAttrs (map (hostname: nameValuePair hostname (create hostname)) devices)) // {
      # [...]
    };
  };
}

lib/default.nix:

{ nixpkgs, ... }:

# From: https://github.com/hlissner/dotfiles

nixpkgs.lib.extend (self: super: { _ = let
        inherit (self) mapAttrsToList filterAttrs hasPrefix any removeSuffix getName nameValuePair;
        inherit (self) makeExtensible attrValues foldr;

        zettelkasten = rec {
            list = ignores: let
                _ignores = ignores ++ [ "default" ];
            in mapAttrsToList (
                name: value: ./. + "/${name}"
            ) (
                filterAttrs ( name: value:
                    (value == "regular") &&
                    (!hasPrefix "_" name) &&
                    (!any (ign: (removeSuffix ".nix" name) == ign) _ignores)
                ) (builtins.readDir ./.)
            );
            set = ignores: builtins.listToAttrs (
                map (file: nameValuePair (removeSuffix ".nix" (builtins.unsafeDiscardStringContext file)) (import file { inherit nixpkgs; })
            ) (list ignores));
        };

        __ = makeExtensible (self: { inherit zettelkasten; } // zettelkasten.set []);
    in __.extend(self: super: foldr (new: old: new // old) {} (attrValues super));
})

from dotfiles.

shadowrylander avatar shadowrylander commented on July 21, 2024

Nope, never mind; I put the specialArgs in the let statement, without actually using it. My bad! 😅😹

from dotfiles.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.