Skip to content

Commit cf0d820

Browse files
committed
examples: standardise on primary user
except in installation media
1 parent fb4107a commit cf0d820

File tree

9 files changed

+82
-38
lines changed

9 files changed

+82
-38
lines changed

doc/concepts/suites.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@
22
Suites provide a mechanism for users to easily combine and name collections of
33
profiles.
44

5-
`suites` are defined in the `importables` argument in either the `home` or `nixos`
6-
namespace. They are a special case of an `importable` which is passed as a special
7-
argument (one that can be use in an `imports` line) to your hosts. All lists defined
8-
in `suites` are flattened and type-checked as paths.
5+
`suites` are defined in the `importables` argument in any of the `nixos`,
6+
`darwin`, or `home` namespaces. They are a special case of an `importable` which
7+
is passed as a special argument (one that can be use in an `imports` line) to
8+
your hosts. All lists defined in `suites` are flattened and type-checked as
9+
paths.
910

1011
## Definition
12+
1113
```nix
1214
rec {
13-
workstation = [ profiles.develop profiles.graphical users.nixos ];
14-
mobileWS = workstation ++ [ profiles.laptop ];
15+
workstation = [
16+
profiles.develop
17+
profiles.graphical
18+
users.primary
19+
];
20+
portableWorkstation =
21+
workstation
22+
++ [ profiles.laptop ];
1523
}
1624
```
1725

1826
## Usage
27+
1928
`hosts/my-laptop.nix`:
29+
2030
```nix
2131
{ suites, ... }:
2232
{
23-
imports = suites.mobileWS;
33+
imports = suites.portableWorkstation;
2434
}
2535
```

examples/devos/flake.nix

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@
119119
users = digga.lib.rakeLeaves ./users;
120120
};
121121
suites = with profiles; rec {
122-
base = [ core.nixos users.nixos users.root ];
122+
base = [
123+
core.nixos
124+
users.root
125+
users.primary
126+
];
123127
};
124128
};
125129
};
@@ -147,7 +151,10 @@
147151
users = digga.lib.rakeLeaves ./users;
148152
};
149153
suites = with profiles; rec {
150-
base = [ core.darwin users.admin ];
154+
base = [
155+
core.darwin
156+
users.primary
157+
];
151158
};
152159
};
153160
};
@@ -162,7 +169,6 @@
162169
};
163170
};
164171
users = {
165-
nixos = { suites, ... }: { imports = suites.base; };
166172
primary = { suites, ... }: { imports = suites.base; };
167173
};
168174
};

examples/devos/hosts/nixos/bootstrap.nix

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{ profiles, ... }:
22
{
3-
imports = [
4-
# profiles.networking
5-
profiles.core.nixos
6-
profiles.users.root # make sure to configure ssh keys
7-
profiles.users.nixos
3+
imports = with profiles; [
4+
core.nixos
5+
# N.B. Make sure to add your public SSH keys to authorized keys!
6+
users.root
7+
# Note that this is different than the usual `primary` user for the sake of
8+
# a familiar installation UX.
9+
users.nixos
810
];
911

1012
boot.loader.systemd-boot.enable = true;

examples/devos/users/admin/default.nix

Lines changed: 0 additions & 11 deletions
This file was deleted.

examples/devos/users/nixos.nix

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{ hmUsers, ... }:
2+
{
3+
# In this profile, the `nixos` system-level user loads the home-manager
4+
# profile for the `primary` user defined in the flake's
5+
# `self.home.users.primary` option.
6+
#
7+
# The user profile names defined in `self.home.users.<name>` don't need to
8+
# correspond directly to system-level usernames. They can, instead, be
9+
# imported as a module in any `home-manager.users` configuration, allowing for
10+
# more flexibility.
11+
#
12+
# Compare with the `primary` system user (in this directory), which uses a
13+
# simplified (but limited) approach.
14+
home-manager.users.nixos = {...}: { imports = [hmUsers.primary]; };
15+
16+
users.users.nixos = {
17+
# This is the standard password for installation media.
18+
password = "nixos";
19+
description = "default";
20+
isNormalUser = true;
21+
extraGroups = [ "wheel" ];
22+
};
23+
}

examples/devos/users/nixos/default.nix

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{ hmUsers, ... }:
2+
{
3+
users.users.primary = {
4+
description = "primary administrative user on this machine";
5+
isNormalUser = true;
6+
extraGroups = [ "wheel" ];
7+
8+
# Make sure to change this!
9+
initialPassword = "nixos";
10+
};
11+
12+
# The following home-manager user definition doesn't include any further
13+
# customization beyond the default `hmUsers.primary` profile, so its
14+
# implementation can be simplified.
15+
#
16+
# Note, however, that the pattern demonstrated in the `nixos` user profile is
17+
# more flexible in the long run, especially if you want to share the same
18+
# home-manager profile amongst multiple users with different usernames.
19+
home-manager.users = { inherit (hmUsers) primary; };
20+
}
File renamed without changes.

src/modules.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
globalDefaults = { hmUsers }:
1919
{ config, pkgs, self, ... }: {
20-
# digga lib can be accessed in modules directly as config.lib.digga
20+
# Digga's library functions can be accessed directly through the module
21+
# system as `config.lib.digga`.
2122
lib = {
2223
inherit (pkgs.lib) digga;
2324
};
@@ -32,6 +33,10 @@
3233
};
3334

3435
nixosDefaults = { self, ... }: {
36+
# N.B. If users are not explicitly defined in configuration, they will be
37+
# removed from the resulting system. This could result in data loss if
38+
# you're not starting from a fresh install -- even if you are currently
39+
# logged in!
3540
users.mutableUsers = lib.mkDefault false;
3641
hardware.enableRedistributableFirmware = lib.mkDefault true;
3742
system.configurationRevision = lib.mkIf (self ? rev) self.rev;

0 commit comments

Comments
 (0)