Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare inclusion in nixos-search #2971

Merged
merged 4 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/flake.lock
/result*
14 changes: 13 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{ pkgs ? import <nixpkgs> { } }:

rec {
let

flake = (import
(let lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in fetchTarball {
url =
"https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}) { src = ./.; }).defaultNix;
Comment on lines +5 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels pretty ugly to me. Why not simply change the pkgs.fetchFromGitLab to fetchTarball when fetching nmd and nmt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only a compatibility layer that should progressively become useless as we transition to flakes and the new nix CLI.

Why not simply change the pkgs.fetchFromGitLab to fetchTarball when fetching nmd and nmt?

We could, but if we're going to use flakes, we might as well use them fully, i.e. for all inputs. I think they're a nicer way to manage dependencies, and they make updating and overriding easier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that eventually it will be worth switching over to flakes but I'm skeptical about delving too deep while the feature is marked as experimental. At least unless there is a really compelling reason. But in this case there is a straight forward way to avoid the pkgs reference without touching flakes and needing compatibility shims.

I also would like to move the nmt and nmd projects over to sourcehut at some point and it doesn't seem like the flake-compat project supports the sourcehut URLs. I'll probably maintain a mirror at the gitlab location so this is not a blocker, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also not a blocker because we can just use URLs like git+https://git.sr.ht/~rycee/nmt.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm skeptical about delving too deep while the feature is marked as experimental.

It is only marked as experimental to not have to create backwards compatibility while it still might change.


in rec {
docs = with import ./docs { inherit pkgs; }; {
html = manual.html;
manPages = manPages;
Expand All @@ -16,4 +26,6 @@ rec {
nixos = import ./nixos;

path = ./.;

inherit (flake) inputs;
}
12 changes: 2 additions & 10 deletions docs/default.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
{ pkgs
{ pkgs, nmdSrc ? (import ./.. { }).inputs.nmd

# Note, this should be "the standard library" + HM extensions.
# Note, this should be "the standard library" + HM extensions.
, lib ? import ../modules/lib/stdlib-extended.nix pkgs.lib }:

let

nmdSrc = pkgs.fetchFromGitLab {
name = "nmd";
owner = "rycee";
repo = "nmd";
rev = "9e7a20e6ee3f6751f699f79c0b299390f81f7bcd";
sha256 = "1s49gjn1wapcjn0q4gabi8jwp8k5f18354a9c1vji0hfqsaknxzj";
};

nmd = import nmdSrc { inherit lib pkgs; };

# Make sure the used package is scrubbed to avoid actually
Expand Down
94 changes: 94 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 40 additions & 35 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,43 +1,31 @@
{
description = "Home Manager for Nix";

outputs = { self, nixpkgs }:
let
# List of systems supported by home-manager binary
supportedSystems = with nixpkgs.lib.platforms; linux ++ darwin;
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs.nmd.url = "gitlab:rycee/nmd";
inputs.nmd.flake = false;
inputs.nmt.url = "gitlab:rycee/nmt";
inputs.nmt.flake = false;

# Function to generate a set based on supported systems
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
inputs.utils.url = "github:numtide/flake-utils";
inputs.flake-compat.url = "github:edolstra/flake-compat";
inputs.flake-compat.flake = false;

nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
in rec {
nixosModules.home-manager = import ./nixos;
nixosModule = self.nixosModules.home-manager;

darwinModules.home-manager = import ./nix-darwin;
darwinModule = self.darwinModules.home-manager;

packages = forAllSystems (system:
let docs = import ./docs { pkgs = nixpkgsFor.${system}; };
in {
home-manager = nixpkgsFor.${system}.callPackage ./home-manager { };
docs-html = docs.manual.html;
docs-manpages = docs.manPages;
docs-json = docs.options.json;
default = self.packages.${system}.home-manager;
});

# defaultPackage is deprecated as of Nix 2.7.0
defaultPackage = forAllSystems (system: self.packages.${system}.default);

apps = forAllSystems (system: {
home-manager = {
type = "app";
program = "${defaultPackage.${system}}/bin/home-manager";
};
});
outputs = { self, nixpkgs, nmd, utils, ... }:
{
nixosModules = rec {
home-manager = import ./nixos;
default = home-manager;
};
# deprecated in Nix 2.8
nixosModule = self.nixosModules.default;

defaultApp = forAllSystems (system: apps.${system}.home-manager);
darwinModules = rec {
home-manager = import ./nix-darwin;
default = home-manager;
};
# unofficial; deprecated in Nix 2.8
darwinModule = self.darwinModules.default;

lib = {
hm = import ./modules/lib { lib = nixpkgs.lib; };
Expand All @@ -56,5 +44,22 @@
};
};
};
};
} // utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
docs = import ./docs {
inherit pkgs;
nmdSrc = nmd;
};
in {
packages = rec {
home-manager = pkgs.callPackage ./home-manager { };
docs-html = docs.manual.html;
docs-manpages = docs.manPages;
docs-json = docs.options.json;
default = home-manager;
};
# deprecated in Nix 2.7
defaultPackage = self.packages.${system}.default;
});
}
1 change: 0 additions & 1 deletion format
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ find . -name '*.nix' \
! -path ./modules/programs/bash.nix \
! -path ./modules/programs/ssh.nix \
! -path ./modules/programs/zsh.nix \
! -path ./nix-darwin/default.nix \
! -path ./tests/default.nix \
-exec nixfmt $CHECK_ARG {} +
1 change: 1 addition & 0 deletions home-manager/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ in runCommand "home-manager" {
preferLocalBuild = true;
nativeBuildInputs = [ gettext ];
meta = with lib; {
mainProgram = "home-manager";
description = "A user environment configurator";
maintainers = [ maintainers.rycee ];
platforms = platforms.unix;
Expand Down
124 changes: 124 additions & 0 deletions integration-common.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# This module is the common base for the NixOS and nix-darwin modules.
ncfavier marked this conversation as resolved.
Show resolved Hide resolved
# For OS-specific configuration, please edit nixos/default.nix or nix-darwin/default.nix instead.

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

with lib;

let

cfg = config.home-manager;

extendedLib = import ./modules/lib/stdlib-extended.nix pkgs.lib;

hmModule' = types.submoduleWith {
specialArgs = {
lib = extendedLib;
osConfig = config;
modulesPath = builtins.toString ./modules;
} // cfg.extraSpecialArgs;
modules = [
({ name, ... }: {
imports = import ./modules/modules.nix {
inherit pkgs;
lib = extendedLib;
useNixpkgsModule = !cfg.useGlobalPkgs;
};

config = {
submoduleSupport.enable = true;
submoduleSupport.externalPackageInstall = cfg.useUserPackages;

home.username = config.users.users.${name}.name;
home.homeDirectory = config.users.users.${name}.home;

# Make activation script use same version of Nix as system as a whole.
# This avoids problems with Nix not being in PATH.
home.extraActivationPath = [ config.nix.package ];
};
})
] ++ cfg.sharedModules;
} // {
description = "Home Manager module";
};

# TODO: hack until https://github.com/NixOS/nixpkgs/pull/173621 lands
hmModule = hmModule' // {
substSubModules = m:
hmModule'.substSubModules m // {
inherit (hmModule') description;
};
};

in {
options.home-manager = {
useUserPackages = mkEnableOption ''
installation of user packages through the
<option>users.users.&lt;name&gt;.packages</option> option
'';

useGlobalPkgs = mkEnableOption ''
using the system configuration's <literal>pkgs</literal>
argument in Home Manager. This disables the Home Manager
options <option>nixpkgs.*</option>
'';

backupFileExtension = mkOption {
type = types.nullOr types.str;
default = null;
example = "backup";
description = ''
On activation move existing files by appending the given
file extension rather than exiting with an error.
'';
};

extraSpecialArgs = mkOption {
type = types.attrs;
default = { };
example = literalExpression "{ inherit emacs-overlay; }";
description = ''
Extra <literal>specialArgs</literal> passed to Home Manager. This
option can be used to pass additional arguments to all modules.
'';
};

sharedModules = mkOption {
type = with types; listOf raw;
default = [ ];
example = literalExpression "[ { home.packages = [ nixpkgs-fmt ]; } ]";
description = ''
Extra modules added to all users.
'';
};

verbose = mkEnableOption "verbose output on activation";

users = mkOption {
type = types.attrsOf hmModule;
default = { };
# Prevent the entire submodule being included in the documentation.
visible = "shallow";
description = ''
Per-user Home Manager configuration.
'';
};
};

config = mkIf (cfg.users != { }) {
warnings = flatten (flip mapAttrsToList cfg.users (user: config:
flip map config.warnings (warning: "${user} profile: ${warning}")));

assertions = flatten (flip mapAttrsToList cfg.users (user: config:
flip map config.assertions (assertion: {
inherit (assertion) assertion;
message = "${user} profile: ${assertion.message}";
})));

users.users = mkIf cfg.useUserPackages
(mapAttrs (username: usercfg: { packages = [ usercfg.home.path ]; })
cfg.users);

environment.pathsToLink = mkIf cfg.useUserPackages [ "/etc/profile.d" ];
};
}
2 changes: 1 addition & 1 deletion modules/misc/xdg-desktop-entries.nix
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ let
};

# Required for the assertions
# TODO: Remove me once `mkRemovedOptionModule` works correctly with submodules
# TODO: Remove me once https://github.com/NixOS/nixpkgs/issues/96006 is fixed
assertions = mkOption {
type = types.listOf types.unspecified;
default = [ ];
Expand Down
Loading