Commit graph

161 commits

Author SHA1 Message Date
talyz
e985164ad5
nixos: Introduce persistentStoragePath option
This allows the path to persistent storage to be defined through an
option in the submodule, not just by the submodule name, i.e. instead
of

```nix
environment.persistence."/persistent" = {
  files = [ ... ]
  directories = [ ... ]
};
```

you could specify

```nix
environment.persistence.main = {
  persistentStoragePath = "/persistent";
  files = [ ... ]
  directories = [ ... ]
};
```

which is good for readability and when you want to split the config
between multiple files.

Fixes #117.
2023-06-24 17:37:01 +02:00
Kim Lindberger
89253fb151
Merge pull request #125 from ReneHollander/master
Skip generating bind mounts if no bind mounts are configured.
2023-05-16 21:15:34 +02:00
Rene Hollander
6f4fc9d70c
Skip generating bind mounts if no bind mounts are configured.
This fixes #105 by no longer generating an empty bash function. Empty
functions in bash are invalid, which cause the activation to fail.
2023-05-15 19:48:16 +02:00
Kim Lindberger
ec1a8e70d6
Merge pull request #128 from lovesegfault/disable
feat(nixos): allow persistant locations to be disabled
2023-05-15 11:54:52 +02:00
Bernardo Meurer
5a39142bbb
feat(nixos): allow persistant locations to be disabled 2023-05-14 17:02:35 -04:00
Kim Lindberger
df1692e2d9
Merge pull request #126 from alois31/assertion-hotfix
nixos: Fix collision detection logic
2023-04-23 18:46:51 +02:00
Alois Wohlschlager
2d575226bf
nixos: Fix collision detection logic
The logic for detecting whether a file or directory is specified
multiple times was not updated to account for the recent
file/filePath and directory/dirPath changes. This can lead to spurious
failures like the following if the same home-relative path is persisted
for different users:

       Failed assertions:
       - environment.persistence:
           The following directories were specified two or more
           times:
             .cache
             .config
             .local/share
             .local/state
             .gnupg
             .ssh

In addition, the assertion may falsely not trigger in the contrived
situation where the same entity is persisted both in a per-user
configuration (using the relative path) and the global configuration
(using the absolute path).

Fix these situations by checking the absolute paths again using
filePath and dirPath.
2023-04-23 16:14:43 +02:00
Kim Lindberger
c3f7012dc3
Merge pull request #109 from nix-community/dir-creation-order
nixos: Improve directory creation and permission and ownership assignment
2023-04-23 08:20:41 +02:00
talyz
170e9b105d
README: Add matrix room link
Also, remove the unrelated name explanation.
2023-04-23 08:16:13 +02:00
talyz
b4160ba71d
nixos: Rewrite directory creation for saner default permissions
Construct directory items for all parent directories of the user
specified files and directories, assigning better default permissions
and ownership to each and removing this responsibility from the
create-directories script.

This means that all parent directories of root directories will now
have the default permissions and ownership, not inherit them from the
child. User directories are assigned default user ownership. The home
directory itself is handled specially to make sure it is owned by the
user, not readable by anyone else and its parent gets default root
ownership.

To illustrate this with an example, here is a directory specification
and the ownership and permissions that could potentially be assigned
to the parent directories, given none of them yet exist in persistent
storage:

environment.persistence."/persistent" = {
  users.talyz = {
    directories = [
      { directory = ".local/share/secret"; mode = "0500"; }
    ];
  };
};

Before:
/home                            talyz:talyz   0500
/home/talyz                      talyz:talyz   0500
/home/talyz/.local               talyz:talyz   0500
/home/talyz/.local/share         talyz:talyz   0500
/home/talyz/.local/share/secret  talyz:talyz   0500

After:
/home                            root:root     0755
/home/talyz                      talyz:talyz   0700
/home/talyz/.local               talyz:talyz   0755
/home/talyz/.local/share         talyz:talyz   0755
/home/talyz/.local/share/secret  talyz:talyz   0500
2023-04-23 08:16:07 +02:00
talyz
d30c421e4e
nixos: Change internal file and directory semantics
This adds the new internal options `home`, `filePath` and
`dirPath`. Whereas previously `file` and `directory` would be
rewritten to the full path for user files and directories, they now
keep the value specified by the user. The new `filePath` and `dirPath`
options fill their previous use where the full path is required. In
addition, the new `home` option can be used to get the path to the
user's home directory for a specific file or directory item; for root
items it's set to `null`.
2023-04-23 08:16:01 +02:00
talyz
cc00a2a523
nixos: Use coercedTo type rather than manually converting from str
This simplifies the code quite a bit and should be easier to maintain.
2023-04-23 08:15:55 +02:00
talyz
d144e365cf
all: Line up lib inherits vertically 2023-04-23 08:15:49 +02:00
talyz
a65d7088db
nixos: Use mkDefault to set the default directory permissions
This means we don't have to pass them around as function arguments,
making things a bit cleaner.
2023-04-23 08:15:40 +02:00
Kim Lindberger
6138eb8e73
Merge pull request #114 from mweinelt/persist-nixos-uidgidmap
nixos: Recommend persisting /var/lib/nixos
2023-02-02 18:40:54 +01:00
Kim Lindberger
3792c10037
Merge pull request #115 from Kranzes/master
nixos: Mount binds after the persistent storage path
2023-02-02 18:38:53 +01:00
Ilan Joselevich
ba22f42f53
nixos: Mount binds after the persistent storage path 2023-02-02 19:28:09 +02:00
Martin Weinelt
a0b6d84f54
nixos: Recommend persisting /var/lib/nixos
The `/var/lib/nixos` directory contains the uid and gid map for entities
without a static id. Not persisting them means your user and group ids
could change between reboots, which is likely undesirable.
2023-02-02 17:25:20 +01:00
Kim Lindberger
5df9108b34
Merge pull request #110 from ckiee/gate-verbose
mount-file.bash: be quieter when debugging is off
2022-11-17 08:08:35 +01:00
ckie
32a5793139
mount-file.bash: be quieter when debugging is off 2022-11-17 08:09:12 +02:00
talyz
cd56321db5
home-manager: Add wrappers path for fusermount
Since
886675991b
the path no longer includes the wrappers, since it's reset. To fix
this, add the wrappers to the path.
2022-11-15 18:32:06 +01:00
Kim Lindberger
def994adbd
Merge pull request #100 from plietar/master
Make bash scripts work in cross-compiled environments.
2022-08-31 10:04:31 +02:00
Paul Liétar
e40af4a2a4 Make bash scripts work in cross-compiled environments.
When cross-compiling, `patchShebangs` requires the host platform's bash
to be present in the HOST_PATH environment variable. However, by default
when using `pkgs.runCommand`, only the build platform's bash is
implicitly added to the PATH. The result is that the shebang is not
replaced, and the script fails to run because the activation scripts
don't have `bash` in their environment.

By explicitly adding `pkgs.bash` to the build inputs, this ensures the
HOST_PATH is populated and makes `patchShebangs` work as expected.
2022-08-30 20:27:07 +01:00
Kim Lindberger
2237ad2809
Merge pull request #99 from Misterio77/allow-symlinking-directories
home-manager: adds configurable symlink/bindfs option
2022-08-27 10:56:20 +02:00
Gabriel Fontes
fc9ca99ef8
home-manager: adds configurable symlink/bindfs option 2022-08-22 11:31:31 -03:00
Kim Lindberger
e7c6fbbe90
Merge pull request #83 from devplayer0/qemu-vm-dirs
nixos: Fix bind mounts in VM build
2022-08-22 10:05:43 +02:00
Jack O'Sullivan
723c1a7535 nixos: Fix bind mounts in VM build 2022-03-13 16:42:49 +00:00
Kim Lindberger
2f39baeb7d
Merge pull request #85 from nix-community/minimize-activation-script-debug
nixos: Minimize activation script debug, add debugging, and more
2022-03-01 11:44:19 +01:00
talyz
95f9089e86
nixos: Minimize the amount of text added to the activation script
This is done to reduce the risk of build errors, isolate each run of
the script and reduce the amount of replicated code.

- Make the file mount script generated by `mkMountScript` a discrete
  script and only generate its invocations.

- Wrap the script invocations in scripts.
2022-02-16 15:24:47 +01:00
talyz
e8a4cefe13
nixos: Add an internal debugging option to aid script debugging 2022-02-16 13:40:17 +01:00
talyz
6ee09b4a71
create-directories: Set noglob and inherit_errexit, document options
In addition to the currently set bash options, set `noglob` and
`inherit_errexit`.

- `noglob` disables filename expansion, which could happen in the for
  loop where we do path splitting if the path contains characters
  recognized by bash as wildcards, such as `?` or `*`.

- `inherit_errexit` makes subshells inherit the status of the
  `errexit` option.
2022-02-16 13:25:17 +01:00
talyz
635bcd2d88
Add missing descriptions and improve existing ones
Closes #81
2022-02-13 23:27:11 +01:00
Kim Lindberger
bc3376a8e5
Merge pull request #82 from crunchcat/speify-main-flake-modules
Add default NixOS module to flake
2022-02-11 20:43:12 +01:00
crunchcat
7a36ba9279 Add default NixOS module to flake 2022-02-10 22:39:01 -05:00
maydayv7
ff540dbe20 docs: Document hideMounts Option 2022-02-04 14:41:56 -08:00
maydayv7
5f5bafee3a feat: Support Hiding of Bind Mounts
This is done using `x-gvfs-hide` Mount Option
2022-02-04 14:41:56 -08:00
talyz
423940122a nixos: Fix the path splitting in create-directories.bash
Previously, paths were split on bash's default delimiters (space, tab
and newline) with slashes converted to space. This meant paths
containing any such delimiters were incorrectly handled.

Fix this by temporarily replacing bash's default delimiters with `/`,
making sure this is the only character we split on.
2022-02-02 12:15:21 -08:00
talyz
65caf299a5
nixos: Fix user permissions for string type files and directories
Set the permissions for user directories and files properly when
converting them from string to submodule. Previously, they would use
the root default of `root:root`.

Fixes #74.
2022-02-02 10:09:42 +01:00
Bernardo Meurer
05cc388c3e fix(nixos): allow eval to succeed when the module is unused 2022-01-31 11:42:45 -08:00
Bernardo Meurer
3fe959d3dc refactor: utillinux -> util-linux 2022-01-31 11:12:51 -08:00
talyz
406924e62e nixos: Add support for custom permissions on created directories
Allow the owner and mode to be set when directories are created in
persistent storage by the `create-directories.bash` script. Very
useful for directories used to store secrets.

Also, make sure the user directories are created with reasonable
defaults, i.e. owned by the user and its group, not by `root:root`.
2022-01-31 11:12:29 -08:00
talyz
7f12a9d7cc nixos: Implement support for user files and directories
Allow user files and directories to be specified as follows:

environment.persistence."/persistent" = {
  users.talyz = {
    files = [
      ".screenrc"
    ];
    directories = [
      "Downloads"
    ];
  };
};

This provides an alternative to the home-manager module and may even
deprecate it in the future.
2022-01-31 11:12:29 -08:00
talyz
5738763c8d nixos: Assert that no duplicate files or directories are specified 2022-01-31 11:12:29 -08:00
talyz
0befe72b48 nixos: Refactor the module to simplify future extensibility
Implement support for a submodule representation for files and
directories. Strings are automatically converted to appropriate
submodule representations and each file and directory is handled based
only on their respective submodule's attributes. This means that for
most files, a string will suffice, but if more advanced options need
to be set for the specific files or directories, a submodule can be
used instead. It also, arguably, simplifies the implementation a bit.
2022-01-31 11:12:29 -08:00
Kim Lindberger
ff2240b04f
Merge pull request #67 from olmokramer/escape-directories
home-manager: Fix unquoted path when creating directories
2022-01-16 20:45:10 +01:00
Olmo Kramer
46aa52de9f
home-manager: Fix unquoted path when creating directories 2022-01-03 19:57:15 +01:00
Kim Lindberger
29d781b47b
Merge pull request #62 from nix-community/home-manager-start-early
home-manager: Start the bind units as early as possible
2021-12-29 21:13:21 +01:00
talyz
085284c398
home-manager: Start the bind units as early as possible 2021-12-28 20:43:39 +01:00
Kim Lindberger
0d03fa3d93
Merge pull request #61 from lourkeur/hm-bindfs-race
home-manager: allow dependencies on bind mounts
2021-12-28 15:51:46 +01:00
Louis Bettens
77a0cebfdd home-manager: allow dependencies on bind mounts 2021-12-27 17:37:29 +01:00